示例#1
0
    // ----------------------------------------------------------------
    private void InitPuzzle(int mapIndex)
    {
        if (mapIndex < 0 || mapIndex >= Maps.Count)
        {
            SetGameState(EGameState.GameOver);
            return;
        }

        SetGameState(EGameState.GamePlay);

        CurrentMapIndex = mapIndex;
        MapInfo currentMap = Maps[mapIndex];

        //currentMap.DebugLog();

        PositionOnGrid playerPos = currentMap.PlayerStartingPosRand();

        Rigidbody2D playerRb = PlayerController.GetComponent <Rigidbody2D>();

        if (playerRb == null)
        {
            return;
        }

        float zeroX = playerRb.transform.position.x - playerPos.X * PuzzleController.TileSize;
        float zeroY = playerRb.transform.position.y - playerPos.Y * PuzzleController.TileSize;

        PuzzleController.ClearBoard();
        PuzzleController.Generate(currentMap, zeroX, zeroY);
        PlayerController.Init(playerPos);

        StartLevelMoves = MovesAvailable;
    }
    public static PositionOnGrid Previous(this PositionOnGrid position)
    {
        PositionOnGrid[] posArray = (PositionOnGrid[])Enum.GetValues(typeof(PositionOnGrid));
        int previousIndex         = System.Array.IndexOf(posArray, position) - 1;

        return((previousIndex <= 0) ? posArray[0] : posArray[previousIndex]);
    }
    public static int GetUnshiftedNumber(this PositionOnGrid position)
    {
        PositionOnGrid[] posArray = (PositionOnGrid[])Enum.GetValues(typeof(PositionOnGrid));
        int posInIndex            = System.Array.IndexOf(posArray, position);

        return(posInIndex);
    }
    public static PositionOnGrid Next(this PositionOnGrid position)
    {
        PositionOnGrid[] posArray = (PositionOnGrid[])Enum.GetValues(typeof(PositionOnGrid));
        int nextIndex             = System.Array.IndexOf(posArray, position) + 1;

        return((nextIndex >= posArray.Length) ? posArray[0] : posArray[nextIndex]);
    }
示例#5
0
    // ----------------------------------------------------------------
    public ESin?GetSin(PositionOnGrid p)
    {
        if (PuzzleMapExtended[p.Y][p.X] < 0)
        {
            return(null);
        }

        return((ESin)(PuzzleMapExtended[p.Y][p.X]));
    }
示例#6
0
    // ----------------------------------------------------------------
    public void Init(PositionOnGrid pos)
    {
        Pos = pos;

        Rigidbody2D rb = GetComponent <Rigidbody2D>();

        Destination = rb.position;

        SetMoving(false);
    }
示例#7
0
    // ----------------------------------------------------------------
    private void UpdateGamePlay()
    {
        if (PlayerController.Moving)
        {
            return;
        }

        if (MovesAvailable <= 0 && PlayerController.Moving == false)
        {
            SetGameState(EGameState.GameOver);
            return;
        }

        MapInfo currentMap = Maps[CurrentMapIndex];

        if (currentMap.IsTileType(PlayerController.Pos, ETile.Out))
        {
            DoorOpened = false;
            InitPuzzle(CurrentMapIndex + 1);
            return;
        }

        EDirection dir = DirectionFromKeyboard();

        if (dir == EDirection.No)
        {
            return;
        }

        PositionOnGrid newPos      = new PositionOnGrid(PlayerController.Pos.X, PlayerController.Pos.Y);
        Vector2        destination = PuzzleController.GetDestination(currentMap, ref newPos, dir, DoorOpened);

        bool madeMove = newPos.X != PlayerController.Pos.X || newPos.Y != PlayerController.Pos.Y;

        ESin?newSin = currentMap.GetSin(newPos);

        // If not moving to a board pos, move without penalization
        if (newSin.HasValue == false)
        {
            PlayerController.Pos = newPos;
            PlayerController.MoveTo(destination);
            return;
        }

        // Else move to an unlocked board pos and increase sin score
        PlayerController.Pos = newPos;
        PlayerController.MoveTo(destination);

        if (madeMove)
        {
            SetAvailableMoves(MovesAvailable - 1);
        }
    }
示例#8
0
 // ----------------------------------------------------------------
 public EndingPoint(int x, int y, int m)
 {
     Pos          = new PositionOnGrid(x, y);
     mapInfoIndex = m;
 }
示例#9
0
    // ----------------------------------------------------------------
    public Vector2 GetDestination(MapInfo mi, ref PositionOnGrid newPos, EDirection d, bool doorOpened)
    {
        int x = newPos.X;
        int y = newPos.Y;

        int destX = newPos.X;
        int destY = newPos.Y;

        List <List <int> > map = mi.PuzzleMapExtended;

        PositionOnGrid nextPos = newPos.NextPos(d);

        // Ca not move if undef or void
        if (false == mi.IsDefined(nextPos) || mi.IsTileType(nextPos, ETile.Void))
        {
            return(GetDestinationFromTile(newPos));
        }

        // Can not move from board back to in tile
        if (mi.IsTileType(newPos, ETile.In) == false && mi.IsTileType(nextPos, ETile.In))
        {
            return(GetDestinationFromTile(newPos));
        }

        // If in, move just one tile
        if (mi.IsTileType(nextPos, ETile.In))
        {
            newPos = nextPos;
            return(GetDestinationFromTile(newPos));
        }

        // If out, move only if door opened
        if (mi.IsTileType(nextPos, ETile.Out))
        {
            if (doorOpened)
            {
                newPos = nextPos;
            }
            return(GetDestinationFromTile(newPos));
        }

        // Else inside map - move through all tiles with the same color
        switch (d)
        {
        case EDirection.Up:
            for (int i = y + 1; i < map.Count; i++)
            {
                if (map[y + 1][x] == map[i][x])
                {
                    destY = i;
                }
                else
                {
                    break;
                }
            }
            break;

        case EDirection.Right:
            for (int i = x + 1; i < map[y].Count; i++)
            {
                if (map[y][x + 1] == map[y][i])
                {
                    destX = i;
                }
                else
                {
                    break;
                }
            }
            break;

        case EDirection.Down:
            for (int i = y - 1; i >= 0; i--)
            {
                if (map[y - 1][x] == map[i][x])
                {
                    destY = i;
                }
                else
                {
                    break;
                }
            }
            break;

        case EDirection.Left:
            for (int i = x - 1; i >= 0; i--)
            {
                if (map[y][x - 1] == map[y][i])
                {
                    destX = i;
                }
                else
                {
                    break;
                }
            }
            break;
        }

        newPos.X = destX;
        newPos.Y = destY;

        return(GetDestinationFromTile(newPos));
    }
示例#10
0
 // ----------------------------------------------------------------
 private Vector2 GetDestinationFromTile(PositionOnGrid pos)
 {
     return(new Vector2(OffsetX + pos.X * TileSize, OffsetY + pos.Y * TileSize));
 }
示例#11
0
 // ----------------------------------------------------------------
 public bool IsTileType(PositionOnGrid p, ETile type)
 {
     return((int)type == PuzzleMapExtended[p.Y][p.X]);
 }
示例#12
0
 // ----------------------------------------------------------------
 public bool IsDefined(PositionOnGrid p)
 {
     return(p.X >= 0 && p.Y >= 0 && p.X < DimColsExtended() && p.Y < DimRowsExtended());
 }