Guest User

Untitled

a guest
Jun 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1.  class Farm : Drawable
  2.     {
  3.         int size_x;
  4.         int size_y;
  5.         Ground[,] grounds;
  6.  
  7.         public Farm(int size_x, int size_y)
  8.             :base(drawable_type.farm)
  9.         {
  10.             int i,j ;
  11.             i = 0;
  12.             j = 0;
  13.             Random rand;
  14.             rand = new Random();
  15.             this.size_y=size_y;
  16.             this.size_x=size_x;
  17.           this.grounds=new myFarm.Ground[size_x,size_y];
  18.           while (j<=this.size_y-1)
  19.           {
  20.               while (i <=this.size_x-1)
  21.               {
  22.                  
  23.                   if(rand.Next(2)==0)
  24.                   this.grounds[i, j] = new Ground(new Vector2(i, j), groundType.grass, drawable_type.grass);
  25.                      
  26.                   else
  27.                       this.grounds[i,j] = new Ground(new Vector2(i,j),groundType.dirt,drawable_type.dirt);
  28.  
  29.                   i++;
  30.  
  31.                  
  32.               }
  33.               j++;
  34.               i=0;
  35.           }
  36.         }
  37.         public void addAnimal()
  38.         {
  39.             int x;
  40.             int y;
  41.             Random rand = new Random();
  42.             x = rand.Next(size_x);
  43.             y = rand.Next(size_y);
  44.  
  45.  
  46.             if (!this.grounds[x, y].occupied)
  47.             {
  48.                 this.grounds[x, y].occupied = true;
  49.  
  50.                 if (rand.Next(1) == 1)
  51.                     this.grounds[x, y].containing = new Pony(x, y);
  52.                 else
  53.                     this.grounds[x, y].containing = new Hen(x, y);
  54.  
  55.  
  56.                
  57.             }
  58.  
  59.            
  60.         }
  61.         public void display(SpriteBatch sb)
  62.         {
  63.             int i = 0;
  64.             int j = 0;
  65.            
  66.             while (j <= this.size_y - 1 )
  67.             {
  68.                 while (i <= this.size_x - 1)
  69.                 {
  70.                     if (this.grounds[i, j].occupied)
  71.                     {
  72.                         this.grounds[i, j].containing.Draw(sb);
  73.                     }
  74.                    
  75.                     this.grounds[i, j].Draw(sb);
  76.                     i++;
  77.                 }
  78.                 j++;
  79.                 i = 0;
  80.             }
  81.  
  82.         }
  83.     }
  84. }
Add Comment
Please, Sign In to add comment