Пример #1
0
        /// <summary>
        /// The Constructor Making the Grid and the Cells that are inside of it
        /// </summary>
        /// <param name="form"></param>
        public Grid(Form form)
        {
            _form = form;
            //Set the Hold Block to NULL
            BlockThatIsHeld = TypeOfBlock.Null;
            //Allow the user to Hold a Block at the start of the game
            _allowBlockToBeHeld = true;
            //Setting up Number of Cells
            _cells = new Cells[Properties.Settings.Default.Number_Of_Columns, Properties.Settings.Default.Number_Of_Rows];
            //Setting up a grid to hold all the Cells
            Left   = Properties.Settings.Default.Left_Grid_Margin;
            Top    = Properties.Settings.Default.Top_Grid_Margin;
            Width  = Properties.Settings.Default.Number_Of_Columns * Properties.Settings.Default.Cell_Width;
            Height = Properties.Settings.Default.Number_Of_Rows * Properties.Settings.Default.Cell_Height;
            form.Controls.Add(this);
            //Setting Up the Cells and assigning them an location
            int ColumnAdjuster = Left;
            int RowAdjuster    = Top;

            for (int i = 0; i < Properties.Settings.Default.Number_Of_Columns; i++)
            {
                for (int j = 0; j < Properties.Settings.Default.Number_Of_Rows; j++)
                {
                    _cells[i, j] = new Cells(i, j)
                    {
                        Width  = Properties.Settings.Default.Cell_Width,
                        Height = Properties.Settings.Default.Cell_Height,
                        Left   = ColumnAdjuster + (i * Properties.Settings.Default.Cell_Width),
                        Top    = RowAdjuster + (j * Properties.Settings.Default.Cell_Height)
                    };
                    form.Controls.Add(_cells[i, j]);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// This will fire when the user is going to hold a piece
        /// Updates the picture box with the right image
        /// </summary>
        /// <param name="HeldBlock"></param>
        private void Game_LoadHeldPicture(TypeOfBlock HeldBlock)
        {
            Bitmap tmp = FindWhichPictureToLoad(HeldBlock);

            if (tmp != null)
            {
                heldBlockPb.Image = tmp;
            }
        }
Пример #3
0
        /// <summary>
        /// This will find the First Preview block and put it in its rightful place
        /// </summary>
        /// <param name="PreviewBlock"></param>
        private void Game_LoadFirstPreviewPicture(TypeOfBlock PreviewBlock)
        {
            Bitmap tmp = FindWhichPictureToLoad(PreviewBlock);

            if (tmp != null)
            {
                previewOnePb.Image = tmp;
            }
        }
Пример #4
0
    void DrawElbow(TypeOfBlock blockType, Vector2Int startPoint, Vector2Int vector)
    {
        for (int x = 0; x < Mathf.Abs(vector.x); x++)
        {
            SetGirdValueTo(blockType, IntsToV2(startPoint.x + x * (int)Mathf.Sign(vector.x), startPoint.y));
        }

        for (int y = 0; y < Mathf.Abs(vector.y); y++)
        {
            SetGirdValueTo(blockType, IntsToV2(startPoint.x, startPoint.y + y * (int)Mathf.Sign(vector.y)));
        }
    }
Пример #5
0
 /// <summary>
 /// Creates the New Falling Block, for the Grid to Handle
 /// </summary>
 /// <param name="blockType"></param>
 public void CreateFallingBlock(TypeOfBlock blockType)
 {
     BlockThatsFalling = new FallingBlock(blockType);
     //Checks to see if the Blocks are that the top of the screen
     foreach (var item in BlockThatsFalling.BlockCells)
     {
         if (_cells[item.CellLocationX, item.CellLocationY].Filled)
         {
             Overflow?.Invoke();
             return;
         }
         _cells[item.CellLocationX, item.CellLocationY].BackColor = item.BackColor;
     }
 }
Пример #6
0
 protected void ActionIfNextStepImpossible(TypeOfBlock typeOfBlockNext, int xDir, int yDir)
 {
     RaycastHit2D raycastHit2D = GetCurrentRaycast();
         TypeOfBlock typeOfBlockCurrent = raycastHit2D.transform.GetComponent<Tile>().Type;
         if (typeOfBlockNext == TypeOfBlock.EMPTY)
         {
             if (typeOfBlockCurrent == TypeOfBlock.TELEPORT)
             {
                 raycastHit2D.transform.GetComponent<TeleportTile>().SetIsCanTeleport(true);
             }
             else
             {
                 switch (typeOfBlockCurrent)
                 {
                     case TypeOfBlock.MOVE_UP:
                         AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_RIGHT:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_DOWN:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_LEFT:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_UP_DOWN:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_LEFT_RIGHT:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     case TypeOfBlock.MOVE_ALL:
                     AttemptMoveOnPlatform(raycastHit2D, xDir, yDir);
                     break;
                     default:
                         break;
                 }
             }
         }
         else if (typeOfBlockNext == TypeOfBlock.BLOCK || typeOfBlockNext == TypeOfBlock.LOCK_GREEN || typeOfBlockNext == TypeOfBlock.LOCK_RED )
         {
             if (typeOfBlockCurrent == TypeOfBlock.TELEPORT)
             {
                 raycastHit2D.transform.GetComponent<TeleportTile>().SetIsCanTeleport(true);
             }
         }
 }
Пример #7
0
 /// <summary>
 /// Takes the Current Falling Block and puts it into a Hold state
 /// </summary>
 private void HoldFallingBlock()
 {
     if (BlockThatIsHeld == TypeOfBlock.Null)
     {
         //Set the held block value
         BlockThatIsHeld = BlockThatsFalling.BlockType;
         //Set it to false so that the timer tick will fix it
         BlockThatsFalling.IsItFalling = false;
         //Draw out the old block
         if (BlockThatsFalling.BlockCells != null)
         {
             foreach (var old in BlockThatsFalling.BlockCells)
             {
                 _cells[old.CellLocationX, old.CellLocationY].BackColor = Properties.Settings.Default.Grid_Colour;
             }
         }
         //Creates a new falling Block
         CreateFallingBlock(RandomBlock.PullABlock());
     }
     else
     {
         //Get the HoldBlock
         var oldHeldBlock = BlockThatIsHeld;
         //Set the Block that is falling to held
         BlockThatIsHeld = BlockThatsFalling.BlockType;
         //Draw out the old block
         if (BlockThatsFalling.BlockCells != null)
         {
             foreach (var old in BlockThatsFalling.BlockCells)
             {
                 _cells[old.CellLocationX, old.CellLocationY].BackColor = Properties.Settings.Default.Grid_Colour;
             }
         }
         CreateFallingBlock(oldHeldBlock);
     }
     //Event for the Form to Handle, Fixes the Timer Tick
     PieceHeld?.Invoke();
 }
Пример #8
0
        /// <summary>
        /// Finds Which Bitmap to return based on the TypeOfBlock
        /// </summary>
        /// <param name="Block"></param>
        /// <returns>A Bitmap of the Block</returns>
        private Bitmap FindWhichPictureToLoad(TypeOfBlock Block)
        {
            Bitmap tmp = null;

            switch (Block)
            {
            case TypeOfBlock.LeftL:
                tmp = Properties.Resources.LeftL;
                break;

            case TypeOfBlock.LeftZ:
                tmp = Properties.Resources.LeftZ;
                break;

            case TypeOfBlock.RightL:
                tmp = Properties.Resources.RightL;
                break;

            case TypeOfBlock.RightZ:
                tmp = Properties.Resources.RightZ;
                break;

            case TypeOfBlock.Square:
                tmp = Properties.Resources.Square;
                break;

            case TypeOfBlock.Straight:
                tmp = Properties.Resources.Straight;
                break;

            case TypeOfBlock.TBlock:
                tmp = Properties.Resources.TBlock;
                break;
            }
            return(tmp);
        }
Пример #9
0
 public Block(TypeOfBlock type)
 {
     Type  = type;
     Model = null;
 }
Пример #10
0
    void OnGUI()
    {
        for (int i = 0; i < _rows; i++)
        {
            for (int j = 0; j < _cols; j++)
            {
                _fieldArray[i, j] = 0;
            }
        }

        //select level
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.Label("Level", EditorStyles.boldLabel);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("<<", EditorStyles.miniButtonLeft))
        {
            if (_level > 1)
                PrevLevel();
        }
        this._level = Int32.Parse((EditorGUILayout.TextField(_level.ToString(), GUILayout.MaxWidth(50.0f))));
        if (GUILayout.Button(">>", EditorStyles.miniButtonRight))
        {
            if (_level < _maxLevel)
                NextLevel();
        }

        GUILayout.EndHorizontal();

        GUILayout.BeginHorizontal();
            _typeBlock = (TypeOfBlock) EditorGUILayout.EnumPopup(_typeBlock);
        GUILayout.EndHorizontal();
        GUILayout.Space(25f);
        //GUILayout bElement = GUILayout.Button("button");
        EditorGUILayout.BeginHorizontal();
        /*List<TypeBlock> addBlocks = new List<TypeBlock>();
        foreach (TypeBlock block in Enum.GetValues(typeof (TypeBlock)))
        {
            //bool addBlocks = !
        }
        foreach (TypeBlock block in Enum.GetValues(typeof(TypeBlock)))
        {
            if (GUILayout.Button(block.ToString(), (block == selectedBlock ? selectedButton : GUI.skin.button)))
            {
                selectedBlock = block;
            }
        }
        EditorGUILayout.EndHorizontal();*/
        GUILayout.Space(25f);

           /* for (int i = 0; i < _rows; i++)
        {
            GUILayout.BeginHorizontal();
            for (int j = 0; j < _cols; j++)
            {
                String lableB = _fieldArray[i, j].ToString();
                if (GUILayout.Button(lableB))
                {
                    //Debug.Log("hello " + _typeBlock);
                    lableB = "2";

                }
            }
            GUILayout.EndHorizontal();
        }

        Debug.Log("hello " + _fieldArray[0,2]);*/
    }
Пример #11
0
        /// <summary>
        /// Creates a New Falling Block
        /// </summary>
        /// <param name="blockType">The Type of Block that is Created</param>
        public FallingBlock(TypeOfBlock blockType)
        {
            BlockCells    = new List <Cells>();
            IsItFalling   = true;
            BlockType     = blockType;
            RotationPoint = RotationDegree.threeSixty;
            switch (blockType)
            {
            case TypeOfBlock.Straight:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(5, 3));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Cyan;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.LeftL:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(6, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Orange;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.LeftZ:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(6, 1));
                BlockCells.Add(new Cells(6, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Lime;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.RightL:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(5, 2));
                BlockCells.Add(new Cells(4, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Blue;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.RightZ:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(4, 1));
                BlockCells.Add(new Cells(4, 2));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Red;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.Square:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(6, 0));
                BlockCells.Add(new Cells(6, 1));
                BlockCells.Add(new Cells(5, 1));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Yellow;
                    item.Filled    = true;
                }
                break;

            case TypeOfBlock.TBlock:
                BlockCells.Add(new Cells(5, 0));
                BlockCells.Add(new Cells(5, 1));
                BlockCells.Add(new Cells(4, 1));
                BlockCells.Add(new Cells(6, 1));
                foreach (var item in BlockCells)
                {
                    item.BackColor = System.Drawing.Color.Purple;
                    item.Filled    = true;
                }
                break;
            }
        }
Пример #12
0
 private void OnTriggerStay2D(Collider2D other)
 {
     if (other.tag == "MoveObject")
     {
         TypeOfCerruntBlock = other.transform.GetComponent<Tile>().Type;
         MoveTile = other;
     }
     if (backgroundBlock.GetComponent<SpriteRenderer>().enabled)
     {
         if (other.tag == null)
         {
             TypeOfCerruntBlock = TypeOfBlock.EMPTY;
             MoveTile = null;
         }
     }
 }
Пример #13
0
 private void OnTriggerExit2D(Collider2D other)
 {
     if (backgroundBlock.GetComponent<SpriteRenderer>().enabled)
     {
         TypeOfCerruntBlock = TypeOfBlock.EMPTY;
         MoveTile = null;
     }
 }
Пример #14
0
 protected Boolean IsHaveNecessaryKey(TypeOfBlock type)
 {
     if (type == TypeOfBlock.LOCK_GREEN)
         {
             if (GameManager.instance.keyGreen > 0)
             {
                 return true;
             }
         }
         if (type == TypeOfBlock.LOCK_RED)
         {
             if (GameManager.instance.keyRed > 0)
             {
                 return true;
             }
         }
         return false;
 }