Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- class Program
- {
- static void Main()
- {
- Console.CursorVisible = false;
- int consoleWidth = Console.WindowWidth;
- int consoleHeight = Console.WindowHeight;
- int ballX = consoleWidth / 2;
- int ballY = consoleHeight / 2;
- int speedX = 1;
- int speedY = 1;
- while (true)
- {
- Console.Clear();
- ballX += speedX;
- ballY += speedY;
- if (ballX <= 0 || ballX >= consoleWidth - 1)
- {
- speedX = -speedX;
- }
- if (ballY <= 0 || ballY >= consoleHeight - 1)
- {
- speedY = -speedY;
- }
- Console.SetCursorPosition(ballX, ballY);
- Console.Write("O");
- Console.SetCursorPosition(0, 0);
- Thread.Sleep(50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement