Пример #1
0
    public void AreaCreationWorks()
    {
        Dictionary <Coordinate, GameBoardSquare> boardInfo = new Dictionary <Coordinate, GameBoardSquare>();

        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 3; ++j)
            {
                Coordinate      coord  = new Coordinate(i, j);
                GameBoardSquare square = new GameBoardSquare(coord);
                GameCell        cell   = new GameCell();
                square.AddGameCell(cell);
                boardInfo.Add(coord, square);
            }
        }

        GameBoardSquare sq = boardInfo[new Coordinate(0, 0)];

        sq.TopCell.blockedTop   = false;
        sq.TopCell.blockedRight = false;
        GameBoardSquare sq2 = boardInfo[new Coordinate(1, 0)];

        sq2.TopCell.blockedLeft = false;
        GameBoardSquare sq3 = boardInfo[new Coordinate(0, 1)];

        sq3.TopCell.blockedBottom = false;
        sq3.TopCell.blockedRight  = false;

        GameBoard board = new GameBoard(boardInfo);

        Assert.That(board.AreaForSquare(new Coordinate(0, 0)).Size() == 3);
        Assert.That(board.AreaForSquare(new Coordinate(1, 0)).Size() == 3);

        GameBoardSquare sq4 = boardInfo[new Coordinate(1, 1)];

        sq4.TopCell.blockedLeft  = false;
        sq4.TopCell.blockedRight = false;

        Assert.That(board.AreaForSquare(new Coordinate(0, 0)).Size() == 4);
        Assert.That(board.AreaForSquare(new Coordinate(1, 1)).Size() == 4);

        Assert.That(board.AreaForSquare(new Coordinate(2, 2)).Size() == 1);

        boardInfo[new Coordinate(2, 1)].TopCell.blockedLeft   = false;
        boardInfo[new Coordinate(2, 1)].TopCell.blockedTop    = false;
        boardInfo[new Coordinate(2, 2)].TopCell.blockedBottom = false;
        boardInfo[new Coordinate(2, 2)].TopCell.blockedLeft   = false;
        boardInfo[new Coordinate(1, 2)].TopCell.blockedRight  = false;

        Assert.That(board.AreaForSquare(new Coordinate(2, 2)).Size() == 7);
    }
Пример #2
0
    public static GameBoardSquare GameBoardSquareFromNode(JSONNode square)
    {
        int             row    = square["row"];
        int             column = square["column"];
        GameBoardSquare sq     = new GameBoardSquare();
        Coordinate      coord  = new Coordinate(row, column);

        sq.coordinate = coord;
        //TODO: only add GameCell if square is not "greyed out" (add something in the json for that)
        GameCell gameCell = GameCell.GameCellFromJSONNode(square);

        sq.AddGameCell(gameCell);
        return(sq);
    }
Пример #3
0
    public void MoveTileToSquare(Tile t, Coordinate coord)
    {
        if (this.tileMap.ContainsKey(t))
        {
            int tileRow = this.tileMap[t].row;
            int tileCol = this.tileMap[t].column;
            foreach (Coordinate co in t.squareInfo.Keys)
            {
                Coordinate      c      = new Coordinate(co.row + tileRow, co.column + tileCol);
                GameBoardSquare square = this.boardMap[c];
                square.RemoveGameCell(t.squareInfo[co]);
            }
        }

        foreach (Coordinate co in t.squareInfo.Keys)
        {
            Coordinate      c      = new Coordinate(coord.row + co.row, coord.column + co.column);
            GameBoardSquare square = this.boardMap[c];
            square.AddGameCell(t.squareInfo[co]);
        }

        this.tileMap[t] = coord;
    }