////////// //// HANDLERS FOR BOARD, PIECES, LOGIC AND HIGHLIGHTING LOCATED BELOW HERE ////////// public static void MakeMove(int boardX, int boardY) { if (wait_for_timer || !player_turn || wait_for_computer || !canMove()) { return; } if (MainPage.game_state == GameState.OUT_OF_GAME || MainPage.game_state == GameState.END_GAME || (checkerX == -1 && checkerY == -1)) { return; } if (game_type == GameState.SINGLE_PLAYER) { player_turn = false; } wait_for_timer = true; Move m; try { PieceColor whoseTurn = logic.whoseMove(); int locX = checkerX; int locY = checkerY; // Unhighlight the selected piece handleHighlighting(checkerX, checkerY); m = logic.makeMove(locY, locX, boardY, boardX); handleMove(m); if (whoseTurn.Equals(logic.whoseMove())) { checkerX = boardX; checkerY = boardY; multi_jump = true; } TURN_TIMER.Start(); } catch (PlayerMustJumpException) { MessageBox.Show("You must take an available jump!"); wait_for_timer = false; player_turn = true; } catch (WrongMultiJumpPieceException) { MessageBox.Show("You must finish the multijump!"); wait_for_timer = false; player_turn = true; } catch (InvalidMoveException) { System.Diagnostics.Debug.WriteLine("invalid move"); wait_for_timer = false; player_turn = true; } }
private void Make_Educated_Move(object sender, EventArgs e) { if (!canMove() || !player_turn || (wait_for_computer && sender.Equals(Make_A_Move))) { return; } if (sender.Equals(Make_A_Move)) { used_make_move = true; } if (game_type == GameState.SINGLE_PLAYER) { player_turn = false; } wait_for_timer = true; PieceColor whoseMove = logic.whoseMove(); MoveAttempt a; if (MainPage.DIFFICULT && wait_for_computer) { a = logic.getHardMove(); } else { a = logic.getEasyMove(); } Move m = logic.makeMove(a); handleMove(m); if (!TURN_TIMER.IsEnabled) { TURN_TIMER.Start(); } if (whoseMove.Equals(logic.whoseMove())) { checkerX = a.getXEnd(); checkerY = a.getYEnd(); multi_jump = true; } }
private void timerTick(object o, EventArgs e) { TURN_TIMER.Stop(); if (checkEndGame()) { MainPage.game_state = GameState.END_GAME; return; } PieceColor last = logic.getWhoMovedLast(); // if there is a double jump available and it isn't forced if (multi_jump) { // if black is making the jump if (!last.Equals(PieceColor.RED) || (MainPage.game_state != GameState.SINGLE_PLAYER)) { if (used_make_move) { Make_Educated_Move(o, e); } else { if (!MainPage.FORCE_JUMP) { if (MessageBox.Show("Double Jump Available!", "Take the double jump?", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel) { logic.skipMultiJump(); multi_jump = false; } else { int x = checkerX; int y = checkerY; checkerX = checkerY = -1; handleHighlighting(x, y); } } } } else { if (MainPage.game_state == GameState.SINGLE_PLAYER) { COMPUTER_DELAY.Start(); } } } else { used_make_move = false; checkerX = checkerY = -1; } multi_jump = false; WhoseTurn.Text = (logic.whoseMove().Equals(PieceColor.RED) ? "Red" : "Black") + " to move next."; Moves.Text = "Moves: " + logic.getMoveNumber(); wait_for_timer = false; player_turn = true; if (MainPage.game_state == GameState.SINGLE_PLAYER) { //MessageBox.Show("Computer's turn."); wait_for_computer = !wait_for_computer; if (wait_for_computer && logic.whoseMove().Equals(PieceColor.RED)) { COMPUTER_DELAY.Start(); } else { wait_for_computer = false; } } }