If lumn = selected_lumn + 1 and hole.row = selected_hole.row:Įlif selected_hole.has_piece and not target_hole.has_piece and selected_lumn = target_lumn: Move_piece(hole_in_between, selected_hole, target_hole)Įlif selected_lumn - target_lumn = -2: If lumn = selected_lumn - 1 and hole.row = selected_hole.row: If selected_hole.has_piece and not target_hole.has_piece and selected_hole.row = target_hole.row: class BoardPart():ĭef _init_(self, row, column, button, has_piece, is_selected, is_button):īoard = ĭef check_moves(selected_hole, target_hole): Here I check if the 'selected' and 'targeted' pieces are valid. Selected_(relief= 'raised')ī(image= PIECE_IMAGE)ī(image= HOLE_IMAGE) Game_logic.check_moves(selected_button, clicked_button) If not any(button.is_selected for button in game_buttons): Screen_id(row=board_part.row, column=board_lumn)Įmpty_part = tk.Frame(frame, width= BUTTON_WIDTH, height= BUTTON_HEIGHT, bg='#e5e8ec')Įmpty_id(row=board_part.row, column=board_lumn) Screen_button = tk.Button(frame, width=BUTTON_WIDTH, height=BUTTON_HEIGHT, bg='white', command=lambda x= board_part: click_button(x)) HOLE_IMAGE = tk.PhotoImage(file='restaumhole.png')Ĭanvas = tk.Canvas(root, width= WIDTH, height= HEIGHT, bg='#c5d1ed')įace(relx= 0.5, rely= 0.05, relwidth= 0.9, relheight= 0.9, anchor= 'n') PIECE_IMAGE = tk.PhotoImage(file='restaumpiece.png') This is the main code, I tried to separate the game-logic from the Tkinter representation of the board and stuff. It's kind of hard to explain it since I believe this game doesn't exist outside Brazil. For a move to be allowed, the selected piece must be one tile away from where it will 'jump' and the hole in which it will go has to be empty. The idea of the game is that there are holes in which there are pieces inside, the player has to pick pieces and 'jump' one another until there is only one left on the board. This time I wanted to make a board game that is very popular in Brazil, it's called 'resta um', it means 'there's only one left'.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |