Exemplo n.º 1
0
        /// <summary>
        /// Used to update ghost position
        /// </summary>
        private void UpdateGhost()
        {
            Ghost = Controller.Clone();

            Tetromino test = Ghost;

            while (!Map.CheckPlaceCollision(test))
            {
                Ghost = test;
                test  = Ghost.Clone();
                test.Transform(0, Direction.Forward);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Swaps cotainer out with tetromino
 /// </summary>
 /// <returns>cotainers tetromino</returns>
 public Tetromino Swap(Tetromino tetromino)
 {
     if (this.tetromino == null)
     {
         IsEmpty        = false;
         this.tetromino = tetromino.Clone();
         return(Tetromino);
     }
     else
     {
         Tetromino oldTetromino = this.tetromino;
         this.tetromino = tetromino;
         return(oldTetromino);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Used to rotate the tetromino controller
        /// </summary>
        /// <returns>if the rotation was successful</returns>
        public bool Rotate(Direction direction)
        {
            Tetromino test = Controller.Clone();

            test.Rotate(direction);

            if ((!Map.CheckPlaceCollision(test)) && (!Map.CheckWallCloision(test)))
            {
                Controller = test;
                UpdateGhost();
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Picks next tetromino for controler
        /// </summary>
        private void Next()
        {
            Tetromino randomTetromino = Tetrominos[random.Next(0, Tetrominos.Length)].Clone();

            if (NextContainer.IsEmpty)
            {
                NextContainer.Swap(randomTetromino);
                Next();
            }
            else
            {
                Controller = NextContainer.Swap(randomTetromino);
                Controller.Reset(Map.Width / 2 - 2, -Controller.Height);

                UpdateGhost();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Used to create a game of tetris
        /// </summary>
        /// <param name="timerInterval">in milliseconds</param>
        /// <param name="width">width of the map</param>
        /// <param name="height">height of the map</param>
        public GameManager(int timerInterval = 500, int width = 10, int height = 21)
        {
            timer          = new Timer(timerInterval);
            timer.Elapsed += OnTimedEvent;
            timer.Enabled  = true;

            Map        = new Map(width, height);
            Tetrominos = new Tetromino[]
            {
                new Tetromino("....XXXX........", Field.Cyan, 90, 4, 4),
                new Tetromino("...XXX..X", Field.Blue, 180),
                new Tetromino("...XXXX..", Field.Orange, 180),
                new Tetromino("XXXX", Field.Yellow, 0, 2, 2),
                new Tetromino("....XXXX.", Field.Green),
                new Tetromino("...XXX.X.", Field.Purple, 180),
                new Tetromino("...XX..XX", Field.Red),
            };

            Reset();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Used to move the tetromino controller
        /// </summary>
        /// <returns>if the transform was successful</returns>
        public bool Transform(Direction x, Direction y)
        {
            Tetromino test = Controller.Clone();

            test.Transform(x, y);

            if (y != Direction.None)
            {
                isTransformDownMade = true;

                if (Map.CheckPlaceCollision(test))
                {
                    // Checks for lose
                    if (Controller.Y < 0)
                    {
                        Reset();
                    }
                    else // Place tetromino
                    {
                        isNewHoldMade = false;
                        Map.PlaceTetromino(Controller);
                        Score += Map.ClearLines() * 100;
                        Next();
                    }
                    return(false);
                }
            }

            if ((!Map.CheckPlaceCollision(test)) && (!Map.CheckWallCloision(test)))
            {
                Controller = test;
            }

            UpdateGhost();

            return(true);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Clears container
 /// </summary>
 public void Clear()
 {
     tetromino = null;
     IsEmpty   = true;
 }