コード例 #1
0
        public void RotatePiece()
        {
            int NewRotation = Rotacion;

            if (NewRotation == 3)
            {
                NewRotation = 0;
            }
            else
            {
                NewRotation++;
            }

            Point[] SendPiece = new Point[4];
            for (int i = 0; i < 4; i++)
            {
                SendPiece[i] = Forma[PiezaActual, NewRotation, i];
            }

            if (!Playground.CheckCollisionMove(SendPiece, x, y))
            {
                Available = false;
                Erase(x, y, PiezaActual);
                Rotacion = NewRotation;
                Sonidos.PlaySound(Sonidos.Sounds.Rotar);
                Draw(x, y, PiezaActual);
                Playground.SensibilizeCell(x, y, Height, Width);
            }
            else
            {
                Sonidos.PlaySound(Sonidos.Sounds.Topa);
            }
        }
コード例 #2
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
 private static void CheckIfLose()
 {
     for (int i = 1; i < 11; i++)
     {
         if (Matriz[i, 4])
         {
             Sonidos.StopBGM();
             Sonidos.PlaySound(Sonidos.Sounds.Pierde_1);
             for (int j = 23; j > 0; j--)
             {
                 Console.SetCursorPosition(1, j);
                 Console.Write("KBKBKBKBKB");
                 Thread.Sleep(20);
             }
             for (int j = 1; j < 24; j++)
             {
                 Console.SetCursorPosition(1, j);
                 Console.Write("          ");
                 Thread.Sleep(20);
             }
             Sonidos.PlaySound(Sonidos.Sounds.Pierde_2);
             Lose = true;
             ConsoleFunctions.WriteConsoleInput('\0');
             break;
         }
     }
 }
コード例 #3
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
        private static void EatLines(int[] CompleteLines)
        {
            DeSensibilizeCell();
            switch (CompleteLines.Length)
            {
            case 1: Sonidos.PlaySound(Sonidos.Sounds.Single);
                Score += 40 * (Level + 1);
                Lines += 1;
                break;

            case 2: Sonidos.PlaySound(Sonidos.Sounds.Double);
                Score += 100 * (Level + 1);
                Lines += 2;
                break;

            case 3: Sonidos.PlaySound(Sonidos.Sounds.Triple);
                Score += 300 * (Level + 1);
                Lines += 3;
                break;

            case 4: Sonidos.PlaySound(Sonidos.Sounds.Tetris);
                Score += 1200 * (Level + 1);
                Lines += 4;
                FlashScreen();
                break;
            }
            for (int h = 0; h < CompleteLines.Length; h++)
            {
                Console.SetCursorPosition(1, CompleteLines[h]);
                for (int q = 1; q < 11; q++)
                {
                    Console.SetCursorPosition(q, CompleteLines[h]);
                    Console.Write(" ");
                    Thread.Sleep(15);
                }
                for (int i = CompleteLines[h]; i > 1; i--)
                {
                    for (int j = 1; j < 11; j++)
                    {
                        Matriz[j, i] = Matriz[j, i - 1];
                    }
                }

                Console.MoveBufferArea(1, 4, 10, CompleteLines[h] - 4, 1, 5);
                for (int k = h + 1; k < CompleteLines.Length; k++)
                {
                    CompleteLines[k] += 1;
                }
                Sonidos.PlaySound(Sonidos.Sounds.Linea_Cae);
            }
            UpdateStatus();
            Thread.Sleep(200);

            //Draw(20,0);
        }
コード例 #4
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
        public static void Initialize()
        {
            Limits.Clear();
            Sonidos.StopBGM();
            Sonidos.PlayBGM();

            Limits.Draw(4, "Green");
            Console.ForegroundColor = ConsoleColor.DarkRed;
            for (int i = 0; i < 12; i++)
            {
                Console.SetCursorPosition(i, 0);
                Console.Write("█");
            }
            for (int i = 1; i < 5; i++)
            {
                Console.SetCursorPosition(0, i);
                Console.Write("█");
                Console.SetCursorPosition(11, i);
                Console.Write("█");
            }
            Console.ResetColor();


            Lose  = false;
            Score = 0;
            Lines = 0;
            Level = 0;
            for (int i = 1; i < 24; i++)
            {
                for (int j = 1; j < 11; j++)
                {
                    Matriz[j, i] = false;
                }
            }


            for (int i = 0; i < 12; i++)
            {
                Matriz[i, 0]  = true;
                Matriz[i, 24] = true;
            }
            for (int i = 0; i < 25; i++)
            {
                Matriz[0, i]  = true;
                Matriz[11, i] = true;
            }
            UpdateStatus();
        }
