Пример #1
0
 // A barricade cannot be placed on a barricade, therefore only a pawn can hit a barricade.
 /*
  * Put the barricade into the current player's hand. This barricade must be placed on the board before the end of the turn.
  *
  * TODO: Can a player hit his own barricade?
  */
 public override bool isHit(Pawn p)
 {
     Player = p.Player;
     Square from = Square;
     p.Player.Baricade = this;
     Square.Piece = null;
     p.Square.removePawn(p);
     from.setPawn(p);
     Square = null;
     return true;
 }
Пример #2
0
        // Only a pawn can hit a pawn.
        /*
         * The method isHit replaces the pawn on the square with the one in the signature and
         * places it in the associated player's starting position.
         */
        public override bool isHit(Pawn p)
        {
            if (this.Square.mayPawnBeHit())
            {
                // If the current player tries to hit one of his own pawns, then return false.
                if (this.Player == p.Player)
                {
                    return false;
                }

                Square to = Square.getReturnTo();
                Square from = Square;
                Square.removePawn(this);
                from.setPawn(p);
                to.setPawn(this);
                return true;
            }
            return false;
        }
Пример #3
0
 public override void setPawn(Pawn p)
 {
     base.setPawn(p);
     board.Game.Finished = true;
 }
Пример #4
0
 private void addPawn(Pawn p)
 {
     Pieces.Add(p);
 }
Пример #5
0
 public override void setPawn(Pawn p)
 {
     p.Square = this;
     Pieces.Add(p);
 }
Пример #6
0
 public override void removePawn(Pawn p)
 {
     p.Square = null;
     bool check = Pieces.Remove(p);
 }
Пример #7
0
        public Game Load(String uri)
        {
            XmlReader r = XmlReader.Create(uri);

            board = null;
            FinishSquare f = null;
            ForestSquare forest = null;
            Square previous = null;

            playerSquares = new List<PlayerSquare>();
            linkList = new List<Square>();
            playerList = new Circuit<Player>();
            baricades = new List<BaricadePiece>();
            pawns = new List<Pawn>();
            baricadeSquares = new List<Square>();
            connectors = new List<Connector>();

            while (r.Read())
            {
                if (r.Name.ToLower() == "square")
                {
                    Square s = new Square(board);
                    if (s.readElement(r))
                    {
                        s.View = new VSquare(s);
                        insertInto(s.Id, s);
                        previous = s;
                    }
                }

                else if (r.Name.ToLower() == "villagesquare")
                {
                    VillageSquare s = new VillageSquare(board);
                    if (s.readElement(r))
                    {
                        insertInto(s.Id, s);
                        previous = s;
                    }
                }

                else if (r.Name.ToLower() == "baricadesquare")
                {
                    BaricadeSquare s = new BaricadeSquare(board);
                    if (s.readElement(r))
                    {
                        insertInto(s.Id, s);
                        baricadeSquares.Add(s);
                        previous = s;
                    }
                }

                else if (r.Name.ToLower() == "baricadevillagesquare")
                {
                    BaricadeVillageSquare s = new BaricadeVillageSquare(board);
                    if(s.readElement(r))
                    {
                        insertInto(s.Id, s);
                        baricadeSquares.Add(s);
                        previous = s;
                    }
                }

                else if (r.Name.ToLower() == "restsquare")
                {
                    RestSquare s = new RestSquare(board);
                    if(s.readElement(r))
                    {
                        insertInto(s.Id,s);
                    }
                }

                else if (r.Name.ToLower() == "playersquare")
                {
                    PlayerSquare s = new PlayerSquare(board);
                    if (s.readElement(r))
                    {
                        playerSquares.Add(s);
                        insertInto(s.Id, s);
                        previous = s;
                    }
                }

                else if (r.Name.ToLower() == "pawn")
                {
                    Pawn p = new Pawn();
                    if (p.readElement(r))
                    {
                        pawns.Add(p);
                    }

                }

                else if (r.Name.ToLower() == "baricadepiece")
                {
                    BaricadePiece b = new BaricadePiece();
                    if (b.readElement(r))
                    {
                        baricades.Add(b);
                    }
                }

                else if (r.Name.ToLower() == "lowrowsquare")
                {
                    LowRowSquare s = new LowRowSquare(board);
                    if (s.readElement(r))
                    {
                        insertInto(s.Id, s);
                    }
                }

                else if (r.Name.ToLower() == "connector")
                {
                    Connector s = new Connector(board);
                    if (s.readElement(r))
                    {
                        insertInto(s.Id, s);
                        connectors.Add(s);
                    }
                }

                else if (r.Name.ToLower() == "player")
                {
                    Player p = new Player(playerList);
                    if (p.readElement(r))
                    {
                        _numberofPlayers++;
                        _numberOfHumanPlayers++;

                        p.PlayerSquare = (PlayerSquare)linkList[find(p.PlayerSquareId)];
                        p.PlayerId = playerList.Count + 1;
                        playerList.Add(p);
                    }
                }

                else if (r.Name.ToLower() == "aiplayer")
                {
                    AIPlayer p = new AIPlayer(playerList);
                    if (p.readElement(r))
                    {
                        _numberOfAIPlayers++;
                        _numberOfHumanPlayers++;
                        p.PlayerSquare = (PlayerSquare)linkList[find(p.PlayerSquareId)];
                        p.PlayerId = playerList.Count + 1;
                        playerList.Add(p);
                    }
                }

                else if (r.Name.ToLower() == "finishsquare")
                {
                    FinishSquare s = new FinishSquare(board);
                    if (s.readElement(r))
                    {
                        f = s;
                        insertInto(s.Id, s);
                        previous = s;
                    }
                }
                else if (r.Name.ToLower() == "forestsquare")
                {
                    ForestSquare s = new ForestSquare(board);
                    if (s.readElement(r))
                    {
                        forest = s;
                        insertInto(s.Id, s);
                        previous = s;
                    }
                }
                else if (r.Name.ToLower() == "board")
                {
                    Board b = new Board();
                    if (b.readElement(r))
                    {
                        board = b;
                        _numberOfPawns = board.NumberOfPawns;
                    }
                }
            }
            r.Close();
            link();
            setPiecesToSquares();
            setPawnsToPlayer();
            checkPlayers();
            checkPieces();
            playerList.setCurrent(_currentPlayer);
            setPosition(f, f.X, f.Y);
            conectors();
            board.Squares = linkList;
            board.Baricades = baricades;
            if (forest != null)
            {
                board.ForestSquare = forest;
            }
            Game game = new Game(board, playerList, f);
            board.Game = game;
            return game;
        }
Пример #8
0
 public VPawn(Pawn pawn)
     : base(pawn)
 {
 }