コード例 #1
0
ファイル: Loader.cs プロジェクト: spboom/Baricade
        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;
        }
コード例 #2
0
ファイル: Loader.cs プロジェクト: spboom/Baricade
        internal Game Load(string s, int humanPlayers)
        {
            int humans=0;
            Game game = Load(s);
            Circuit<Player> players = new Circuit<Player>();
            for (int i = 0; i < baricades.Count; i++)
            {
                baricades[i].Square.Piece = null;
                baricades[i].Square = null;
            }

            baricades = new List<BaricadePiece>();
            while (baricades.Count < baricadeSquares.Count)
            {
                BaricadePiece b = new BaricadePiece();
                baricadeSquares[baricades.Count].Piece = b;
                b.Square = baricadeSquares[baricades.Count];
                baricades.Add(b);
            }

            for(int i=0;i<game.Players.Count;i++)
            {
                Player p = game.Players.pop();
                for(int j=0;j<p.PlayerPawns.Count;j++)
                {
                    p.PlayerPawns[j].Square.removePawn(p.PlayerPawns[j]);
                }
                PlayerColor color = p.Color;
                int id = p.PlayerId;
                PlayerSquare square = p.PlayerSquare;

                if (humans < humanPlayers)
                {
                    p = new Player(players);
                    humans++;
                }
                else
                {
                    p = new AIPlayer(players);
                }
                p.PlayerSquare = square;
                p.PlayerId = id;
                p.Color = color;

                for (int j = 0; j < game.Board.NumberOfPawns; j++)
                {
                    p.addPawn(new Pawn(null,p));
                }
                players.Add(p);
            }
            game.Players = players;
            return game;
        }
コード例 #3
0
ファイル: VBaricade.cs プロジェクト: spboom/Baricade
 public VBaricade(BaricadePiece baricade)
     : base(baricade)
 {
     this.barricade = baricade;
 }