Exemplo n.º 1
0
        public bool Collision(Tetrominoe figure)
        {
            if (gameState.CurrentFigureCol > tetrisCols - figure.Height)
            {
                return(true);
            }
            if (gameState.CurrentFigureRow + figure.Wigth - 1 == tetrisRows)
            {
                return(true);
            }

            for (int row = 0; row < figure.Wigth; row++)
            {
                for (int col = 0; col < figure.Height; col++)
                {
                    if (figure.Body[row, col] &&
                        gameState.TetrisField[gameState.CurrentFigureRow + row,
                                              gameState.CurrentFigureCol + col])
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private static void Update()
        {
            while (true)//Update Loop
            {
                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 < 10; j++)
                {
                    if (droppedtetrominoeLocationGrid[0, j] == 1)
                    {
                        return;
                    }
                }

                Input();
                ClearBlock();
            } //end Update
        }
Exemplo n.º 3
0
        static void Main()
        {
            SoundPlayer sp = new SoundPlayer();

            sp.SoundLocation = Environment.CurrentDirectory + "\\01_-_Tetris_Tengen_-_NES_-_Introduction.wav";
            sp.PlayLooping();
            Console.CursorVisible = false;
            drawBorder();
            Console.SetCursorPosition(4, 5);
            Console.WriteLine("Bir Tuşa Basın");
            Console.ReadKey(true);
            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\music.wav";
            sp.PlayLooping();
            timer.Start();
            dropTimer.Start();
            long time = timer.ElapsedMilliseconds;

            Console.SetCursorPosition(25, 0);
            Console.WriteLine("Seviye " + level);
            Console.SetCursorPosition(25, 1);
            Console.WriteLine("Puan " + score);
            Console.SetCursorPosition(25, 2);
            Console.WriteLine("Satır Silindi " + linesCleared);
            nexttet = new Tetrominoe();
            tet     = nexttet;
            tet.Spawn();
            nexttet = new Tetrominoe();

            Update();

            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\08_-_Tetris_Tengen_-_NES_-_Game_Over.wav";
            sp.Play();
            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Oyun Bitti \n Yeniden Oyna? (Y/N)");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                int[,] grid = new int[23, 10];
                droppedtetrominoeLocationGrid = new int[23, 10];
                timer        = new Stopwatch();
                dropTimer    = new Stopwatch();
                inputTimer   = new Stopwatch();
                dropRate     = 300;
                isDropped    = false;
                isKeyPressed = false;
                linesCleared = 0;
                score        = 0;
                level        = 1;
                GC.Collect();
                Console.Clear();
                Main();
            }
            else
            {
                return;
            }
        }
Exemplo n.º 4
0
        static void Main()
        {
            SoundPlayer sp = new SoundPlayer();

            sp.SoundLocation = Environment.CurrentDirectory + "\\01_Tetris_NES_Music_1.wav";
            sp.PlayLooping();

            drawBorder();
            Console.SetCursorPosition(4, 5);
            Console.WriteLine("Press any key");
            Console.ReadKey(true);
            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\01_Tetris_NES_Music_1.wav";
            sp.PlayLooping();
            timer.Start();
            dropTimer.Start();
            long time = timer.ElapsedMilliseconds;

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

            Update();

            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\08_Tetris_NES_Victory.wav";
            sp.Play();
            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Game Over \n Replay? (Y/N)");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                int[,] grid = new int[23, 10];
                droppedtetrominoeLocationGrid = new int[23, 10];
                timer        = new Stopwatch();
                dropTimer    = new Stopwatch();
                inputTimer   = new Stopwatch();
                dropRate     = 300;
                isDropped    = false;
                isKeyPressed = false;
                linesCleared = 0;
                score        = 0;
                level        = 1;
                GC.Collect();
                Console.Clear();
                Main();
            }
            else
            {
                return;
            }
        }