コード例 #5
0
 public void MoveRight()
 {
     Point[] SendPiece = new Point[4];
     for (int i = 0; i < 4; i++)
     {
         SendPiece[i] = Forma[PiezaActual, Rotacion, i];
     }
     UpdatePieceDimentions();
     if (x + Width != 11 && !Playground.CheckCollisionMove(SendPiece, x + 1, y))
     {
         Available = false;
         Erase(x, y, PiezaActual);
         x++;
         Draw(x, y, PiezaActual);
         Playground.SensibilizeCell(x, y, Height, Width);
     }
     else
     {
         Sonidos.PlaySound(Sonidos.Sounds.Topa);
     }
 }
コード例 #6
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
 public static bool CheckCollisionFall(Point[] Pieza, int x, int y)
 {
     for (int i = 0; i < 4; i++)
     {
         if (Matriz[Pieza[i].X + x, Pieza[i].Y + y])
         {
             for (int j = 0; j < 4; j++)
             {
                 Matriz[Pieza[j].X + x, Pieza[j].Y + y - 1] = true;
             }
             Sonidos.PlaySound(Sonidos.Sounds.Topa);
             Thread.Sleep(200);
             Sonidos.PlaySound(Sonidos.Sounds.Posicionada);
             Score += 6 * (Level + 1);
             UpdateStatus();
             LineControl();
             CheckIfLose();
             return(true);
         }
     }
     return(false);
 }
コード例 #7
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
 public static void UnPause()
 {
     Sonidos.PlaySound(Sonidos.Sounds.Pausa);
     Sonidos.ContinueBGM();
 }
コード例 #8
0
ファイル: Playground.cs プロジェクト: afliw/console-tetris
 public static void Pause()
 {
     DeSensibilizeCell();
     Sonidos.PlaySound(Sonidos.Sounds.Pausa);
     Sonidos.PauseBGM();
 }
