public GameCore() { Application.EnableVisualStyles(); runColor = FigureColor.WHITE; pState = new PlayersState(); pCollection = new ProfileCollection("Users.db"); }
private void ReInitialize() { runColor = FigureColor.WHITE; matrix = new CoreMatrix(); playWindow = new PlayWindow(this, "Chess", new GuiMatrix(matrix)); playWindow.FormClosed += new FormClosedEventHandler(PlayWindowClose); inviteWindow = new InviteWindow(pCollection); inviteWindow.OnChoice += new InviteWindow.OnChoiceEventHandler(InviteWindowMessageReceived); inviteWindow.Show(); }
private void Start() { runColor = FigureColor.WHITE; matrix = new CoreMatrix(); playWindow = new PlayWindow(this, "Chess", new GuiMatrix(matrix)); playWindow.FormClosed += new FormClosedEventHandler(PlayWindowClose); PlayerClock = new System.Windows.Forms.Timer(); PlayerClock.Tick += new EventHandler(PlayerClock_Tick); PlayerClock.Interval = 1000; endGameLock = false; PlayerClock.Start(); playWindow.Show(); }
public void PlayerClock_Tick(Chess.Figures.FigureColor clr) { if (clr == FigureColor.WHITE) { p1Time++; Player1Time.Text = ((int)(p1Time / 60) < 10) ? '0' + Convert.ToString((int)(p1Time / 60)) : Convert.ToString((int)(p1Time / 60)); Player1Time.Text += ':'; Player1Time.Text += ((int)((p1Time / 60.0 - (int)(p1Time / 60)) * 60) < 10) ? '0' + Convert.ToString((int)((p1Time / 60.0 - (int)(p1Time / 60)) * 60)) : Convert.ToString((int)((p1Time / 60.0 - (int)(p1Time / 60)) * 60)); } else { p2Time++; Player2Time.Text = ((int)(p2Time / 60) < 10) ? '0' + Convert.ToString((int)(p2Time / 60)) : Convert.ToString((int)(p2Time / 60)); Player2Time.Text += ':'; Player2Time.Text += ((int)((p2Time / 60.0 - (int)(p2Time / 60)) * 60) < 10) ? '0' + Convert.ToString((int)((p2Time / 60.0 - (int)(p2Time / 60)) * 60)) : Convert.ToString((int)((p2Time / 60.0 - (int)(p2Time / 60)) * 60)); } }
private void MoveFigure(Position oldPos, Position newPos) { //changing play window cursor playWindow.Cursor = Cursors.WaitCursor; //rock change implementation if (newPos.Equals(matrix.GetKing(runColor)) && !matrix.FigureAt(matrix.GetKing(runColor)).IsMoved) { int dx = oldPos.X - newPos.X; dx = (dx > 0) ? (1) : (-1); Position kingPos = new Position(newPos.X + dx * 2, newPos.Y); Position rockPos = new Position(newPos.X + dx, newPos.Y); matrix.MoveFigure(newPos, kingPos); matrix.FigureAt(kingPos).IncreaseSteps(); playWindow.matrix.MoveImage(newPos, kingPos); matrix.MoveFigure(oldPos, rockPos); matrix.FigureAt(rockPos).IncreaseSteps(); playWindow.matrix.MoveImage(oldPos, rockPos); //print message in system log console playWindow.PrintToConsole("System: ", System.Drawing.Color.Red); playWindow.PrintToConsoleLn("King-rock change", System.Drawing.Color.Green); } else { //simple figure move //print message in system log console if (runColor == FigureColor.WHITE) { playWindow.PrintToConsole("System: ", System.Drawing.Color.Red); playWindow.PrintToConsoleLn("Player1 moved " + matrix.FigureAt(oldPos).ToString() + " from " + (char)('A' + oldPos.X) + Convert.ToString(8 - oldPos.Y) + " to " + (char)('A' + newPos.X) + Convert.ToString(8 - newPos.Y), System.Drawing.Color.FromArgb(64, 128, 255)); } else { playWindow.PrintToConsole("System: ", System.Drawing.Color.Red); playWindow.PrintToConsoleLn("Player2 moved " + matrix.FigureAt(oldPos).ToString() + " from " + (char)('A' + oldPos.X) + Convert.ToString(8 - oldPos.Y) + " to " + (char)('A' + newPos.X) + Convert.ToString(8 - newPos.Y), System.Drawing.Color.FromArgb(128, 64, 255)); } Figure figure = matrix.FigureAt(oldPos); matrix.MoveFigure(oldPos, newPos); playWindow.matrix.MoveImage(oldPos, newPos); figure.IncreaseSteps(); //checking pawn move gap if (figure is Pawn) { ((Pawn)figure).TwoStepState = (Math.Abs(oldPos.Y - newPos.Y) == 2); //Проверка на замену пешки другой фигурой if ((runColor == FigureColor.WHITE && newPos.Y == 0) || (runColor == FigureColor.BLACK && newPos.Y == 7)) { if ((network.type == NetWorkType.SERVER && runColor == FigureColor.WHITE) || (network.type == NetWorkType.CLIENT && runColor == FigureColor.BLACK)) { FigureChoiceWindow w = new FigureChoiceWindow(playWindow.GetPosOnScreen(newPos), runColor); w.ShowDialog(playWindow); matrix.SetFigure(w.Result, newPos); playWindow.matrix.SetImage(w.Result.image, newPos); playWindow.ReDraw(true); } } else { GetInPass(oldPos, newPos); ((Pawn)matrix.FigureAt(newPos)).NeighborsFigures[1] = matrix.FigureAt(newPos.X + 1, newPos.Y); ((Pawn)matrix.FigureAt(newPos)).NeighborsFigures[0] = matrix.FigureAt(newPos.X - 1, newPos.Y); } } } //changing color changing runColor = (runColor == FigureColor.WHITE) ? (FigureColor.BLACK) : (FigureColor.WHITE); CheckForMate(); playWindow.matrix.ResetAllAttribures(); playWindow.Cursor = Cursors.Default; playWindow.ReDraw(); }
public GameCore() { Application.EnableVisualStyles(); runColor = FigureColor.WHITE; pState = new PlayersState(); }