Beispiel #1
0
    public void TestFullGridIsBlocked()
    {
        HyperGrid hyperGrid = new HyperGrid(5, 5, 5, 5);

        for (int x = 0; x < 5; x++)
        {
            for (int y = 0; y < 5; y++)
            {
                for (int z = 0; z < 5; z++)
                {
                    for (int w = 0; w < 5; w++)
                    {
                        hyperGrid.setBlocked(x, y, z, w);
                    }
                }
            }
        }

        bool isBlocked1 = hyperGrid.checkBlocked(0, 2, 0, 0);
        bool isBlocked2 = hyperGrid.checkBlocked(0, 0, 2, 2);
        bool isBlocked3 = hyperGrid.checkBlocked(0, 3, 1, 0);
        bool isBlocked4 = hyperGrid.checkBlocked(2, 1, 3, 3);

        Assert.IsTrue(isBlocked1);
        Assert.IsTrue(isBlocked2);
        Assert.IsTrue(isBlocked3);
        Assert.IsTrue(isBlocked4);
    }
Beispiel #2
0
    public void TestWalkForward()
    {
        // Given
        HyperGrid      hyperGrid       = new HyperGrid(8, 8, 8, 8);
        HyperPosition  playerPosition  = new HyperPosition(0, 1, 0, 3);
        HyperDirection playerDirection = new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left);
        Player         player          = new Player(playerPosition, playerDirection);
        Game           game            = new Game(player, hyperGrid);

        for (int x = 0; x < 7; x++)
        {
            hyperGrid.setBlocked(x, 0, 0, 3);
        }

        //When
        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 1, 0, 3), player.position, player.position.printOut());
        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(2, 1, 0, 3), player.position, player.position.printOut());
        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 1, 0, 3), player.position, player.position.printOut());
        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(4, 1, 0, 3), player.position, player.position.printOut());

        //Then
        Assert.AreEqual(new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left), player.direction);
    }
Beispiel #3
0
    public void PlayerOnWinPlayerWins()
    {
        // Given
        HyperPosition playerStart = new HyperPosition(0, 0, 0, 0);
        Player        player      = new Player(playerStart, HyperDirection.normal);

        HyperGrid hyperGrid = new HyperGrid(8, 8, 8, 8);
        Game      game      = new Game(player, hyperGrid, new HyperPosition(0, 0, 0, 0));

        Assert.IsTrue(game.checkWon());
    }
Beispiel #4
0
    public static HyperGrid TenByTenPlatformAtWZero()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);

        for (int x = 2; x < 8; x++)
        {
            for (int z = 2; z < 8; z++)
            {
                hyperGrid.setBlocked(x, 2, z, 0);
            }
        }
        return(hyperGrid);
    }
Beispiel #5
0
    public void TestEmptyGridIsNotBlocked()
    {
        HyperGrid hyperGrid  = new HyperGrid(5, 5, 5, 5);
        bool      isBlocked1 = hyperGrid.checkBlocked(0, 0, 0, 0);
        bool      isBlocked2 = hyperGrid.checkBlocked(0, 0, 2, 2);
        bool      isBlocked3 = hyperGrid.checkBlocked(0, 3, 1, 0);
        bool      isBlocked4 = hyperGrid.checkBlocked(2, 3, 3, 3);

        Assert.IsFalse(isBlocked1);
        Assert.IsFalse(isBlocked2);
        Assert.IsFalse(isBlocked3);
        Assert.IsFalse(isBlocked4);
    }
Beispiel #6
0
    public void CreatePathToUp()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);

        hyperGrid.createPath(new HyperPosition(0, 0, 0, 0), Direction.up, 7);

        Assert.IsTrue(hyperGrid.checkBlocked(0, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 1, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 2, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 3, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 4, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 5, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(0, 6, 0, 0));

        Assert.IsFalse(hyperGrid.checkBlocked(0, 7, 0, 0));
    }
Beispiel #7
0
    public static HyperGrid TenByTenCube()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);

        for (int x = 2; x < 8; x++)
        {
            for (int z = 2; z < 8; z++)
            {
                for (int y = 2; y < 8; y++)
                {
                    hyperGrid.setBlocked(x, y, z, 0);
                }
            }
        }
        return(hyperGrid);
    }
Beispiel #8
0
    public void TestGameMovesPlayerDownAndForward()
    {
        // Given
        HyperGrid      hyperGrid       = new HyperGrid(5, 5, 5, 5);
        HyperPosition  playerPosition  = new HyperPosition(0, 1, 0, 0);
        HyperDirection playerDirection = new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left);
        Player         player          = new Player(playerPosition, playerDirection);
        Game           game            = new Game(player, hyperGrid);

        hyperGrid.setBlocked(0, 0, 0, 0);

        //When
        game.process(MoveIntent.forward);

        //Then
        Assert.AreEqual(new HyperPosition(1, 0, 0, 0), player.position);
    }