コード例 #9
0
        static void Main(string[] args)
        {
            SetConsoleFont(GetStdHandle(STDOUT_HANDLE), 8);
            bool Quit = false, ShowingScores = false, ShowingAbout = false;

            Console.Title         = "afliw's Tetris";
            Console.CursorVisible = false;
            string[] HighScoresArray = new string[0];
            Sonidos.StopBGM();
            LoadScores(ref HighScoresArray);
            Box    NextPieceBox      = new Box(14, 0, 3, 3);
            bool   Paused            = false;
            Piezas ObPieza           = new Piezas();
            Thread GamePlay          = new Thread(Game);

            Console.Clear();
            Writeafliw();
            WriteInstructions();
            Console.WindowHeight = (int)WindowSize.Regular.Height;
            Console.WindowWidth  = (int)WindowSize.Regular.Width;
            Console.BufferHeight = (int)WindowSize.Regular.Height;
            Console.BufferWidth  = (int)WindowSize.Regular.Width;
            ConsoleFunctions.SetConsoleFont(8);
            Playground.Initialize();
            ObPieza.Initialize();
            NextPieceBox.Draw(0, "Green");

            GamePlay.Start(ObPieza);
            string UserAction = " ";

            do
            {
                if (!Playground.Lose)
                {
                    switch (UserAction = Console.ReadKey(true).Key.ToString())
                    {
                    case "UpArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.RotatePiece();
                        }
                        break;

                    case "DownArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.Fall();
                        }
                        Playground.PointsByFall(); break;

                    case "LeftArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.MoveLeft();
                        }
                        break;

                    case "RightArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.MoveRight();
                        }
                        break;

                    case "Enter": PauseGame(GamePlay, ref Quit, ref ObPieza); break;

                    case "Spacebar":
                        ShowingScores = ShowingScores ? false : true;
                        if (ShowingScores)
                        {
                            ShowScoresTable(HighScoresArray, -1);
                            if (ShowingAbout)
                            {
                                ShowingAbout = false;
                            }
                        }
                        else
                        {
                            SetWindowWidth((int)WindowSize.Regular.Width);
                        }
                        ConsoleFunctions.FlushConsoleInputBuffer();
                        break;

                    case "F1":
                        ShowingAbout = ShowingAbout ? false : true;
                        if (ShowingAbout)
                        {
                            About();
                            if (ShowingScores)
                            {
                                ShowingScores = false;
                            }
                        }
                        else
                        {
                            SetWindowWidth((int)WindowSize.Regular.Width);
                        }
                        ConsoleFunctions.FlushConsoleInputBuffer();
                        break;
                    }
                }
                else
                {
                    int i;
                    for (i = 0; i < HighScoresArray.Length && ConvertScore(HighScoresArray[i]) >= Playground.Score; i++)
                    {
                        ;
                    }
                    if (i < HighScoresArray.Length - 1 || (i == HighScoresArray.Length - 1 && ConvertScore(HighScoresArray[HighScoresArray.Length - 1]) < Playground.Score))
                    {
                        afliw.Clear(0, Console.WindowHeight, 31, Console.WindowWidth);
                        SetWindowWidth((int)WindowSize.SaveScore.Width);
                        string PlayersName;
                        Console.SetCursorPosition(37, 5);
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("CONGRATULATIONS!");
                        Console.ResetColor();
                        Console.SetCursorPosition(35, 6);
                        Console.Write("You've made it in to");
                        Console.SetCursorPosition(34, 7);
                        Console.Write("the top 10 best scores.");
                        InputField getname = new InputField(15, true, true, true, false, false);
                        PlayersName = getname.GetString(33, 9, true, "Name ", true);


                        for (int j = HighScoresArray.Length - 1; j > i; j--)
                        {
                            HighScoresArray[j] = HighScoresArray[j - 1];
                        }
                        HighScoresArray[i] = PlayersName + "|" + Playground.Achivements();
                        SaveScores(ref HighScoresArray);
                        afliw.Clear(0, Console.WindowHeight, 32, Console.WindowWidth);
                        ShowScoresTable(HighScoresArray, i);
                    }
                    Console.SetCursorPosition(4, 8);
                    Console.Write("Play");
                    Console.SetCursorPosition(3, 9);
                    Console.Write("again?");
                    Menu Retry = new Menu(4, 11, -1, "Gray");
                    Retry.AddItem("Yes", "No");
                    if (Retry.DrawMenu(0) == 0)
                    {
                        RestartGame(ref ObPieza);
                    }
                    else
                    {
                        Quit = true;
                    }
                }
            }while(!Quit);
            try
            {
                GamePlay.Abort();
            }
            catch (Exception)
            {
                GamePlay.Resume();
                GamePlay.Abort();
            }
        }
コード例 #10
0
        public static void Options()
        {
            SetWindowWidth((int)WindowSize.Options.Width);
            afliw.Clear(0, Console.BufferHeight - 1, 31, Console.BufferWidth - 1);
            Box OptionsBox = new Box(31, 0, Console.BufferWidth - 34, Console.BufferHeight - 3);

            OptionsBox.Draw(0, "Magenta");
            string[] Opciones = { "Shadow", "Sounds", "Sound Volume", "Tetris' Flash", "Music", "Music Volume", "Back" };

            for (int i = 0; i < 7; i++)
            {
                Console.SetCursorPosition(35, 2 + (i * 3));
                Console.Write(Opciones[i]);
            }

            for (int i = 0; i < 6; i++)
            {
                OptSwitch(i, 0);
            }

            ushort[,] Normal = new ushort[1, Opciones[3].Length];
            for (int i = 0; i < Normal.GetLength(1); i++)
            {
                Normal[0, i] = 7;
            }
            int  Selected = 0;
            bool Back     = false;
            int  SaveBGM  = Sonidos.CurrentBGM;

            do
            {
                ushort[,] Highlight = new ushort[1, Opciones[Selected].Length];

                for (int i = 0; i < Highlight.GetLength(1); i++)
                {
                    Highlight[0, i] = 128;
                }
                for (int i = 0; i < Opciones.Length; i++)
                {
                    ConsoleFunctions.WriteConsoleAttribute(35, 2 + (i * 3), Normal);
                    if (i == Selected)
                    {
                        ConsoleFunctions.WriteConsoleAttribute(35, 2 + (i * 3), Highlight);
                    }
                }

                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.UpArrow: if (Selected == 0)
                    {
                        Selected = 6;
                    }
                    else
                    {
                        Selected--;
                    } break;

                case ConsoleKey.DownArrow: if (Selected == 6)
                    {
                        Selected = 0;
                    }
                    else
                    {
                        Selected++;
                    } break;

                case ConsoleKey.RightArrow: OptSwitch(Selected, 1); break;

                case ConsoleKey.LeftArrow: OptSwitch(Selected, -1); break;

                case ConsoleKey.Enter: if (Selected == 6)
                    {
                        Back = true;
                    }
                    break;
                }
            }while(!Back);
            if (SaveBGM != Sonidos.CurrentBGM)
            {
                Sonidos.StopBGM();
                Sonidos.ChangeBGM();
            }
            SetWindowWidth((int)WindowSize.Regular.Width);
        }
コード例 #11
0
        public static void OptSwitch(int Selected, int Switch)
        {
            string[] BGMNames = { "Technotris", "Kalinka", "Troika", "OFF" };
            if (Selected != 4)
            {
                if (Switch != 0)
                {
                    switch (Selected)
                    {
                    case 0: Playground.Shadow = Playground.Shadow ? false : true; break;

                    case 1: Sonidos.Sounds_ON = Sonidos.Sounds_ON ? false : true; break;

                    case 2: if (Switch == 1)
                        {
                            Sonidos.SoundsVolume(true);
                        }
                        else
                        {
                            Sonidos.SoundsVolume(false);
                        } break;

                    case 3: Playground.Flash = Playground.Flash ? false : true; break;

                    case 5: if (Switch == 1)
                        {
                            Sonidos.BGMVolume(true);
                        }
                        else
                        {
                            Sonidos.BGMVolume(false);
                        } break;
                    }
                }
                Console.SetCursorPosition(49, 2 + (Selected * 3));
            }
            else
            {
                if (Switch != 0)
                {
                    Sonidos.CurrentBGM += Switch;
                    if (Sonidos.CurrentBGM < 0)
                    {
                        Sonidos.CurrentBGM = 3;
                    }
                    else if (Sonidos.CurrentBGM > 3)
                    {
                        Sonidos.CurrentBGM = 0;
                    }
                }
                afliw.Clear(2 + (Selected * 3), 2 + (Selected * 3) + 1, 40, Console.BufferWidth - 5);
                Console.SetCursorPosition(52 - BGMNames[Sonidos.CurrentBGM].Length, 2 + (Selected * 3));
            }
            Console.Write("◄ ");
            switch (Selected)
            {
            case 0: if (Playground.Shadow)
                {
                    Console.Write("ON ");
                }
                else
                {
                    Console.Write("OFF");
                } break;

            case 1: if (Sonidos.Sounds_ON)
                {
                    Console.Write("ON ");
                }
                else
                {
                    Console.Write("OFF");
                } break;

            case 2: Console.Write(Sonidos.ReturnVolume(1).ToString("000")); break;

            case 3: if (Playground.Flash)
                {
                    Console.Write("ON ");
                }
                else
                {
                    Console.Write("OFF");
                } break;

            case 4: Console.Write(BGMNames[Sonidos.CurrentBGM]); break;

            case 5: Console.Write(Sonidos.ReturnVolume(0).ToString("000")); break;
            }
            Console.Write(" ►");
        }