Advertisement
Guest User

c# random generation

a guest
Feb 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Test_Game
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void Form1_Load(object sender, EventArgs e)
  21.         {
  22.            /* int[][] map = new int[][]
  23.             {
  24.                 new int[] { 0,0,0,0,0,0 },
  25.                 new int[] { 0,0,0,0,0,0 },
  26.                 new int[] { 0,0,0,0,0,0 },
  27.                 new int[] { 0,0,0,0,0,0 },
  28.                 new int[] { 0,0,0,0,0,0 },
  29.                 new int[] { 0,0,0,0,0,0 }
  30.             };
  31.             */
  32.             // CREATE MAP
  33.             int size = new int();
  34.             size = 64;
  35.             int[,] map = new int[size, size];
  36.             int crow = new int();
  37.             int cpos = new int();
  38.             crow = 0;
  39.             cpos = 0;
  40.             for (int i = 0; i < size * size; i++)
  41.             {
  42.                 Random rnd = new Random();
  43.                 int type = rnd.Next(0, 2);
  44.                
  45.                 map[cpos,crow] = type;
  46.                 cpos++;
  47.                 if (cpos == size)
  48.                 {
  49.                     cpos = 0;
  50.                     crow++;
  51.                 }
  52.             }
  53.  
  54.             int row = new int();
  55.             int pos = new int();
  56.             int curx = new int();
  57.             int cury = new int();
  58.             Boolean temp = new Boolean();
  59.             temp = false;
  60.             row = 0;
  61.             pos = 0;
  62.             curx = 0;
  63.             cury = 0;
  64.             for (int i = 0; i < map.Length; i++)
  65.             {
  66.                 if (map[row, pos] == 0)
  67.                 {
  68.                     PictureBox tile = new PictureBox();
  69.                     tile.Size = new System.Drawing.Size(64, 64);
  70.                     if (temp == false)
  71.                     {
  72.                         tile.BackColor = Color.Magenta;
  73.                         temp = true;
  74.                     }
  75.                     else
  76.                     {
  77.                         tile.BackColor = Color.Black;
  78.                         temp = false;
  79.                     }
  80.                     tile.Visible = true;
  81.                     tile.Location = new Point(curx, cury);
  82.                     this.Controls.Add(tile);
  83.                     curx = curx + 64;
  84.  
  85.                 }
  86.                 if (map[row, pos] == 1)
  87.                 {
  88.                     PictureBox tile = new PictureBox();
  89.                     tile.Size = new System.Drawing.Size(64, 64);
  90.                     if (temp == false)
  91.                     {
  92.                         tile.BackColor = Color.Magenta;
  93.                         temp = true;
  94.                     }
  95.                     else
  96.                     {
  97.                         tile.BackColor = Color.Blue;
  98.                         temp = false;
  99.                     }
  100.                     tile.Visible = true;
  101.                     tile.Location = new Point(curx, cury);
  102.                     this.Controls.Add(tile);
  103.                     curx = curx + 64;
  104.  
  105.                 }
  106.                 pos++;
  107.                 if (pos == size)
  108.                 {
  109.                     pos = 0;
  110.                     curx = 0;
  111.                     row++;
  112.                     cury = cury + 64;
  113.                     if (temp == true)
  114.                     {
  115.                         temp = false;
  116.                     } else
  117.                     {
  118.                         temp = true;
  119.                     }
  120.                 }
  121.             }
  122.  
  123.  
  124.  
  125.             /*     CREATE A PICTUREBOX
  126.             PictureBox Player = new PictureBox();
  127.             Player.Size = new System.Drawing.Size(64, 64);
  128.             Player.BackColor = Color.Red;
  129.             Player.Visible = true;
  130.             Player.Location = new Point((this.Width / 2) - Player.Width / 2,(this.Height / 2) - Player.Height / 2);
  131.             this.Controls.Add(Player);
  132.             */    
  133.     }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement