Example #1
0
    /// <summary>
    /// Checks if the tile in the input direction is valid of not.
    /// </summary>
    /// <param name="direction"/>
    private void Move(Direction direction)
    {
        int nextRow = row;
        int nextCol = col;

        // Check for board bounds
        switch (direction)
        {
        case Direction.NORTH:
            nextRow--;
            if (row <= 0)
            {
                return;
            }
            break;

        case Direction.SOUTH:
            nextRow++;
            if (row >= gridSize - 1)
            {
                return;
            }
            break;

        case Direction.EAST:
            nextCol++;
            if (col >= gridSize - 1)
            {
                return;
            }
            break;

        case Direction.WEST:
            nextCol--;
            if (col <= 0)
            {
                return;
            }
            break;
        }

        // Check if altitudes match
        if (board.boardIsFlipped &&
            board.myTiles[nextRow, nextCol].CurrentStatus != Tile.TileStatus.CHANGED)
        {
            return;
        }

        if (!board.boardIsFlipped &&
            board.myTiles[nextRow, nextCol].CurrentStatus != Tile.TileStatus.UNCHANGED)
        {
            return;
        }

        // valid moves

        // attempt to remove the tile
        TileRemoval();

        // lower the tile
        board.LowerTile(row, col);

        // destination position
        Vector3 destination = new Vector3(0, 0, 0);

        switch (direction)
        {
        case Direction.NORTH:
            bear.transform.rotation = Quaternion.Euler(0, -90, 0);
            destination             = new Vector3(-tileSize, 0, 0);
            break;

        case Direction.SOUTH:
            bear.transform.rotation = Quaternion.Euler(0, 90, 0);
            destination             = new Vector3(tileSize, 0, 0);
            break;

        case Direction.EAST:
            bear.transform.rotation = Quaternion.Euler(0, 0, 0);
            destination             = new Vector3(0, 0, tileSize);
            break;

        case Direction.WEST:
            bear.transform.rotation = Quaternion.Euler(0, 180, 0);
            destination             = new Vector3(0, 0, -tileSize);
            break;
        }

        // translate
        transform.Translate(destination);

        // update current position
        this.col = nextCol;
        this.row = nextRow;

        if (!isTutorial)
        {
            // Enemy moves
            int[] newPos = enemyController.moveEnemy();
            if (newPos.Length > 0)
            {
                row = newPos[0];
                col = newPos[1];
            }
        }
        else
        {
            enemyController.spawnPoint(0, 0);
            if (this.row == 0 && this.col == 0)
            {
                row = 2;
                col = 2;
                transform.position = new Vector3(row * tileSize, 2, col * tileSize);
            }
        }

        // pick up a flag
        Flag flag = IsOnFlag();

        if (flag != null)
        {
            if (!flag.CollectFlag())
            {
                Debug.Log("Cannot remove flag");
            }
        }

        // check if won
        if (HasWonGame())
        {
            Debug.Log("Win!!");

            gameManager.GetComponent <GameManager>().WinGame();
        }
    }