Ejemplo n.º 1
0
        private static void Update()
        {
            while (true)
            {
                ResetWindowSize();
                drawBorder();
                dropTime = (int)dropTimer.ElapsedMilliseconds;
                if (dropTime > dropRate)
                {
                    dropTime = 0;
                    dropTimer.Restart();
                    tet.Drop();
                }
                if (isDropped == true)
                {
                    tet     = nextTet;
                    nextTet = new Tetrominoe();
                    tet.Spawn();

                    isDropped = false;
                }
                int j;
                for (j = 0; j < gridWidth; j++)
                {
                    if (droppedTetrominoeLocationGrid[0, j] == 1)
                    {
                        return;
                    }
                }
                Console.SetCursorPosition(gridLenght + 1, gridWidth + 1);
                Input();
                ClearBlock();
            }
        }
Ejemplo n.º 2
0
        static void Main()
        {
            SoundPlayer sp = new SoundPlayer();

            sp.SoundLocation = Environment.CurrentDirectory + "\\Original Tetris theme.wav";
            sp.PlayLooping();

            Console.CursorVisible = false;
            Console.BufferWidth   = Console.WindowWidth = 41;
            Console.BufferHeight  = Console.WindowHeight = 30;

            Console.SetCursorPosition(9, 5);
            Console.WriteLine("Up Arrow for rotation");
            Console.SetCursorPosition(8, 7);
            Console.WriteLine("Spacebar to drop Piece");
            Console.SetCursorPosition(8, 9);
            Console.WriteLine("Press any key to start");
            Console.ReadKey(true);
            Console.Clear();

            timer.Start();
            dropTimer.Start();
            long time = timer.ElapsedMilliseconds;

            Console.SetCursorPosition(gridLenght + 2, 0);
            Console.WriteLine("Level " + level);
            Console.SetCursorPosition(gridLenght + 2, 1);
            Console.WriteLine("Score " + score);
            Console.SetCursorPosition(gridLenght + 2, 2);
            Console.WriteLine("LinesCleared " + linesCleared);
            nextTet = new Tetrominoe();
            tet     = nextTet;
            tet.Spawn();
            nextTet = new Tetrominoe();

            Update();

            Console.SetCursorPosition(10, gridLenght + 3);
            Console.WriteLine("Game Over");
            Console.SetCursorPosition(7, gridLenght + 4);
            Console.WriteLine("Replay ? (Y / N)");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                int[,] grid = new int[gridLenght, gridWidth];
                droppedTetrominoeLocationGrid = new int[gridLenght, gridWidth];
                timer        = new Stopwatch();
                dropTimer    = new Stopwatch();
                isDropped    = false;
                isKeyPressed = false;
                linesCleared = 0;
                score        = 0;
                level        = 1;
                GC.Collect();
                Console.Clear();
                Main();
            }
            else
            {
                return;
            }
        }