Advertisement
SalyT

Untitled

Dec 12th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. class GameItem
  2.     {
  3.         private int[] DirectionVector;
  4.         private Tile[,] ItemTiles;
  5.         private readonly Color[] TileColors = { Color.Crimson, Color.Aqua, Color.ForestGreen, Color.Indigo, Color.Yellow, Color.Chocolate };
  6.  
  7.         public GameItem()
  8.         {
  9.             int random = new Random(DateTime.Now.Millisecond).Next(0,2);
  10.             if (random == 0)
  11.             {
  12.                 this.DirectionVector = new int[2] { 1, 0 };
  13.             }
  14.             else
  15.             {
  16.                 this.DirectionVector = new int[2] { 0, 1 };
  17.             }
  18.  
  19.             int x = 0;
  20.             int y = 0;
  21.             int colorSelector = new Random(DateTime.Now.Millisecond).Next(0, 6);
  22.  
  23.             this.ItemTiles = new Tile[DirectionVector[0]*2, DirectionVector[1]*2];
  24.  
  25.             for (int i = 0; i < 3; i++)
  26.             {
  27.                 Tile tile = new Tile(x, y);
  28.                 tile.SetColor(this.TileColors[colorSelector]);
  29.                 this.ItemTiles[x, y] = tile; // INDEX OUT OF RANGE
  30.                 x += this.DirectionVector[0];
  31.                 y += this.DirectionVector[1];
  32.             }
  33.            
  34.         }
  35.  
  36.         public int[] GetVector()
  37.         {
  38.             return this.DirectionVector;
  39.         }
  40.  
  41.         public Color GetColor(int x, int y)
  42.         {
  43.             return this.ItemTiles[x, y].BackColor;
  44.         }
  45.  
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement