public void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (holdChess != null)
            {
                DeskCell cell = gamePage.Game.Desk.GetCellByMouse(e.Location);
                if (cell != null)
                {
                    this.InvokeEx(() =>
                    {
                        Point from = holdChess.Cell.Index;
                        if (gamePage.Game.Move(holdChess, cell.Index))
                        {
                            gamePage.Game.SwapPlayers();
                            socket.Send(Packet.MoveChessPacket(new ChessMoveData(from, cell.Index, ContenderPlayer.Name)));

                            if (IsEndGame)
                            {
                                socket.Send(Packet.EndGamePacket());
                                gamePage.Game.GameState = Game.State.Finish;
                                Page = selectContenderPage;
                                UpdateContendersList();
                                MessageBox.Show("Game over");
                            }
                            if (IsCheck)
                            {
                                MessageBox.Show("Check");
                            }
                        }
                        gamePage.GameControl.Repaint();
                        holdChess = null;
                    });
                }
            }
        }
        public void OnMouseMove(object sender, MouseEventArgs e)
        {
            DeskCell cell = gamePage.Game.Desk.GetCellByMouse(e.Location);

            if (cell != null)
            {
                select.HoveredCell = cell;
                select.DrawingHovered.Rectangle = cell.Rectangle;

                if (holdChess != null)
                {
                    holdChess.Sprite.Position = new PointF(e.X - holdDiff.X, e.Y - holdDiff.Y);
                }
                gamePage.GameControl.Repaint();
            }
        }
        public void OnMouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            DeskCell cell = gamePage.Game.Desk.GetCellByMouse(e.Location);

            if (cell != null)
            {
                Chess chess = cell.Chess;
                if (IsMyChess(chess) && IsMyMove())
                {
                    holdChess = chess;
                    holdDiff  = new PointF(e.X - chess.Sprite.Position.X, e.Y - chess.Sprite.Position.Y);
                }
                gamePage.GameControl.Repaint();
            }
        }
Beispiel #4
0
        private void LoadCells()
        {
            GameColor currentType;

            for (int j = 0; j < 8; ++j)
            {
                currentType = (j % 2 == 0)
                    ?   GameColor.Black
                    :   GameColor.White;

                for (int i = 0; i < 8; ++i)
                {
                    cells[i, j] = new DeskCell(this, currentType, new Point(i, j));

                    currentType = (currentType == GameColor.Black)
                        ?   GameColor.White
                        :   GameColor.Black;
                }
            }
        }