Advertisement
powerofsoul

25 line game

Jul 11th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System.Linq;
  2. namespace _25linegames{
  3.     class Program{
  4.         static int[] playerPos = new int[] { 0, 0 };
  5.         static int[] enemypos = new int[] { new System.Random().Next(0, 2), 50 };
  6.         static int score = 0;
  7.         static System.Collections.Generic.Dictionary<System.ConsoleKey, System.Action> moves = new System.Collections.Generic.Dictionary<System.ConsoleKey, System.Action>() { { System.ConsoleKey.W, () => playerPos[0] = 0 }, { System.ConsoleKey.S, () => playerPos[0] = 1 } };
  8.         private static string Line(int line) => new string(( Enumerable.Range(0, 50).ToList().Select(x => playerPos[0] == line && playerPos[1] == x ? 'X' : enemypos[0] == line && enemypos[1] == x ? 'E' : ' ').ToArray()));
  9.         static void Main(string[] args) {
  10.             System.Threading.Tasks.Task.Run(() => { while (true){
  11.                 if (playerPos[0] == enemypos[0] && playerPos[1] == enemypos[1]){
  12.                     System.Console.WriteLine($"Game Over. Your score is:{score}");
  13.                     break;
  14.                 }else if(playerPos[1] == 40 ) System.Console.WriteLine("You won!");
  15.                 System.Console.Clear();
  16.                 for (int i = 0; i < 2; i++) System.Console.WriteLine(Line(i));
  17.                 System.Console.WriteLine($"Score:{score}");
  18.                 System.Threading.Thread.Sleep(9);
  19.                 enemypos[1]--;
  20.                 if (enemypos[1] == -1) {
  21.                     enemypos = new int[] { new System.Random().Next(0, 2), 50 };
  22.                         score = ++playerPos[1];
  23.                 }}
  24.             });
  25.         while (true) moves[System.Console.ReadKey().Key]?.Invoke();}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement