GameH









How do I use Game H
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: Program.cs Copy
75     static void Main()
76     {
77         Console.OutputEncoding = Encoding.GetEncoding(1252);
78         Console.CursorVisible = false;
79         Console.Title = "Tetris";
80         Console.WindowWidth = GameWidth;
81         Console.BufferWidth = GameWidth;
82         Console.WindowHeight = GameHeight + 1;
83         Console.BufferHeight = GameHeight + 1;
84
85         StartNewGame();
86         PrintBorders();
87
88         Task.Run(() =>
89         {
90             while (true)
91             {
92                 PlaySound();
93             }
94         });
95
96         while(true)
97         {
98             if (Console.KeyAvailable)
99             {
100                 var key = Console.ReadKey();
101                 if (key.Key == ConsoleKey.LeftArrow)
102                 {
103                     if (currentFigureCol > 1)
104                     {
105                         currentFigureCol--;
106                     }
107                 }
108                 else if (key.Key == ConsoleKey.RightArrow)
109                 {
110                     if (currentFigureCol + currentFigure.GetLength(1) - 1 < TetrisWidth)
111                     {
112                         currentFigureCol++;
113                     }
114                 }
115             }
116
117             if (CollisionDetection())
118             {
119                 PlaceCurrentFigure();
120                 int removedLines = CheckForFullLines();
121
122                 if (removedLines > 0)
123                 {
124                     Score += scorePerLines[removedLines - 1] * Level;
125                 }
126
127                 Level = Score / 1000 + 1;
128
129                 currentFigure = nextFigure;
130                 nextFigure = Figures[random.Next(0, Figures.Length)];
131                 currentFigureRow = 1;
132                 currentFigureCol = 4;
133             }
134             else
135             {
136                 currentFigureRow++;
137             }
138
139             PrintInfoPanel();
140
141             PrintGameField();
142
143             PrintBorders();
144
145             PrintFigure(currentFigure,
146                 currentFigureRow, currentFigureCol);
147
148             Thread.Sleep(speedPerLevel[Level - 1]);
149         }
150     }
File name: Program.cs Copy
313     static void PrintBorders()
314     {
315         for (int col = 0; col < GameWidth; col++)
316         {
317             Print(0, col, BorderCharacter);
318             Print(GameHeight - 1, col, BorderCharacter);
319         }
320
321         for (int row = 0; row < GameHeight; row++)
322         {
323             Print(row, 0, BorderCharacter);
324             Print(row, TetrisWidth + 1, BorderCharacter);
325             Print(row, TetrisWidth + 1 + InfoPanelWidth + 1, BorderCharacter);
326         }
327     }

Download file with original file name:GameH

GameH 79 lượt xem

Gõ tìm kiếm nhanh...