Exemplo n.º 1
0
        public void EmptyCell(ChessBoardPosition chessBoardPosition)
        {
            var cell = new ChessBoardCell
            {
                Entity     = null,
                IsOccupied = false,
            };

            SetCell(chessBoardPosition, cell);
        }
Exemplo n.º 2
0
        public void LoadLevel(string[] levelPath)
        {
            _chessBoardCells = new ChessBoardCell[Rows, Columns];

            for (int row = 0; row < Rows; row++)
            {
                for (int column = 0; column < Columns; column++)
                {
                    char cell = (levelPath[row])[column];

                    var chessBoardCell = new ChessBoardCell();
                    switch (cell)
                    {
                    case 'G':
                        chessBoardCell.Entity     = new Grunt();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case 'J':
                        chessBoardCell.Entity     = new Jumpship();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case 'T':
                        chessBoardCell.Entity     = new Tank();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case 'D':
                        chessBoardCell.Entity     = new Drone();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case 'N':
                        chessBoardCell.Entity     = new Dreadnought();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case 'C':
                        chessBoardCell.Entity     = new CommandUnit();
                        chessBoardCell.IsOccupied = true;
                        break;

                    case '0':
                        chessBoardCell.Entity     = null;
                        chessBoardCell.IsOccupied = false;
                        break;
                    }

                    _chessBoardCells[row, column] = chessBoardCell;
                }
            }
        }
Exemplo n.º 3
0
        public ChessBoardPosition CalculatePosition(ChessBoardPosition currentPosition, int x, int y, bool ignoreOccupacy = false)
        {
            var newPosition = new ChessBoardPosition
            {
                CurrentRow    = currentPosition.CurrentRow - x,
                CurrentColumn = currentPosition.CurrentColumn - y,
            };

            if ((newPosition.CurrentRow > -1 && newPosition.CurrentRow < 8) &&
                (newPosition.CurrentColumn > -1 && newPosition.CurrentColumn < 8))
            {
                ChessBoardCell cell = GetCell(newPosition);
                if (cell.IsOccupied && !ignoreOccupacy)
                {
                    return(null);
                }

                return(newPosition);
            }

            return(null);
        }
Exemplo n.º 4
0
        public void Draw()
        {
            ///("_ +___+___+___+___+___+___+___+___+");
            ///("  |   |   |   |   |   |   |   |   |");
            ///("A |   |   |   |   |   |   |   |   |");
            ///("  |___|___|___|___|___|___|___|___|");
            ///("  |   |   |   |   |   |   |   |   |");
            ///("B |   |   |   |   |   |   |   |   |");
            ///("  |___|___|___|___|___|___|___|___|");

            Console.Clear();

            Console.WriteLine();
            Console.WriteLine("   +___+___+___+___+___+___+___+___+");

            for (int row = 0; row < Rows; row++)
            {
                Console.WriteLine("   |   |   |   |   |   |   |   |   |");

                var rowLine = new StringBuilder();
                Console.Write($" {Rows - row} |");

                bool invertEmptySpace = row % 2 != 0;
                for (int column = 0; column < Columns; column++)
                {
                    ChessBoardCell cell = ChessBoardCells[row, column];
                    if (cell.IsOccupied && cell.Entity != null)
                    {
                        if (cell.Entity.ControlType == EntityControlType.Human)
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                        }
                        else if (cell.Entity.ControlType == EntityControlType.Ai)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                        }

                        Console.Write($"{cell}");
                        Console.ResetColor();
                        Console.Write("|");
                    }
                    else
                    {
                        if ((column % 2) == 0)
                        {
                            if (invertEmptySpace)
                            {
                                Console.Write($"{OddCellSymbol}|");
                            }
                            else
                            {
                                Console.Write($"{EvenCellSymbol}|");
                            }
                        }
                        else
                        {
                            if (invertEmptySpace)
                            {
                                Console.Write($"{EvenCellSymbol}|");
                            }
                            else
                            {
                                Console.Write($"{OddCellSymbol}|");
                            }
                        }
                    }
                }

                Console.WriteLine();
                Console.WriteLine("   |___|___|___|___|___|___|___|___|");
            }

            Console.WriteLine("     A   B   C   D   E   F   G   H  ");
        }
Exemplo n.º 5
0
 public void SetCell(ChessBoardPosition chessBoardPosition, ChessBoardCell cell)
 {
     ChessBoardCells[chessBoardPosition.CurrentRow, chessBoardPosition.CurrentColumn] = cell;
 }
Exemplo n.º 6
0
        public Entity GetEntity(PlayerPiece playerPiece)
        {
            ChessBoardCell cell = GetCell(playerPiece.CurrentPosition);

            return(cell.Entity);
        }