Beispiel #9
0
    //---------------------Easy Grid Creation, to be removed--------------
    public static HyperGrid ConstructedLevel()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);

        hyperGrid.createPath(new HyperPosition(2, 2, 2, 0), Direction.east, 6);
        hyperGrid.createPath(new HyperPosition(2, 2, 2, 0), Direction.north, 6);
        hyperGrid.createPath(new HyperPosition(2, 2, 7, 0), Direction.east, 6);
        hyperGrid.createPath(new HyperPosition(2, 2, 2, 0), Direction.left, 6);
        hyperGrid.createPath(new HyperPosition(7, 2, 7, 0), Direction.up, 6);
        hyperGrid.createPath(new HyperPosition(2, 2, 7, 6), Direction.south, 6);

        hyperGrid.createPath(new HyperPosition(2, 1, 7, 5), Direction.up, 6);

        hyperGrid.createPath(new HyperPosition(3, 6, 3, 0), Direction.left, 6);

        hyperGrid.createPath(new HyperPosition(3, 6, 4, 0), Direction.north, 6);
        return(hyperGrid);
    }
Beispiel #10
0
 public void updateGrid(HyperGrid hyperGrid, GridSlice slice)
 {
     if (blocks == null)
     {
         createGrid();
     }
     for (int x = 0; x < Constants.sizeX; x++)
     {
         for (int y = 0; y < Constants.sizeY; y++)
         {
             for (int z = 0; z < Constants.sizeZ; z++)
             {
                 GameObject block = blocks[x, y, z];
                 block.SetActive(checkBlockedForDirection(hyperGrid, slice.worldOrientation, x, y, z, slice.unseenDepth));
             }
         }
     }
 }
Beispiel #11
0
    private bool checkBlockedForDirection(HyperGrid hyperGrid, WorldOrientation dir, int x, int y, int z, int w)
    {
        switch (dir)
        {
        case WorldOrientation.xyz:
            return(hyperGrid.checkBlocked(x, y, z, w));

        case WorldOrientation.xyw:
            return(hyperGrid.checkBlocked(x, y, w, z));

        case WorldOrientation.yzw:
            return(hyperGrid.checkBlocked(w, y, z, x));

        case WorldOrientation.xzw:
            return(hyperGrid.checkBlocked(x, w, z, y));
        }
        return(false);
    }
Beispiel #12
0
    public void TestSomeBlockedOthersNot()
    {
        //Given
        HyperGrid hyperGrid = new HyperGrid(8, 8, 8, 8);

        //When
        hyperGrid.setBlocked(0, 0, 0, 0);
        hyperGrid.setBlocked(3, 3, 2, 1);
        hyperGrid.setBlocked(7, 6, 5, 4);
        hyperGrid.setBlocked(3, 0, 2, 7);

        //Then
        Assert.IsTrue(hyperGrid.checkBlocked(0, 0, 0, 0));
        Assert.IsFalse(hyperGrid.checkBlocked(0, 0, 0, 1));
        Assert.IsTrue(hyperGrid.checkBlocked(3, 3, 2, 1));
        Assert.IsFalse(hyperGrid.checkBlocked(7, 7, 7, 7));
        Assert.IsTrue(hyperGrid.checkBlocked(7, 6, 5, 4));
        Assert.IsTrue(hyperGrid.checkBlocked(3, 0, 2, 7));
    }
Beispiel #13
0
    public void CreatePathToEast()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);

        hyperGrid.createPath(new HyperPosition(0, 0, 0, 0), Direction.east, 7);

        Assert.IsTrue(hyperGrid.checkBlocked(0, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(1, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(2, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(3, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(4, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(5, 0, 0, 0));
        Assert.IsTrue(hyperGrid.checkBlocked(6, 0, 0, 0));
        Assert.IsFalse(hyperGrid.checkBlocked(7, 0, 0, 0));

        Assert.IsFalse(hyperGrid.checkBlocked(8, 0, 0, 0));
        Assert.IsFalse(hyperGrid.checkBlocked(0, 1, 0, 0));
        Assert.IsFalse(hyperGrid.checkBlocked(0, 0, 1, 0));
    }
Beispiel #14
0
    public static HyperGrid TenByTenPyramid()
    {
        HyperGrid hyperGrid = new HyperGrid(10, 10, 10, 10);
        int       baseStart = 2;
        int       baseEnd   = 8;

        for (int y = 2; y < 8; y++)
        {
            for (int x = baseStart; x < baseEnd; x++)
            {
                for (int z = baseStart; z < baseEnd; z++)
                {
                    hyperGrid.setBlocked(x, y, z, 0);
                }
            }
            baseStart++;
            baseEnd--;
        }
        return(hyperGrid);
    }
Beispiel #15
0
    public void TestPlayerMovesUp()
    {
        // Given
        HyperGrid      hyperGrid       = new HyperGrid(10, 10, 10, 10);
        HyperPosition  playerPosition  = new HyperPosition(2, 2, 2, 0);
        HyperDirection playerDirection = new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left);
        Player         player          = new Player(playerPosition, playerDirection);
        Game           game            = new Game(player, hyperGrid);

        hyperGrid.setBlocked(2, 1, 2, 0);
        hyperGrid.setBlocked(3, 1, 2, 0);
        hyperGrid.setBlocked(4, 2, 2, 0);
        hyperGrid.setBlocked(4, 3, 2, 0);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 2, 2, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 2, 2, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 3, 2, 0), player.position, player.position.printOut());
    }
Beispiel #16
0
    public void TestGameMovesPlayerFourTimes()
    {
        // Given
        HyperGrid      hyperGrid       = new HyperGrid(10, 10, 10, 10);
        HyperPosition  playerPosition  = new HyperPosition(5, 5, 5, 5);
        HyperDirection playerDirection = new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left);
        Player         player          = new Player(playerPosition, playerDirection);
        Game           game            = new Game(player, hyperGrid);

        hyperGrid.setBlocked(5, 4, 5, 5);

        // When
        game.process(MoveIntent.forward);
        game.process(MoveIntent.forward);
        game.process(MoveIntent.forward);

        //Then
        Assert.AreEqual(new HyperPosition(4, 4, 5, 5), player.position);
        Assert.AreEqual(new HyperDirection(Direction.up, Direction.west, Direction.north, Direction.left), player.direction);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 5, 5, 5), player.position);
    }
