Beispiel #1
0
 public Game(Board board, Circuit<Player> players, FinishSquare finish)
 {
     this.board = board;
     this.players = players;
     currentPlayer = players.peek();
     _finishSquare = finish;
 }
Beispiel #2
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;
        }
Beispiel #3
0
 public VFinishSquare(FinishSquare square)
     : base(square)
 {
 }