예제 #1
0
        // adds possible moves for king unit
        public void AddMovesKing(Unit king)
        {
            int   yDir   = king.MoveDir;
            Coord kCoord = new Coord(king.UnitCoords.X, king.UnitCoords.Y);

            BoardCell curr = Board.Cells[kCoord.X, kCoord.Y];

            Coord currCoords = kCoord;

            Coord[] dirs = new Coord[4];

            dirs[0] = new Coord(1, yDir);
            dirs[1] = new Coord(-1, yDir);
            dirs[2] = new Coord(1, -yDir);
            dirs[3] = new Coord(-1, -yDir);

            // for every dir check if cell in -> dir is empty and on board
            for (int i = 0; i < dirs.Length; i++)
            {
                Coord cXY = currCoords + dirs[i];

                if (IsCoordsOnBoard(cXY))
                {
                    if (Board.Cells[cXY.X, cXY.Y].Occupant == null)
                    {
                        BoardCell finish = Board.Cells[cXY.X, cXY.Y];

                        int    opponentIdx = (Turn + 1) % 2;
                        Player opponent    = GetPlayer(opponentIdx);
                        Moves.Add(new Move(curr, finish, CurrPlayer, opponent));

                        // Ensure cells that can move has no duplicates
                        if (!CellsAble.Contains(curr))
                        {
                            CellsAble.Add(curr);
                        }
                    }
                }
            }
        }
        public GameBoard(GameManager manager)
        {
            m_manager = manager;

            Cells = new BoardCell[8, 8];

            for (int y = 0; y < 8; y++)
            {
                for (int x = 0; x < 8; x++)
                {
                    Cells[x, y] = new BoardCell(this, x, y);

                    if (y == 0 || y == 7)
                    {
                        Cells[x, y].KingsLane = true;
                    }
                }
            }

            SetUpPlayer1();
            SetUpPlayer2();
        }
예제 #3
0
 public Attack(BoardCell start, BoardCell end, BoardCell defender, Player current, Player opponent)
     : base(start, end, current, opponent)
 {
     m_defenderCell = defender;
 }
예제 #4
0
        // clears the board and armies and replaces the pieces with ones stored in redo history item
        public void Redo()
        {
            Player p1 = Players[0];
            Player p2 = Players[1];

            for (int i = 0; i < p1.ArmyUnits.Count; i++)
            {
                Unit      unit = p1.ArmyUnits[i];
                BoardCell cell = Board.Cells[unit.UnitCoords.X, unit.UnitCoords.Y];

                cell.EmptyCell();
            }

            for (int i = 0; i < p2.ArmyUnits.Count; i++)
            {
                Unit      unit = p2.ArmyUnits[i];
                BoardCell cell = Board.Cells[unit.UnitCoords.X, unit.UnitCoords.Y];

                cell.EmptyCell();
            }

            p1.ArmyUnits = new List <Unit>();
            p1.Kills     = 0;

            p2.ArmyUnits = new List <Unit>();
            p2.Kills     = 0;

            m_history.Redo();

            HistoryItem item = m_history.CurrItem;

            p1.Kills = item.P1Kills;
            p2.Kills = item.P2Kills;
            for (int i = 0; i < item.P1UnitCoords.Count; i++)
            {
                BoardCell cell = Board.Cells[item.P1UnitCoords[i].X, item.P1UnitCoords[i].Y];
                switch (item.P1UnitTypes[i])
                {
                case 0:
                    Man man = new Man(item.P1UnitCoords[i].X, item.P1UnitCoords[i].Y, p1);
                    man.MoveDir = -1;

                    cell.FillCell(man);
                    break;

                case 1:
                    King king = new King(item.P1UnitCoords[i].X, item.P1UnitCoords[i].Y, p1);
                    king.MoveDir = -1;

                    cell.FillCell(king);
                    break;
                }
            }

            for (int i = 0; i < item.P2UnitCoords.Count; i++)
            {
                BoardCell cell = Board.Cells[item.P2UnitCoords[i].X, item.P2UnitCoords[i].Y];
                switch (item.P2UnitTypes[i])
                {
                case 0:
                    Man man = new Man(item.P2UnitCoords[i].X, item.P2UnitCoords[i].Y, p2);
                    man.MoveDir = 1;

                    cell.FillCell(man);
                    break;

                case 1:
                    King king = new King(item.P2UnitCoords[i].X, item.P2UnitCoords[i].Y, p2);
                    king.MoveDir = 1;

                    cell.FillCell(king);
                    break;
                }
            }

            Turn       = item.Turn;
            CurrPlayer = Players[Turn % 2];
        }