Esempio n. 1
0
    public GameBoardState Clone()
    {
        GameBoardState newGbs = new GameBoardState(this.levels, this.rows, this.cols);

        IGameBoardState igbs = this;

        for (int lvl = 0; lvl < (igbs.GetNumLevels()); lvl++)
        {
            for (int row = 0; row < (igbs.GetNumRows()); row++)
            {
                for (int col = 0; col < (igbs.GetNumCols()); col++)
                {
                    ISpaceState iss = igbs.GetSpaceState(lvl, row, col);
                    newGbs.spaces[lvl][row][col].occupied = iss.IsOccupied();
                    IPieceState ips = iss.Occupier();

                    if (ips != null)
                    {
                        PieceState ps = ips.CreatePieceState();
                        newGbs.spaces[lvl][row][col].occupier = ps;
                        newGbs.AlivePieces.Add(ps);
                        ps.space = newGbs.spaces[lvl][row][col];
                    }
                }
            }
        }

        foreach (IPieceState piece in DeadPieces)
        {
            newGbs.DeadPieces.Add(piece.CreatePieceState());
        }

        return(newGbs);
    }
Esempio n. 2
0
    public SpaceState CreateSpaceState()
    {
        SpaceState ss = new SpaceState();

        ss.occupied = ((ISpaceState)this).IsOccupied();

        IPieceState ps = ((ISpaceState)this).Occupier();


        if (ps != null)
        {
            ss.occupier = ps.CreatePieceState();
        }

        return(ss);
    }
Esempio n. 3
0
    SpaceState ISpaceState.CreateSpaceState()
    {
        SpaceState ss = new SpaceState();

        IPieceState ps = ((ISpaceState)this).Occupier();

        if (ps != null)
        {
            ss.occupier = ps.CreatePieceState();
        }
        ss.occupied = ((ISpaceState)this).IsOccupied();
        ss.level    = this.level;
        ss.row      = this.row;
        ss.col      = this.col;

        return(ss);
    }