Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.4 kB
1
Indexable
Never
using System;
using System.Console;

namespace Pong
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Pong v0.1");
            Console.WriteLine("");
            Console.WriteLine("Press any key to start the game.");
            Console.ResetColor();

            var currentPlayer = 1;
            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey().Key;
                    if (key == ConsoleKey.W || key == ConsoleKey.S)
                    {
                        if (currentPlayer == 1)
                        {
                            Console.SetCursorPosition(0, 13);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("O");
                            switch (key)
                            {
                                case ConsoleKey.W:
                                    Console.Write("o");
                                    Console.SetCursorPosition(0, 13);
                                    break;
                                case ConsoleKey.S:
                                    Console.Write("\\");
                                    Console.SetCursorPosition(3, 12);
                                    break;
                            }
                            currentPlayer = 2;
                        }
                        else
                        {
                            Console.SetCursorPosition(4, 13);
                            Console.ForegroundColor = ConsoleColor.DarkGreen;
                            Console.Write("X");
                            console.resetcolor();
                            switch (key)
                            {
                                case ConsoleKey.W:
                                    Console.Write("x");
                                    break;
                                case ConsoleKey.S:
                                    Console.Write("\\\\");
                                    Console.SetCursorPosition(7, 12);
                                    break;
                            }
                        }
                        break;
                    }
                }
            }
        }
    }
}`