Advertisement
Guest User

RocksObject

a guest
Mar 5th, 2012
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6.  
  7. namespace SnakeV2
  8. {
  9.     class RocksObject
  10.     {
  11.         public List<Point> List;
  12.         Point Rock;
  13.         Random rnd = new Random();
  14.  
  15.         public RocksObject(Point Food)
  16.         {
  17.             List = new List<Point>();
  18.             refreshRocks(Food);
  19.         }
  20.  
  21.         public void refreshRocks(Point Food)
  22.         {
  23.             List.Clear();
  24.             for (int i = 0; i < 5; i++)
  25.             {
  26.                 Rock = new Point(rnd.Next(2, Console.WindowHeight - 2), rnd.Next(2, Console.WindowWidth - 2));
  27.                 while (Rock.X == Food.X && Rock.Y == Food.Y)
  28.                     Rock = new Point(rnd.Next(2, Console.WindowHeight - 2), rnd.Next(2, Console.WindowWidth - 2));
  29.                 List.Add(Rock);
  30.             }
  31.         }
  32.  
  33.         public void Draw()
  34.         {
  35.             foreach (Point Rock in List)
  36.             {
  37.                 Console.SetCursorPosition(Rock.Y, Rock.X);
  38.                 Console.Write('=');
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement