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); } }
public static void UnPauseGame(Thread GamePlay, ConsoleFunctions.CHAR_INFO[] Buffer, ConsoleFunctions.CHAR_INFO[] BufferNext) { afliw.Clear(1, 24, 1, 11); Console.Title = Console.Title.Remove(14); ConsoleFunctions.WriteBufferToConsole(1, 1, 11, 24, Buffer); ConsoleFunctions.WriteBufferToConsole(15, 1, 4, 4, BufferNext); Playground.UnPause(); GamePlay.Resume(); ConsoleFunctions.FlushConsoleInputBuffer(); }
private void NewPiece() { this.Rotacion = 0; Erase(xNext, YNext, NextPiece); this.PiezaActual = NextPiece; this.NextPiece = new Random().Next(0, 7); Draw(xNext, YNext, NextPiece); x = InitX; y = InitY; UpdatePieceDimentions(); Draw(x, y, PiezaActual); Playground.SensibilizeCell(x, y, Height, Width); }
public static void PauseGame(Thread GamePlay, ref bool Quit, ref Piezas ObPieza) { ConsoleFunctions.CHAR_INFO[] Buffer = new ConsoleFunctions.CHAR_INFO[11 * 24]; ConsoleFunctions.CHAR_INFO[] BufferNext = new ConsoleFunctions.CHAR_INFO[4 * 4]; GamePlay.Suspend(); Playground.Pause(); Buffer = ConsoleFunctions.ReadConsoleOutput(1, 1, 11, 24); BufferNext = ConsoleFunctions.ReadConsoleOutput(15, 1, 4, 4); Console.Title = Console.Title + " (Paused)"; afliw.Clear(1, 24, 1, 11); afliw.Clear(1, 5, 15, 19); ConsoleFunctions.WriteConsole(3, 1, (ushort)ConsoleColor.DarkCyan, "Paused"); for (int i = 0; i < 11; i++) { Console.MoveBufferArea(3, 1 + i, 6, 1, 3, 2 + i); Thread.Sleep(300 / (5 * (i + 1))); } for (int i = 0; i < 3; i++) { Console.MoveBufferArea(3, 12 - i, 6, 1, 3, 11 - i); Thread.Sleep(30 * (i + 1)); } Thread.Sleep(20); for (int i = 0; i < 3; i++) { Console.MoveBufferArea(3, 9 + i, 6, 1, 3, 10 + i); Thread.Sleep(30 * (i + 1)); } int Option = 2; Menu PauseMenu = new Menu(2, 14, -1, "Gray"); PauseMenu.AddItem(true, "Continue", "Restart", "Config", "Quit"); ConsoleFunctions.FlushConsoleInputBuffer(); do { Option = PauseMenu.DrawMenu(0); switch (Option) { case 0: UnPauseGame(GamePlay, Buffer, BufferNext); break; case 1: UnPauseGame(GamePlay, Buffer, BufferNext); RestartGame(ref ObPieza); break; case 2: Options(); break; case 3: Quit = true; break; } }while(Option == 2); }
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); } }
public void Fall() { Available = false; Point[] SendPiece = new Point[4]; for (int i = 0; i < 4; i++) { SendPiece[i] = Forma[PiezaActual, Rotacion, i]; } if (Playground.CheckCollisionFall(SendPiece, x, y + 1)) { ConsoleFunctions.FlushConsoleInputBuffer(); if (!Playground.Lose) { NewPiece(); } } else { UpdatePieceDimentions(); Erase(x, y, PiezaActual); y++; Draw(x, y, PiezaActual); } }
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(); } }
public static void RestartGame(ref Piezas ObPieza) { SetWindowWidth((int)WindowSize.Regular.Width); Playground.Initialize(); ObPieza.Initialize(); }
public static void RestartGame(ref Piezas ObPieza) { WindowGrowAndShrink(31); Playground.Initialize(); ObPieza.Initialize(); }