예제 #1
0
 void Update()
 {
     dynamicScore.text = "Your Current Score : " + MatrixGrid.returnPlayerScore().ToString();
     if (TetrisObject.IsGameOver())
     {
         Application.LoadLevel("End screen");
     }
 }
예제 #2
0
 private void AddDeadBlock(TetrisObject[,] tetrisObjects)
 {
     foreach (TetrisObject item in tetrisObjects)
     {
         for (int i = 0; i < stoppedblocks.GetLength(0); i++)
         {
             for (int j = 0; j < stoppedblocks.GetLength(1); j++)
             {
                 if (item.Pos == playfield[i, j].Pos && item.alive)
                 {
                     stoppedblocks[i, j] = new TetrisObject(item.Pos, item.tex);
                 }
             }
         }
     }
 }
예제 #3
0
        public I(Texture2D color, Vector2 startPos)
        {
            this.color = color;
            //this.startPos = startPos;
            iMatrix = new TetrisObject[4, 4];

            //Contents of the I, looping through the dubbelarray setting positions and textures
            for (int i = 0; i < iMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < iMatrix.GetLength(1); j++)
                {
                    iMatrix[i, j]      = new TetrisObject(Vector2.Zero, color);
                    iMatrix[i, j].PosX = startPos.X + i * color.Width;
                    iMatrix[i, j].PosY = startPos.Y + j * color.Height;
                }
            }
            formation = iblockState.one;//Default formation of the I figure
            UpdateFormation();
        }
예제 #4
0
        public J(Texture2D color, Vector2 startPos)
        {
            magicFlames = new List <AnimatedObject>();

            this.color    = color;
            this.startPos = startPos;
            jMatrix       = new TetrisObject[3, 3];

            ////Contents of the I, looping through the matrix setting positions and textures
            for (int i = 0; i < jMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < jMatrix.GetLength(1); j++)
                {
                    jMatrix[i, j]      = new TetrisObject(Vector2.Zero, color);
                    jMatrix[i, j].PosX = startPos.X + i * color.Width;
                    jMatrix[i, j].PosY = startPos.Y + j * color.Height;
                }
            }

            Formation = blockState.one;//Default formation of the J figure
            UpdateFormation();
        }
예제 #5
0
        public I(Texture2D color, Vector2 startPos)
        {
            magicFlames = new List <AnimatedObject>();

            Color = color;

            iMatrix = new TetrisObject[4, 4];

            //Contents of the I, looping through the matrix setting positions and textures
            for (int i = 0; i < iMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < iMatrix.GetLength(1); j++)
                {
                    iMatrix[i, j] = new TetrisObject(Vector2.Zero, color)
                    {
                        PosX = startPos.X + i * color.Width,
                        PosY = startPos.Y + j * color.Height
                    };
                }
            }
            Formation = IblockState.one;//Default Formation of the I figure
            UpdateFormation();
        }
예제 #6
0
        public TetrisObject[,] NextRotatePosition(bool clockwise)
        {
            TetrisObject[,] newPosition = new TetrisObject[zMatrix.GetLength(0), zMatrix.GetLength(1)];
            for (int i = 0; i < newPosition.GetLength(0); i++)
            {
                for (int j = 0; j < newPosition.GetLength(1); j++)
                {
                    newPosition[i, j]      = new TetrisObject(Vector2.Zero, Color);
                    newPosition[i, j].PosX = zMatrix[0, 0].PosX + i * Color.Width;
                    newPosition[i, j].PosY = zMatrix[0, 0].PosY + j * Color.Height;
                }
            }

            if (clockwise)
            {
                switch (Formation)
                {
                case BlockState.one:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[2, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;

                case BlockState.two:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    newPosition[2, 2].ChangeState(false);
                    break;

                case BlockState.three:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[0, 2].ChangeState(false);
                    break;

                case BlockState.four:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 0].ChangeState(false);
                    newPosition[1, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    break;
                }
            }
            else if (!clockwise)
            {
                switch (Formation)
                {
                case BlockState.one:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[0, 2].ChangeState(false);
                    break;

                case BlockState.two:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 0].ChangeState(false);
                    newPosition[1, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    break;

                case BlockState.three:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[2, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;

                case BlockState.four:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    newPosition[2, 2].ChangeState(false);
                    break;
                }
            }
            return(newPosition);
        }
예제 #7
0
        public bool AllowRotation(bool clockwise, Vector2 maxValues, Vector2 minValues)
        {
            TetrisObject[,] newPosition = new TetrisObject[sMatrix.GetLength(0), sMatrix.GetLength(1)];
            for (int i = 0; i < newPosition.GetLength(0); i++)
            {
                for (int j = 0; j < newPosition.GetLength(1); j++)
                {
                    newPosition[i, j]      = new TetrisObject(Vector2.Zero, Color);
                    newPosition[i, j].PosX = sMatrix[0, 0].PosX + i * Color.Width;
                    newPosition[i, j].PosY = sMatrix[0, 0].PosY + j * Color.Height;
                }
            }

            if (clockwise)
            {
                switch (Formation)
                {
                case BlockState.one:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[2, 2].ChangeState(false);
                    break;

                case BlockState.two:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[0, 2].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;

                case BlockState.three:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;

                case BlockState.four:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[2, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    break;
                }
            }
            else if (!clockwise)
            {
                switch (Formation)
                {
                case BlockState.one:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[0, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;

                case BlockState.two:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[2, 0].ChangeState(false);
                    newPosition[0, 1].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    break;

                case BlockState.three:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 0].ChangeState(false);
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[2, 2].ChangeState(false);
                    break;

                case BlockState.four:
                    foreach (TetrisObject item in newPosition)
                    {
                        item.ChangeState(true);
                    }
                    newPosition[1, 1].ChangeState(false);
                    newPosition[2, 1].ChangeState(false);
                    newPosition[0, 2].ChangeState(false);
                    newPosition[1, 2].ChangeState(false);
                    break;
                }
            }
            return(minValues.X <= MinValues(newPosition).X&& maxValues.X >= MaxValues(newPosition).X&& maxValues.Y >= MaxValues(newPosition).Y);
        }