예제 #1
0
    public void TestIsValidPosition()
    {
        bool result;

        // (0, 0) is a valid position
        result = TilePosition.IsValidPosition(0, 0);
        Assert.AreEqual(result, true);

        // (2, 2) is a valid position
        result = TilePosition.IsValidPosition(0, 0);
        Assert.AreEqual(result, true);

        // y has to be positive
        result = TilePosition.IsValidPosition(0, -4);
        Assert.AreEqual(result, false);

        // x and y must have the same parity
        result = TilePosition.IsValidPosition(0, 1);
        Assert.AreEqual(result, false);
    }
예제 #2
0
    public List <TilePosition> GetAdjacentPositions()
    {
        List <TilePosition> adjacent_pos = new List <TilePosition> ();
        int x, y;

        func AddIfValid = (List <TilePosition> p_list, int x_, int y_) =>
        {
            if (TilePosition.IsValidPosition(x_, y_))
            {
                adjacent_pos.Add(new TilePosition(x_, y_));
            }
        };

        // Above
        x = this.x;
        y = this.y - 2;
        AddIfValid(adjacent_pos, x, y);
        // Below
        x = this.x;
        y = this.y + 2;
        AddIfValid(adjacent_pos, x, y);
        // Top left
        x = this.x - 1;
        y = this.y - 1;
        AddIfValid(adjacent_pos, x, y);
        // Bottom left
        x = this.x - 1;
        y = this.y + 1;
        AddIfValid(adjacent_pos, x, y);
        // Top right
        x = this.x + 1;
        y = this.y - 1;
        AddIfValid(adjacent_pos, x, y);
        // Bottom right
        x = this.x + 1;
        y = this.y + 1;
        AddIfValid(adjacent_pos, x, y);

        return(adjacent_pos);
    }