Exemplo n.º 1
0
        private void ChessTile_MouseClick(object sender, MouseEventArgs e)
        {
            var selectedTileCoordinates = Tuple.Create(
                ChessBoard.GetCellPosition(sender as Control).Row,
                ChessBoard.GetCellPosition(sender as Control).Column);

            if (e.Button == MouseButtons.Left)
            {
                Game.SelectFigure(selectedTileCoordinates);
            }
            if (e.Button == MouseButtons.Right)
            {
                if (figureList.SelectedIndex == -1 || figureList.SelectedIndex == 0)
                {
                    Game.MoveFigure(selectedTileCoordinates);
                }
                else
                {
                    Game.SpawnFigure(selectedTileCoordinates, figureList.SelectedItem.ToString());
                }
                figureList.ClearSelected();
                RedrawBoard();
                if (Game.GameFinished)
                {
                    MessageBox.Show(Game.PlayerTurn.ToString() + " player lost the game!");
                    ChessBoard.Enabled   = false;
                    PlayerTurnLabel.Text = @"Press ""Start game"" button";
                }
            }
        }
Exemplo n.º 2
0
        public void FiguresCantSpawnOnOthers()
        {
            var game        = new Game();
            var whiteQueen  = new Queen(Color.White);
            var blackPawn   = new Pawn(Color.Black);
            var blackBishop = new Bishop(Color.Black);

            game.SelectedFigureCoordinates = Tuple.Create(3, 3);
            game.Board[3, 3] = whiteQueen;
            game.Board[4, 3] = blackPawn;
            game.Board[0, 0] = blackBishop;
            game.MoveFigure(Tuple.Create(4, 3));
            game.SelectedFigureCoordinates = Tuple.Create(0, 0);
            game.MoveFigure(Tuple.Create(1, 1));
            game.SpawnFigure(Tuple.Create(1, 1), "Pawn");
            game.SpawnFigure(Tuple.Create(4, 3), "Pawn");
            Assert.AreEqual(game.Board[1, 1].GetType(), blackBishop.GetType());
            Assert.AreEqual(game.Board[4, 3].GetType(), whiteQueen.GetType());
        }