

It makes it harder to read and much harder to maintain.
PEG SOLITAIRE TRAINGULAR BOARD JAVA CODE CODE
There is a lot of copied and pasted code in your work. There is room for improvement in your code, I'll give a few pointers of things that stand out to me.
PEG SOLITAIRE TRAINGULAR BOARD JAVA CODE UPDATE
I still want to update the game graphics, because they're still rough sketches haha. I couldn't figure out a way to check if there were no more possible moves or if the player won the game(if there was only one piece left), so if the player loses or wins the program doesn't do anything. Move_piece(hole_in_between, selected_hole= selected_hole, target_hole= target_hole)ĭef move_piece(hole_in_between, selected_hole, target_hole): If hole.row = selected_hole.row + 1 and lumn = selected_lumn: If hole.row = selected_hole.row - 1 and lumn = selected_lumn:Įlif selected_hole.row - target_hole.row = -2: If selected_hole.row - target_hole.row = 2: 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'.