Beispiel #17
0
 public Game(Player player, HyperGrid hyperGrid, HyperPosition?levelGoal = null)
 {
     this.player    = player;
     this.hyperGrid = hyperGrid;
     this.levelGoal = levelGoal;
 }
Beispiel #18
0
 public Level(HyperGrid hyperGrid, HyperPosition playerStart, HyperPosition goalPosition)
 {
     this.hyperGrid    = hyperGrid;
     this.playerStart  = playerStart;
     this.goalPosition = goalPosition;
 }
Beispiel #19
0
    public void TestWalkInCircle()
    {
        // Given
        HyperGrid      hyperGrid       = new HyperGrid(10, 10, 10, 10);
        HyperPosition  playerPosition  = new HyperPosition(2, 2, 2, 0);
        HyperDirection playerDirection = new HyperDirection(Direction.east, Direction.up, Direction.north, Direction.left);
        Player         player          = new Player(playerPosition, playerDirection);
        Game           game            = new Game(player, hyperGrid);

        hyperGrid.setBlocked(2, 1, 2, 0);
        hyperGrid.setBlocked(3, 1, 2, 0);
        hyperGrid.setBlocked(4, 1, 2, 0);
        hyperGrid.setBlocked(5, 1, 2, 0);

        hyperGrid.setBlocked(5, 1, 3, 0);
        hyperGrid.setBlocked(5, 1, 4, 0);
        hyperGrid.setBlocked(5, 1, 5, 0);
        hyperGrid.setBlocked(5, 1, 6, 0);

        hyperGrid.setBlocked(4, 1, 6, 0);
        hyperGrid.setBlocked(3, 1, 6, 0);
        hyperGrid.setBlocked(2, 1, 6, 0);
        hyperGrid.setBlocked(1, 1, 6, 0);

        hyperGrid.setBlocked(1, 1, 5, 0);
        hyperGrid.setBlocked(1, 1, 4, 0);
        hyperGrid.setBlocked(1, 1, 3, 0);
        hyperGrid.setBlocked(1, 1, 2, 0);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 2, 2, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(4, 2, 2, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 2, 2, 0), player.position, player.position.printOut());

        game.process(MoveIntent.turnRightSide);
        Assert.AreEqual(new HyperPosition(5, 2, 2, 0), player.position, player.position.printOut());
        Assert.AreEqual(new HyperDirection(Direction.north, Direction.up, Direction.west, Direction.left), player.direction);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 2, 3, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 2, 4, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 2, 5, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(5, 2, 6, 0), player.position, player.position.printOut());

        game.process(MoveIntent.turnRightSide);
        Assert.AreEqual(new HyperPosition(5, 2, 6, 0), player.position, player.position.printOut());
        Assert.AreEqual(new HyperDirection(Direction.west, Direction.up, Direction.south, Direction.left), player.direction);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(4, 2, 6, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(3, 2, 6, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(2, 2, 6, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 2, 6, 0), player.position, player.position.printOut());

        game.process(MoveIntent.turnRightSide);
        Assert.AreEqual(new HyperPosition(1, 2, 6, 0), player.position, player.position.printOut());
        Assert.AreEqual(new HyperDirection(Direction.south, Direction.up, Direction.east, Direction.left), player.direction);

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 2, 5, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 2, 4, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 2, 3, 0), player.position, player.position.printOut());

        game.process(MoveIntent.forward);
        Assert.AreEqual(new HyperPosition(1, 2, 2, 0), player.position, player.position.printOut());
    }