Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WindowHeight = 40;
- Console.WindowWidth = 53;
- Console.BufferHeight = Console.WindowHeight;
- Console.BufferWidth = Console.WindowWidth;
- Console.SetCursorPosition(10, 10);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write("First player name: ");
- var name1 = Console.ReadLine();
- Console.ResetColor();
- Console.SetCursorPosition(10, 20);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("Second player name: ");
- var name2 = Console.ReadLine();
- Console.ResetColor();
- Console.Clear();
- //player1 cordinates
- var playerOneY = 49 / 2;
- var playerOneX = 25;
- var playerOneIcon = "[]";
- int firstPlayerScores = 0;
- //player1 Projectile
- var projectileOneX = 0;
- var projectileOneY = 0;
- var projectileOneIcon = "|";
- var projectileOneVisible = false;
- //player2 cordinates
- var playerTwoX = 49 / 2 + 1;
- var playerTwoY = 5;
- var playerTwoIcon = "[]";
- int secondPlayerScores = 0;
- //player2 Projectile
- var projectileTwoX = 0;
- var projectileTwoY = 0;
- var projectileTwoIcon = "|";
- var projectileTwoVisible = false;
- //left wall
- var leftWall = 0;
- var leftWallicon = "|";
- Console.SetCursorPosition(15, 15);
- Console.WriteLine("Press any key to start");
- Console.CursorVisible = false;
- //player One scores
- var scorePlayer1X = 0;
- var scorePlayer1Y = 37;
- //player two scores
- var scorePlayer2X = 0;
- var scorePlayer2Y = 39;
- while (true)
- {
- while (true)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo pressedKey = Console.ReadKey();
- switch (pressedKey.Key)
- {
- //player One
- case ConsoleKey.LeftArrow:
- if (playerOneX - 1 >= 4)
- {
- playerOneX = playerOneX - 1;
- }
- break;
- case ConsoleKey.RightArrow:
- if (playerOneX + 1 < 50)
- {
- playerOneX = playerOneX + 1;
- }
- break;
- case ConsoleKey.UpArrow:
- if (playerOneY - 1 >= (33 / 2) + 2)
- {
- playerOneY = playerOneY - 1;
- }
- break;
- case ConsoleKey.DownArrow:
- if (playerOneY + 1 < 35)
- {
- playerOneY = playerOneY + 1;
- }
- break;
- case ConsoleKey.Enter:
- projectileOneX = playerOneX;
- projectileOneY = playerOneY - 1;
- projectileOneVisible = true;
- break;
- //player Two
- case ConsoleKey.A:
- if (playerTwoX - 1 >= 4)
- {
- playerTwoX = playerTwoX - 1;
- }
- break;
- case ConsoleKey.D:
- if (playerTwoX + 1 < 50)
- {
- playerTwoX = playerTwoX + 1;
- }
- break;
- case ConsoleKey.W:
- if (playerTwoY - 1 >= 1)
- {
- playerTwoY = playerTwoY - 1;
- }
- break;
- case ConsoleKey.S:
- if (playerTwoY + 1 < (33 / 2) + 1)
- {
- playerTwoY = playerTwoY + 1;
- }
- break;
- case ConsoleKey.Spacebar:
- projectileTwoX = playerTwoX;
- projectileTwoY = playerTwoY + 1;
- projectileTwoVisible = true;
- break;
- }
- Console.Clear();
- Console.CursorVisible = false;
- for (int i = 0; i < 1; i++)
- {
- Console.WriteLine("{0}|{1}|",
- new string(' ', 3),
- new string('*', 47));
- }
- for (int i = 0; i <= 33; i++)
- {
- Console.Write(" " + leftWallicon);
- if (leftWall <= 33)
- {
- leftWall++;
- }
- if (i == 33 / 2)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.Write(new string('-', 47));
- Console.ResetColor();
- }
- else
- {
- Console.Write(new string(' ', 47));
- }
- Console.Write(leftWallicon);
- if (leftWall < 28)
- {
- leftWall++;
- }
- Console.WriteLine();
- }
- for (int i = 0; i < 1; i++)
- {
- Console.Write(" {0}",
- new string('^', 49));
- }
- }
- if (projectileOneVisible)
- {
- Console.SetCursorPosition(projectileOneX, projectileOneY);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(projectileOneIcon);
- Console.ResetColor();
- if (projectileOneY > 0)
- {
- projectileOneY--;
- projectileOneVisible = true;
- }
- else
- {
- projectileOneVisible = false;
- }
- }
- if (projectileTwoVisible)
- {
- Console.SetCursorPosition(projectileTwoX, projectileTwoY);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(projectileTwoIcon);
- Console.ResetColor();
- if (projectileTwoY < 35)
- {
- projectileTwoY++;
- }
- else
- {
- projectileTwoVisible = false;
- }
- }
- if (projectileOneX == playerTwoX && projectileOneY == playerTwoY)
- {
- projectileOneVisible = true;
- firstPlayerScores = firstPlayerScores + 1;
- }
- if (projectileTwoX == playerOneX && projectileTwoY == playerOneY)
- {
- projectileTwoVisible = true;
- secondPlayerScores = secondPlayerScores + 1;
- }
- Console.SetCursorPosition(scorePlayer1X, scorePlayer1Y);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(name1 + "'s score is: " + firstPlayerScores);
- Console.ResetColor();
- Console.SetCursorPosition(scorePlayer2X, scorePlayer2Y);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(name2 + "'s score is: " + secondPlayerScores);
- Console.ResetColor();
- Console.SetCursorPosition(playerOneX, playerOneY);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(playerOneIcon);
- Console.ResetColor();
- Console.SetCursorPosition(playerTwoX, playerTwoY);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(playerTwoIcon);
- Console.ResetColor();
- Thread.Sleep(0);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement