Example #1
0
        private void AddNewRandomTetromino()
        {
            Array values = Enum.GetValues(typeof(Tetromino.TetrominoTypes));

            Tetromino.TetrominoTypes t = (Tetromino.TetrominoTypes)r.Next(values.Length);

            if (activeTetromino != null && activeTetromino.Type == t)
            {
                t = (Tetromino.TetrominoTypes)r.Next(values.Length);
            }

            if (Stats.ContainsKey(t))
            {
                Stats[t]++;
            }
            else
            {
                Stats.Add(t, 1);
            }

            activeTetromino    = new Tetromino(t, BlockWidth, BlockHeight);
            activeTetromino.X  = BlockWidth * (GridWidth - activeTetromino.Size) / 2;
            activeTetromino.X -= activeTetromino.X % BlockWidth;
            activeTetromino.Y -= activeTetromino.Area.Top * BlockHeight;

            if (!CanMove(Tetromino.Directions.Down))
            {
                Task.Run(() => ShowBanner("GAME OVER", 5000));
                gameOver = true;
            }
            else
            {
                Points++;
            }
        }
Example #2
0
        public object Clone()
        {
            Tetromino p = new Tetromino(Type, BlockWidth, BlockHeight)
            {
                X = this.X,
                Y = this.Y
            };

            p.Blocks = (bool[][])this.Blocks.Clone();
            p.UpdateArea();
            return(p);
        }
Example #3
0
        private bool IsOverlapping(Tetromino t)
        {
            for (int x = t.Area.Left; x <= t.Area.Right; x++)
            {
                for (int y = t.Area.Top; y <= t.Area.Bottom; y++)
                {
                    if (t.Blocks[x][y] && Cells[t.X / BlockWidth + x][t.Y / BlockHeight + y].Value)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #4
0
        private bool CanMove(Tetromino.Directions d)
        {
            Tetromino tmp = (Tetromino)activeTetromino.Clone();

            tmp.Move(d);

            if (tmp.X / BlockWidth + tmp.Area.Left < 0)
            {
                return(false);
            }
            if (tmp.X / BlockWidth + tmp.Area.Right > GridWidth - 1)
            {
                return(false);
            }
            if (tmp.Y / BlockWidth + tmp.Area.Bottom > GridHeight - 1)
            {
                return(false);
            }

            return(!IsOverlapping(tmp));
        }