I need help for this game [Solved]
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
I need help for this game [Solved]
Can Ren'Py make a game like this?
http://www.javaonthebrain.com/java/solitaire/
Can someone help me please?
I really need help.
Too confuse use python code T_T
http://www.javaonthebrain.com/java/solitaire/
Can someone help me please?
I really need help.
Too confuse use python code T_T
Last edited by Yureilee on Sat Jan 18, 2014 5:59 pm, edited 1 time in total.
- SundownKid
- Lemma-Class Veteran
- Posts: 2299
- Joined: Mon Feb 06, 2012 9:50 pm
- Completed: Icebound, Selenon Rising Ep. 1-2
- Projects: Selenon Rising Ep. 3-4
- Organization: Fastermind Games
- Deviantart: sundownkid
- Location: NYC
- Contact:
Re: I need help for this game
There is a card game engine here: http://www.renpy.org/wiki/renpy/Frameworks
It seems like it works for games of Solitaire.
It seems like it works for games of Solitaire.
Re: I need help for this game
It's the actual game of Solitaire (the marble jumping one), not a card game of Patience.SundownKid wrote:It seems like it works for games of Solitaire.
Yes, you should be able to programme something like that into Ren'Py, though I don't know how easy it would be. You could either do it in Pygame (which I'm sure is possible) or try doing it in Ren'Py itself, probably using a screen with imagebuttons for the marbles/holes.
Re: I need help for this game
i did find this code http://programsofkannan.blogspot.com/20 ... -game.html
and i will use picture for peg and board and maybe drag system.
but how i code it with renpy? please help T_T
and i will use picture for peg and board and maybe drag system.
but how i code it with renpy? please help T_T
Re: I need help for this game
Okay, I've used that code as the basis to get this working in Ren'Py:
First, we need some stuff in an init block.
Then when we're ready to actually run the game we use this code somewhere after the start label:
It's a bit of a clunky interface, since you have to type in the row and column to move pieces. You should be able to adjust this code so you can click on the pieces instead by changing them to textbuttons in the screen, I'd imagine...
First, we need some stuff in an init block.
Code: Select all
init:
python:
PEG = '☻'
BLANK = '☼'
HOLE = '☺'
clickrow = 0
clickcol = 0
class Board:
#""" This class is responsible to create board and checking board status"""
def __init__(self):
# """ Initialize Board and it's attributes"""
self.move = 0
self.max_row = 7
self.max_col = 7
self.max_move = 31
self.board = []
self.board.append([BLANK, BLANK, PEG, PEG, PEG, BLANK, BLANK])
self.board.append([BLANK, BLANK, PEG, PEG, PEG, BLANK, BLANK])
self.board.append([PEG, PEG, PEG, PEG, PEG, PEG, PEG])
self.board.append([PEG, PEG, PEG, HOLE, PEG, PEG, PEG])
self.board.append([PEG, PEG, PEG, PEG, PEG, PEG, PEG])
self.board.append([BLANK, BLANK, PEG, PEG, PEG, BLANK, BLANK])
self.board.append([BLANK, BLANK , PEG, PEG, PEG, BLANK, BLANK])
def print_board(self):
# """ Display current status of board """
print '\nBoard:\n'
print " 0 1 2 3 4 5 6"
print "---------------"
count = 0
for row in self.board:
print ("%d") % (count),
count += 1
for position in row:
print position,
print ''
def check_move_possible(self):
# """ Check for further valid move in the board"""
for i in range(self.max_row):
if(i < 2 or i > 4):
ret = self.three_row_check(i)
else:
ret = self.seven_row_check(i)
if(ret == True):
return True
for i in range(self.max_col):
if(i < 2 or i > 4):
ret = self.three_col_check(i)
else:
ret = self.seven_col_check(i)
if(ret == True):
return True
return False
def three_row_check(self, row):
#""" Checking valid move in three column rows"""
if(self.board[row][2] == PEG and self.board[row][3] == PEG
and self.board[row][4] == HOLE):
return True
if(self.board[row][2] == HOLE and self.board[row][3] == PEG
and self.board[row][4] == PEG):
return True
return False
def seven_row_check(self, row):
# """ Checking valid move in seven column rows"""
for i in range(self.max_col):
if(i == 0):
if(self.board[row][0] == PEG and self.board[row][1] == PEG \
and self.board[row][2] == HOLE):
return True
elif(i == 6 or i == 5):
if(self.board[row][6] == PEG and self.board[row][5] == PEG \
and self.board[row][4] == HOLE):
return True
else:
if(self.board[row][i] == PEG and self.board[row][i + 1] == PEG):
if(self.board[row][i - 1] == HOLE or \
self.board[row][i + 2] == HOLE):
return True
return False
def three_col_check(self, col):
# """ Checking valid move in three row cols"""
if(self.board[2][col] == PEG and self.board[3][col] == PEG \
and self.board[4][col] == HOLE):
return True
if(self.board[2][col] == HOLE and self.board[3][col] == PEG \
and self.board[4][col] == PEG):
return True
return False
def seven_col_check(self, col):
# """ Checking valied move in seven row cols"""
for i in range(self.max_row):
if(i == 0):
if(self.board[0][col] == PEG and self.board[1][col] == PEG \
and self.board[2][col] == HOLE):
return True
elif(i == 6 or i == 5):
if(self.board[6][col] == PEG and self.board[5][col] == PEG \
and self.board[4][col] == HOLE):
return True
else:
if(self.board[i][col] == PEG and self.board[i + 1][col] == PEG):
if(self.board[i - 1][col] == HOLE or \
self.board[i + 2][col] == HOLE):
return True
return False
class Play:
#""" This class is responsible to get move info \
#from player and play peg solitaire game."""
def __init__(self):
# "initialize instance variables"
self.get_row = 0
self.get_col = 0
self.put_row = 0
self.put_col = 0
self.midr = 0
self.midc = 0
def get_pos(self):
# """ Get move position from user"""
self.get_row = int (renpy.input("Enter row no to get peg : "))
self.get_col = int (renpy.input("Enter col no to get peg : "))
self.put_row = int (renpy.input("Enter row no to put peg : "))
self.put_col = int (renpy.input("Enter col no to put peg : "))
def validate_pos_board(self):
# """ Validate user entered position inputs with board layout"""
if(self.get_row < 0 or self.get_row > 6):
return False
if(self.get_col < 0 or self.get_col > 6):
return False
if(self.put_row < 0 or self.put_row > 6):
return False
if(self.put_col < 0 or self.put_col > 6):
return False
return True
def validate_valied_pos(self):
#""" validate user entered positions """
if(self.get_row == self.put_row):
val = self.get_col - self.put_col
if(val == -2 or val == 2):
self.midr = self.get_row
self.midc = (self.get_col + self.put_col) / 2
return True
if(self.get_col == self.put_col):
val = self.get_row - self.put_row
if(val == -2 or val == 2):
self.midr = (self.get_row + self.put_row) / 2
self.midc = self.get_col
return True
return False
def validate_pos_with_peg_and_play(self, board):
#""" Valid date user entered position with valid move"""
if(board.board[self.get_row][self.get_col] == PEG):
if(board.board[self.put_row][self.put_col] == HOLE):
if(board.board[self.midr][self.midc] == PEG):
board.board[self.get_row][self.get_col] = HOLE
board.board[self.put_row][self.put_col] = PEG
board.board[self.midr][self.midc] = HOLE
play_board.board[self.get_row][self.get_col] = HOLE
play_board.board[self.put_row][self.put_col] = PEG
play_board.board[self.midr][self.midc] = HOLE
board.move += 1
return True
return False
return False
def main():
# """ Function for playing Peg Solitaire """
play_board = Board()
player = Play()
while(True):
renpy.hide_screen("myboard")
renpy.show_screen("myboard")
player.get_pos()
ret = player.validate_pos_board()
if(ret == False):
renpy.say("", "Wrong Position")
continue
ret = player.validate_valied_pos()
if(ret == False):
renpy.say("", "Wrong Position")
continue
ret = player.validate_pos_with_peg_and_play(play_board)
if(ret == False):
renpy.say("", "Wrong Position")
continue
ret = play_board.check_move_possible()
if(ret == False):
renpy.say("", "No more legal Moves")
play_board.print_board()
break
if(play_board.move == play_board.max_move):
renpy.say("", "Congratulations!! you have solved the puzzle!")
play_board.print_board()
break
if __name__ == '__main__':
main()
screen myboard:
vbox:
text '\nBoard:\n'
text " 0 1 2 3 4 5 6"
text "---------------"
$ count = 0
for row in play_board.board:
hbox:
text ("%d"%(count))
$ count += 1
for position in row:
text position
text ' '
textbutton "Reset" action Jump("game") Code: Select all
label game:
"Let's play Solitaire!"
$ play_board = Board()
$ player = Play()
$ main()Re: I need help for this game
okay it solved. thanks 
Who is online
Users browsing this forum: Bing [Bot]
