Esempio n. 1
0
 public void Init(ref Canvas canvas)
 {
     _current  = total;
     Time      = TimeSpan.Zero;
     State     = TilesState.Ready;
     _selected = Choose();
     Layout(ref canvas);
 }
Esempio n. 2
0
 private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
 {
     if (State != TilesState.Lost)
     {
         Grid      grid = (Grid)sender;
         TilesItem item = (TilesItem)grid.Tag;
         if (item.Type == TilesType.Black)
         {
             _current--;
             if (_current == item.Row)
             {
                 if (State != TilesState.Started)
                 {
                     _start = DateTime.Now;
                     State  = TilesState.Started;
                 }
                 grid.Background = GetBrush(TilesType.Correct);
                 _height         = _height + tile_height;
                 Canvas.SetTop(_layout, _height);
                 if (_current == offset + 1)
                 {
                     _height = _height + tile_height;
                     Canvas.SetTop(_layout, _height);
                     Time = DateTime.Now - _start;
                     if (Best == TimeSpan.Zero || Time < Best)
                     {
                         Best = Time;
                     }
                     State = TilesState.Complete;
                 }
                 else
                 {
                     State = TilesState.Started;
                 }
             }
             else
             {
                 grid.Background = GetBrush(TilesType.Incorrect);
                 State           = TilesState.Lost;
             }
         }
         else if (item.Type == TilesType.White)
         {
             grid.Background = GetBrush(TilesType.Incorrect);
             State           = TilesState.Lost;
         }
         StateChanged?.Invoke(State);
     }
 }
Esempio n. 3
0
        private async void Board_StateChanged(TilesState state)
        {
            switch (state)
            {
            case TilesState.Lost:
                await ShowDialogAsync($@"Game Over, You Lost! Best Time: {_board.Best:ss\.fff}");

                break;

            case TilesState.Complete:
                await ShowDialogAsync($@"Completion Time: {_board.Time:ss\.fff}, Best Time: {_board.Best:ss\.fff}");

                break;
            }
        }
 internal static bool NotWall(this TilesState state)
 {
     return(state == TilesState.CheckedFalse || state == TilesState.UnChecked);
 }
 internal static bool IsWall(this TilesState state)
 {
     return(state == TilesState.CheckedTrue);
 }
    private void CreateGO(TileType tile, Vector2I pos)
    {
        if (tile == TileType.OutOfMap)
        {
            return;
        }
        GridBlock  com;
        GameObject inst;

        if (tile == TileType.Floor)
        {
            inst = Instantiate(FloorPrefabs.GetRandomEntry());
            ++GridBlock.FloorCount;
            com              = inst.GetComponent <GridBlock>();
            com.TileType     = tile;
            com.GridPosition = pos;

            com.transform.parent = transform;
            com.Position         = com.GridPosition.WorldPosition;
            GridBlock.Add(com);
            return;
        }

        inst = Instantiate(FloorPrefabs.GetRandomEntry());
        inst.transform.parent   = transform;
        inst.transform.position = pos.FromX_Y2Z();
        Destroy(inst.GetComponent <GridBlock>());
        inst = null;

        var        neighbour = Map.Value.Neighbours(pos, false);
        TilesState up        = TilesState.UnChecked,
                   down      = TilesState.UnChecked,
                   left      = TilesState.UnChecked,
                   right     = TilesState.UnChecked;

        var checkPos = pos + Vector2I.Up;

        if (neighbour.ContainsPos(checkPos) && neighbour.Neighbours[checkPos] == TileType.Wall)
        {
            up = TilesState.CheckedTrue;
        }
        checkPos = pos + Vector2I.Down;
        if (neighbour.ContainsPos(checkPos) && neighbour.Neighbours[checkPos] == TileType.Wall)
        {
            down = TilesState.CheckedTrue;
        }
        checkPos = pos + Vector2I.Left;
        if (neighbour.ContainsPos(checkPos) && neighbour.Neighbours[checkPos] == TileType.Wall)
        {
            left = TilesState.CheckedTrue;
        }
        checkPos = pos + Vector2I.Right;
        if (neighbour.ContainsPos(checkPos) && neighbour.Neighbours[checkPos] == TileType.Wall)
        {
            right = TilesState.CheckedTrue;
        }
        //ALL
        if (neighbour.Neighbours.All(e => e.Value == TileType.Wall))
        {
            if (up.IsWall() && !down.IsWall() && !left.IsWall() && !right.IsWall())
            {
                inst = Instantiate(Pillar_E_Prefab);
            }
            else if (!up.IsWall() && down.IsWall() && !left.IsWall() && !right.IsWall())
            {
                inst = Instantiate(Pillar_E_Prefab);
                inst.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
            }
            else if (!up.IsWall() && !down.IsWall() && left.IsWall() && !right.NotWall())
            {
                inst = Instantiate(Pillar_E_Prefab);
                inst.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
            }
            else if (!up.IsWall() && !down.IsWall() && !left.IsWall() && right.IsWall())
            {
                inst = Instantiate(Pillar_E_Prefab);
                inst.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
            }
            else
            {
                inst = Instantiate(Wall_X_Prefab);
            }
        }
        //3
        else if (!up.IsWall() && down.IsWall() && left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Wall_T_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
        }
        else if (up.IsWall() && !down.IsWall() && left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Wall_T_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
        }
        else if (up.IsWall() && down.IsWall() && !left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Wall_T_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
        }
        else if (up.IsWall() && down.IsWall() && left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Wall_T_Prefab);
        }
        //2
        ////Straight
        else if (up.IsWall() && down.IsWall() && !left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Wall_S_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
        }
        else if (!up.IsWall() && !down.IsWall() && left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Wall_S_Prefab);
        }
        //
        ////Corner
        else if (!up.IsWall() && down.IsWall() && left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_L_Prefab);
        }
        else if (!up.IsWall() && down.IsWall() && !left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Pillar_L_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
        }
        else if (up.IsWall() && !down.IsWall() && left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_L_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
        }
        else if (up.IsWall() && !down.IsWall() && !left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Pillar_L_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
        }
        //1
        else if (up.IsWall() && !down.IsWall() && !left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_E_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
        }
        else if (!up.IsWall() && down.IsWall() && !left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_E_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(90, Vector3.up);
        }
        else if (!up.IsWall() && !down.IsWall() && left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_E_Prefab);
        }
        else if (!up.IsWall() && !down.IsWall() && !left.IsWall() && right.IsWall())
        {
            inst = Instantiate(Pillar_E_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(180, Vector3.up);
        }
        //0
        else if (!up.IsWall() && !down.IsWall() && !left.IsWall() && !right.IsWall())
        {
            inst = Instantiate(Pillar_Prefab);
            inst.transform.rotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0, 4) * 90, Vector3.up);
        }
        //ELSE
        else
        {
            inst = Instantiate(Pillar_X_Prefab);
        }


        com              = inst.GetComponent <GridBlock>();
        com.TileType     = tile;
        com.GridPosition = pos;

        com.transform.parent = transform;
        com.Position         = com.GridPosition.WorldPosition;
        GridBlock.Add(com);
        ++GridBlock.WallCount;
    }