X–









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

Featured Snippets

Line Code Ex..
200 ballPositionX--; 1

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         }

X– 74 lượt xem

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