Panglot

Falling rocks

Mar 31st, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Threading;
  7. namespace FallingRocks
  8. {
  9.     class FallingRocksGame
  10.     {
  11.         static string[] obsticles = new string[] { "^", "@", "*", "&", "-", "+", "%", "#" };
  12.         static Obsticle dwarf = new Obsticle() { Value = "(0)", X = Console.WindowWidth / 2, Y = Console.WindowHeight };
  13.         static List<Obsticle> obsticlesList = new List<Obsticle>();
  14.         static Random rand = new Random();
  15.  
  16.         static void Main(string[] args)
  17.         {
  18.             Console.Title = "Dwarf Game";
  19.             Console.CursorVisible = false;
  20.             // Console.SetBufferSize(Console.WindowHeight - 1, Console.WindowHeight - 1);
  21.             Console.ForegroundColor = ConsoleColor.Cyan;
  22.             while (true)
  23.             {
  24.                 Thread.Sleep(170);
  25.                 Console.Clear();
  26.  
  27.  
  28.                 // add new rock
  29.                 obsticlesList.Add(new Obsticle() { Value = obsticles[rand.Next(0, obsticles.Length)], Y = 0, X = rand.Next(0, Console.WindowWidth) });
  30.  
  31.                 for (int i = 0; i < obsticlesList.Count; i++)
  32.                 {
  33.                     obsticlesList[i].Y++;
  34.                     if (obsticlesList[i].Y > Console.WindowHeight)
  35.                     {
  36.                         obsticlesList.RemoveAt(i);
  37.                         continue;
  38.                     }
  39.  
  40.                     if (obsticlesList[i].Y == dwarf.Y && (obsticlesList[i].X == dwarf.X || obsticlesList[i].X == dwarf.X + 2 || obsticlesList[i].X == dwarf.X + 1))
  41.                     {
  42.                         Console.Clear();
  43.                         Console.SetCursorPosition(Console.WindowWidth / 2, Console.WindowHeight / 2);
  44.                         Console.WriteLine("GAME OVER");
  45.                         Console.ReadKey();
  46.                         return;
  47.                     }
  48.                     Console.SetCursorPosition(obsticlesList[i].X, obsticlesList[i].Y);
  49.                     Console.Write(obsticlesList[i].Value);
  50.                 }
  51.                 if (Console.KeyAvailable)
  52.                 {
  53.                     ConsoleKeyInfo keyPressed = Console.ReadKey();
  54.                     if (keyPressed.Key == ConsoleKey.LeftArrow)
  55.                     {
  56.                         dwarf.X -= 2;
  57.                     }
  58.                     else if (keyPressed.Key == ConsoleKey.RightArrow)
  59.                     {
  60.                         dwarf.X += 2;
  61.                     }
  62.  
  63.                 }
  64.                 // write dwarf
  65.                 Console.SetCursorPosition(dwarf.X, dwarf.Y);
  66.                 Console.Write(dwarf.Value);
  67.             }
  68.         }
  69.  
  70.  
  71.         static void CheckMoveDwarf()
  72.         {
  73.  
  74.         }
  75.     }
  76.     class Obsticle
  77.     {
  78.         public string Value { get; set; }
  79.  
  80.         public int X { get; set; }
  81.  
  82.         public int Y { get; set; }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment