Advertisement
BorisSimeonov

Falling Rocks - Console Version

Nov 18th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.78 KB | None | 0 0
  1. using System;
  2.  
  3. class FallingRocks
  4. {
  5.     static void Main()
  6.     {
  7.         string[,] intArray = {
  8.                           { "|", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "|" },
  9.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  10.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  11.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  12.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  13.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  14.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  15.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  16.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  17.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  18.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  19.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  20.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  21.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  22.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  23.                           { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" },
  24.                           { "|", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "|" },
  25.                           };
  26.         uint points = 0;
  27.         string dwarfPointer = "Y";
  28.         //dwarf row = 15
  29.         int dwarfPosition = 6;
  30.         bool gameOn = true;
  31.         ConsoleKeyInfo keyPressed;
  32.         int speed = 320;
  33.         string achievement = "Novice";
  34.         while (gameOn)
  35.         {
  36.             string[] firstLine = { "|", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "|" };
  37.  
  38.             Random rnd = new Random();
  39.             int newSimbolCnt = rnd.Next(1, 3);
  40.             for (int cnt = 0; cnt < newSimbolCnt; cnt++)
  41.             {
  42.                 int simbolPosition = rnd.Next(1, 13);
  43.                 if (firstLine[simbolPosition] != " ")
  44.                 {
  45.                     cnt--;
  46.                     continue;
  47.                 }
  48.                 int simbolValue = rnd.Next(1, 12);
  49.                 string simbol = getSimbol(simbolValue);
  50.                 firstLine[simbolPosition] = simbol;
  51.             }
  52.  
  53.             //change row value
  54.             for (int row = 15; row > 0; row--)
  55.             {
  56.                 for (int col = 0; col <= 13; col++)
  57.                 {
  58.                     intArray[row, col] = intArray[row - 1, col];
  59.                 }
  60.             }
  61.             for (int col = 0; col < 14; col++)
  62.             {
  63.                 intArray[1, col] = firstLine[col];
  64.             }
  65.             //Get consoleKey
  66.             if (Console.KeyAvailable)
  67.             {
  68.                 keyPressed = Console.ReadKey();
  69.                 if (keyPressed.Key == ConsoleKey.LeftArrow && (dwarfPosition - 1) >= 1)
  70.                 {
  71.                     dwarfPosition--;
  72.                 }
  73.                 else if (keyPressed.Key == ConsoleKey.RightArrow && (dwarfPosition + 1) <= 12)
  74.                 {
  75.                     dwarfPosition++;
  76.                 }
  77.             }
  78.             //check dwarf position and end game
  79.             if (intArray[15, dwarfPosition] == " ")
  80.             {
  81.                 intArray[15, dwarfPosition] = dwarfPointer;
  82.             }
  83.             else
  84.             {
  85.                 Console.Clear();
  86.                 Console.WriteLine("Game Over\r\nScore: {0}.\r\nSkill Level: {1}", points, achievement);
  87.                 break;
  88.             }
  89.             System.Threading.Thread.Sleep(speed);
  90.             Console.Clear();
  91.             //display all
  92.             for (int row = 0; row <= 16; row++)
  93.             {
  94.                 for (int col = 0; col < 14; col++)
  95.                 {
  96.                     Console.Write("{0,-3}", intArray[row, col]);
  97.                 }
  98.                 Console.WriteLine();
  99.             }
  100.             points += 10;
  101.             if (points == 500)
  102.             {
  103.                 achievement = "Good Job!";
  104.                 speed = 280;
  105.             }
  106.             if (points == 1000)
  107.             {
  108.                 achievement = "Superior!";
  109.                 speed = 230;
  110.             }
  111.             if (points == 1500)
  112.             {
  113.                 achievement = "Insane!";
  114.                 speed = 150;
  115.             }
  116.             if (points == 3000)
  117.             {
  118.                 achievement = "GODLIKE !!!";
  119.                 speed = 125;
  120.             }
  121.             Console.Write("Points: {0}  Achievement:{1}", points, achievement);
  122.         }
  123.     }
  124.  
  125.     private static string getSimbol(int simbolValue)
  126.     {
  127.         string str = "";
  128.         switch (simbolValue)
  129.         {
  130.             case 1: str = "^";
  131.                 break;
  132.             case 2: str = "@";
  133.                 break;
  134.             case 3: str = "*";
  135.                 break;
  136.             case 4: str = "&";
  137.                 break;
  138.             case 5: str = "+";
  139.                 break;
  140.             case 6: str = "$";
  141.                 break;
  142.             case 7: str = "#";
  143.                 break;
  144.             case 8: str = "!";
  145.                 break;
  146.             case 9: str = ".";
  147.                 break;
  148.             case 10: str = ";";
  149.                 break;
  150.             case 11: str = "%";
  151.                 break;
  152.         }
  153.         return str;
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement