GameF









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

Featured Snippets


File name: GameplayController.cs Copy
88  void GameIsOnPlay(){
89   /*if (PlayerBullet () == 0) {
90    timeAfterLastShot += Time.deltaTime;
91    camera.isFollowing = false;
92    if (timeAfterLastShot > 2f) {
93     if (AllStopMoving () && AllEnemiesDestroyed ()) {
94      if (!gameFinished) {
95       gameFinished = true;
96       Debug.Log ("Hello World");
97      }
98     } else if (AllStopMoving () && !AllEnemiesDestroyed ()) {
99      if (!gameFinished) {
100       gameFinished = true;
101       Debug.Log ("Hi World");
102      }
103     }
104    }
105
106   }*/
107
108   if(checkGameStatus){
109    timeAfterLastShot += Time.deltaTime;
110    if (timeAfterLastShot > 2f) {
111     if (AllStopMoving () || Time.time - timeSinceStartedShot > 8f) {
112      if (AllEnemiesDestroyed ()) {
113       if (!gameFinished) {
114        gameFinished = true;
115        GameWin ();
116        timeAfterLastShot = 0;
117        checkGameStatus = false;
118       }
119      } else {
120       if (PlayerBullet () == 0) {
121        if (!gameFinished) {
122         gameFinished = true;
123         timeAfterLastShot = 0;
124         checkGameStatus = false;
125         GameLost ();
126        }
127       } else {
128        checkGameStatus = false;
129        camera.isFollowing = false;
130        timeAfterLastShot = 0;
131       }
132      }
133     }
134    }
135
136   }
137
138  }
File name: Program.cs Copy
55         static void SetInitialPositions()
56         {
57             firstPlayerPosition = Console.WindowHeight / 2 - firstPlayerPadSize / 2;
58             secondPlayerPosition = Console.WindowHeight / 2 - secondPlayerPadSize / 2;
59             SetBallAtTheMiddleOfTheGameField();
60         }
File name: Program.cs Copy
62         static void SetBallAtTheMiddleOfTheGameField()
63         {
64             ballPositionX = Console.WindowWidth / 2;
65             ballPositionY = Console.WindowHeight / 2;
66         }
File name: Program.cs Copy
135         private static void MoveBall()
136         {
137             if (ballPositionY == 0)
138             {
139                 ballDirectionUp = false;
140             }
141             if (ballPositionY == Console.WindowHeight - 1)
142             {
143                 ballDirectionUp = true;
144             }
145             if (ballPositionX == Console.WindowWidth - 1)
146             {
147                 SetBallAtTheMiddleOfTheGameField();
148                 ballDirectionRight = false;
149                 ballDirectionUp = true;
150                 firstPlayerResult++;
151                 Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
152                 Console.WriteLine("First player wins!");
153                 Console.ReadKey();
154             }
155             if (ballPositionX == 0)
156             {
157                 SetBallAtTheMiddleOfTheGameField();
158                 ballDirectionRight = true;
159                 ballDirectionUp = true;
160                 secondPlayerResult++;
161                 Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
162                 Console.WriteLine("Second player wins!");
163                 Console.ReadKey();
164             }
165
166             if (ballPositionX < 3)
167             {
168                 if (ballPositionY >= firstPlayerPosition
169                     && ballPositionY < firstPlayerPosition + firstPlayerPadSize)
170                 {
171                     ballDirectionRight = true;
172                 }
173             }
174
175             if (ballPositionX >= Console.WindowWidth - 3 - 1)
176             {
177                 if (ballPositionY >= secondPlayerPosition
178                     && ballPositionY < secondPlayerPosition + secondPlayerPadSize)
179                 {
180                     ballDirectionRight = false;
181                 }
182             }
183
184             if (ballDirectionUp)
185             {
186                 ballPositionY--;
187             }
188             else
189             {
190                 ballPositionY++;
191             }
192
193
194             if (ballDirectionRight)
195             {
196                 ballPositionX++;
197             }
198             else
199             {
200                 ballPositionX--;
201             }
202         }
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
247     static void PrintGameField()
248     {
249         for (int row = 1; row <= TetrisHeight; row++)
250         {
251             for (int col = 1; col <= TetrisWidth; col++)
252             {
253                 if (gameState[row - 1, col - 1] == true)
254                 {
255                     Print(row, col, '*');
256                 }
257                 else
258                 {
259                     Print(row, col, ' ');
260                 }
261             }
262         }
263     }
File name: Program.cs Copy
32     static void Main(string[] args)
33     {
34         SetGameField();
35         StartupScreen();
36
37         isUsed = new bool[Console.WindowWidth, Console.WindowHeight];
38
39
40         while (true)
41         {
42             if (Console.KeyAvailable)
43             {
44                 ConsoleKeyInfo key = Console.ReadKey(true);
45                 ChangePlayerDirection(key);
46             }
47
48
49             MovePlayers();
50
51
52             bool firstPlayerLoses = DoesPlayerLose(firstPlayerRow, firstPlayerColumn);
53             bool secondPlayerLoses = DoesPlayerLose(secondPlayerRow, secondPlayerColumn);
54
55
56             if (firstPlayerLoses && secondPlayerLoses)
57             {
58                 firstPlayerScore++;
59                 secondPlayerScore++;
60                 Console.WriteLine();
61                 Console.WriteLine("Game over");
62                 Console.WriteLine("Draw game!!!");
63                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
64                 ResetGame();
65             }
66             if (firstPlayerLoses)
67             {
68                 secondPlayerScore++;
69                 Console.WriteLine();
70                 Console.WriteLine("Game over");
71                 Console.WriteLine("Second player wins!!!");
72                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
73                 ResetGame();
74             }
75             if (secondPlayerLoses)
76             {
77                 firstPlayerScore++;
78                 Console.WriteLine();
79                 Console.WriteLine("Game over");
80                 Console.WriteLine("First player wins!!!");
81                 Console.WriteLine("Current score: {0} - {1}", firstPlayerScore, secondPlayerScore);
82                 ResetGame();
83             }
84
85
86             isUsed[firstPlayerColumn, firstPlayerRow] = true;
87             isUsed[secondPlayerColumn, secondPlayerRow] = true;
88
89
90             WriteOnPosition(firstPlayerColumn, firstPlayerRow, '*', ConsoleColor.Yellow);
91             WriteOnPosition(secondPlayerColumn, secondPlayerRow, '*', ConsoleColor.Cyan);
92
93
94             Thread.Sleep(100);
95         }
96     }
File name: Program.cs Copy
132     static void ResetGame()
133     {
134         isUsed = new bool[Console.WindowWidth, Console.WindowHeight];
135         SetGameField();
136         firstPlayerDirection = right;
137         secondPlayerDirection = left;
138         Console.WriteLine("Press any key to start again...");
139         Console.ReadKey();
140         Console.Clear();
141         MovePlayers();
142     }
File name: Program.cs Copy
175     static void SetGameField()
176     {
177         Console.WindowHeight = 30;
178         Console.BufferHeight = 30;
179
180
181         Console.WindowWidth = 100;
182         Console.BufferWidth = 100;
183
184
185         /*
186          *
187          * ->>>> <<<<-
188          *
189          */
190         firstPlayerColumn = 0;
191         firstPlayerRow = Console.WindowHeight / 2;
192
193
194         secondPlayerColumn = Console.WindowWidth - 1;
195         secondPlayerRow = Console.WindowHeight / 2;
196     }

Download file with original file name:GameF

GameF 80 lượt xem

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