Exemplo n.º 5
0
        public static void opneGame()
        {
            Console.CursorVisible = false;
            drawBorder();
            Console.SetCursorPosition(4, 5);
            Console.WriteLine("Press any key");
            Console.ReadKey(true);

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

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

            Update();


            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Game Over \n Replay? (Y/N)");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                int[,] grid = new int[HEIGHT_FIELD, WIDTH_FIELD];
                droppedtetrominoeLocationGrid = new int[HEIGHT_FIELD, WIDTH_FIELD];
                timer        = new Stopwatch();
                dropTimer    = new Stopwatch();
                inputTimer   = new Stopwatch();
                dropRate     = 300;
                isDropped    = false;
                isKeyPressed = false;
                linesCleared = 0;
                score        = 0;
                level        = 1;
                GC.Collect();
                Console.Clear();
                opneGame();
            }
            else
            {
                return;
            }
        }
Exemplo n.º 6
0
        static void Main()// adding sound player
        {
            SoundPlayer sp = new SoundPlayer();


            drawBorder();
            Console.SetCursorPosition(4, 5);
            Console.WriteLine("Press any key");
            Console.ReadKey(true);
            timer.Start();
            dropTimer.Start();
            long time = timer.ElapsedMilliseconds;

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

            Update();


            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Game Over \n Replay? (Y/N)");
            string input = Console.ReadLine();

            if (input == "y" || input == "Y")
            {
                int[,] grid = new int[23, 10];
                droppedtetrominoeLocationGrid = new int[23, 10];
                timer        = new Stopwatch();
                dropTimer    = new Stopwatch();
                inputTimer   = new Stopwatch();
                dropRate     = 300;
                isDropped    = false;
                isKeyPressed = false;
                linesCleared = 0;
                score        = 0;
                level        = 1;
                GC.Collect();
                Console.Clear();
                Main();
            }
            return;
        }
        public void DrawCurrentFigure(Tetrominoe currentFigure, int currentFigureRow, int currentFigureCol)
        {
            var tetrisConsoleWriter = new TetrisConsoleWriter(tetrisRows, tetrisCols, tetrisInfo);

            for (int row = 0; row < currentFigure.Body.GetLength(0); row++)
            {
                for (int col = 0; col < currentFigure.Body.GetLength(1); col++)
                {
                    if (currentFigure.Body[row, col])
                    {
                        tetrisConsoleWriter.Write("*", row + 1 + currentFigureRow, col + 1 + currentFigureCol);
                    }
                }
            }
        }
Exemplo n.º 8
0
        private static void Update()
        {
            while (true)//Update Loop
            {
                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 < 10; j++)
                {
                    if (droppedtetrominoeLocationGrid[0, j] == 1)
                        return;
                }

                Input();
                ClearBlock();
            } //end Update
        }
Exemplo n.º 9
0
        static void Main()
        {
            SoundPlayer sp = new SoundPlayer();
            sp.SoundLocation = Environment.CurrentDirectory + "\\01_-_Tetris_Tengen_-_NES_-_Introduction.wav";
            sp.PlayLooping();

            drawBorder();
            Console.SetCursorPosition(4, 5);
            Console.WriteLine("Press any key");
            Console.ReadKey(true);
            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\music.wav";
            sp.PlayLooping();
            timer.Start();
            dropTimer.Start();
            long time = timer.ElapsedMilliseconds;
            Console.SetCursorPosition(25, 0);
            Console.WriteLine("Level " + level);
            Console.SetCursorPosition(25, 1);
            Console.WriteLine("Score " + score);
            Console.SetCursorPosition(25, 2);
            Console.WriteLine("LinesCleared " + linesCleared);
            nexttet = new Tetrominoe();
            tet = nexttet;
            tet.Spawn();
            nexttet = new Tetrominoe();

            Update();

            sp.Stop();
            sp.SoundLocation = Environment.CurrentDirectory + "\\08_-_Tetris_Tengen_-_NES_-_Game_Over.wav";
            sp.Play();
            Console.SetCursorPosition(0, 0);
            Console.WriteLine("Game Over \n Replay? (Y/N)");
            string input = Console.ReadLine();

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