private void ComputerMove(Point point) { if (Matrix[point.Y][point.X].Text != "") { return; } DrawChess(point, CurrentPlayer); ChangeBackgroundColor(Matrix[point.Y][point.X], true); if (StkUndo.Count > 0) { Point undoPoint = StkUndo.Peek(); Button button = Matrix[undoPoint.Y][undoPoint.X]; ChangeBackgroundColor(button, false); } this.StkUndo.Push(point); this.StkRedo = new Stack <Point>(); if (isEndGame(Matrix[point.Y][point.X])) { IsEndGame = CurrentPlayer == 1 ? ENDGAME.PlayerX : ENDGAME.PlayerO; Form.EndGame(Convert.ToInt32(IsEndGame)); } else { Ready = true; isSearching = false; ChangePlayer(); } }
public void Undo() { if (stkUndo.Count == 0 || isSearching) { return; } Point undoPoint = StkUndo.Pop(); StkRedo.Push(undoPoint); Button btn = Matrix[undoPoint.Y][undoPoint.X]; ChangeBackgroundColor(btn, false); btn.Text = ""; if (StkUndo.Count > 0) { Point point = StkUndo.Peek(); ChangeBackgroundColor(Matrix[point.Y][point.X], true); } if (Ready) { ChangePlayer(); } else { Form.resetTime(CurrentPlayer); } }
public void Redo() { if (StkRedo.Count == 0 || isSearching) { return; } if (StkUndo.Count > 0) { Point point = StkUndo.Peek(); ChangeBackgroundColor(Matrix[point.Y][point.X], false); } Point undoPoint = StkRedo.Pop(); StkUndo.Push(undoPoint); Button btn = Matrix[undoPoint.Y][undoPoint.X]; DrawChess(GetChessPoint(btn), CurrentPlayer); ChangeBackgroundColor(btn, true); if (isEndGame(btn)) { IsEndGame = CurrentPlayer == 1 ? ENDGAME.PlayerX : ENDGAME.PlayerO; Form.EndGame(Convert.ToInt32(IsEndGame)); } else { ChangePlayer(); } }
private void btn_Click(object sender, EventArgs e) { if (!Ready) { return; } Button btn = sender as Button; if (btn.Text != "") { return; } DrawChess(GetChessPoint(btn), CurrentPlayer); ChangeBackgroundColor(btn, true); if (StkUndo.Count > 0) { Point undoPoint = StkUndo.Peek(); Button button = Matrix[undoPoint.Y][undoPoint.X]; ChangeBackgroundColor(button, false); } this.StkUndo.Push(GetChessPoint(btn)); this.StkRedo = new Stack <Point>(); if (isEndGame(btn)) { IsEndGame = CurrentPlayer == 1 ? ENDGAME.PlayerX : ENDGAME.PlayerO; Form.EndGame(Convert.ToInt32(IsEndGame)); } else { ChangePlayer(); if (GameMode == 2) { Ready = false; isSearching = true; new Thread( () => { ComputerMove(Computer.SearchPosition()); } ) { IsBackground = true }.Start(); //ComputerMove(Computer.SearchPosition()); } } }