public void changer(Button clickedButton, ref Turns currentTurn) { int buttonID = int.Parse(clickedButton.Tag.ToString()); //Zero-based row and column int row = buttonID / 3; int col = buttonID % 3; if (GameBoard[row][col] == State.N) { if (currentTurn == Turns.X) { GameBoard[row][col] = State.X; pGameBoard[row][col] = State.X; } else { GameBoard[row][col] = State.O; pGameBoard[row][col] = State.O; } clickedButton.Text = GameBoard[row][col].ToString(); currentTurn++; turns++; } label2.Text = currentTurn.ToString(); }
public void Play(int line, int col) { //Can't play on the board's edges if (line <= 0 || line >= Board.Tiles.GetLength(0) - 1 || col <= 0 || col >= Board.Tiles.GetLength(1) - 1) throw new InvalidMoveException(); //Can't play on top of a used tile if (Board.Tiles[line, col] != TileState.Empty) throw new InvalidMoveException(); //Can't play if the game has already ended if (this._ended) throw new InvalidMoveException(); Board.Tiles[line, col] = this.Turn == Turns.Player1 ? TileState.Player1 : TileState.Player2; if (MoveWinsGame(line, col)) { this._ended = true; AnnounceWinner(this.Turn); } Turn = Turn == Turns.Player1 ? Turns.Player2 : Turns.Player1; }
private void AnnounceWinner(Turns turns) { if (this.Ended != null) this.Ended(this.Turn); }
private RobotPosition Turning(InputInfo inputInfo, Turns turnTo) { // get currently facing configs var conf = FindPlacementConfig(_robotAt.Facing); // Get the current facing value and +1 to it var newFacingVal = (int)conf.FacingVal + (int)turnTo; // Check for valid turn since can keep turning the same direction 360 again and again // if keep turing RIGHT +1 if (newFacingVal > 4) newFacingVal = 1; // if keep turning LEFT -1 if (newFacingVal <= 0) newFacingVal = 4; // Get the Directions of newFacingVal string newDirectionName = Enum.GetName(typeof(Directions), newFacingVal); Directions newDirection; Enum.TryParse(newDirectionName, out newDirection); // Update the current Robot facing value _robotAt.Facing = newDirection; return _robotAt; }
public void turn(ref Turns currentTurn) { if (turns > 8) { MessageBox.Show("Tie!!!"); initializer(GameBoard,pGameBoard); } if (currentTurn.ToString() == "2") { label2.Text = "X"; currentTurn = 0; } }
public void initializer(State[][] arrray, State[][] arrrray) { for (int i = 0; i < 3; i++) { arrray[i] = new State[3]; arrrray[i] = new State[3]; for (int k = 0; k < 3; k++) { arrray[i][k] = 0; arrrray[i][k] = 0; } foreach (Control control in Controls) { if (control is Button) { Button button = (Button)control; button.Text = "?"; } } label2.Text = "X"; turns = 0; currentTurn = 0; } }
void _game_Ended(Turns winner) { string color = winner == Turns.Player1 ? "Blue" : "Red"; MessageBox.Show(color + " player won!", "Winner", MessageBoxButtons.OK); }