Guest User

Untitled

a guest
May 27th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. for (int i = 0; i < arr.GetLength(0); i++)
  2. {
  3. cx = x;
  4. for (int j = 0; j < arr.GetLength(1); j++)
  5. {
  6. value = rnd.Next(0, 2);
  7. t = new Button();
  8. t.Tag = new Place(i,j);
  9. //if (value == 1)
  10. //{
  11. // t.Text = "";
  12. //} // A TEST TO TEST VALUES OF TEXTS ON BUTTONS.
  13. //else
  14. //{
  15. // t.Text = "CsdUS";
  16. //}
  17. if (value == 0)
  18. { rndmimg = rnd.Next(1, 2); }
  19. else
  20. { rndmimg = rnd.Next(2, 6); }
  21. t.BackColor = Color.Red;
  22. t.BackgroundImageLayout = ImageLayout.Stretch;
  23. t.BackgroundImage = Image.FromFile("..\..\Pictures\"+rndmimg+".png");
  24. //t.BackgroundImage = Image.FromFile("..\..\Pictures\2000.png");
  25. t.Bounds = new Rectangle(cx, y, w, h);
  26. //t.BackColor = Color.Red;
  27. t.Click += new System.EventHandler(this.qqq_Click);
  28.  
  29. this.Controls.Add(t);
  30. arr[i, j] = t;
  31. cx += w;
  32.  
  33. }
  34. y += h;
  35.  
  36. }
  37.  
  38. }
  39.  
  40. public Form1()
  41. {
  42.  
  43. InitializeComponent();
  44. }
  45.  
  46. private void Form1_Load(object sender, EventArgs e)
  47. {
  48. rnd = new Random();
  49. }
  50.  
  51. private void qqq_Click(object sender, EventArgs e) //When Click
  52. {
  53. int px;
  54. int py;
  55. Place pl = (Place)(((Button)sender).Tag);
  56. px = pl.GetR();
  57. py = pl.GetC();
  58. rndmcus = rnd.Next(0, 2); //Rndmcus Determines the color when clicked the button.
  59.  
  60. if (rndmcus == 0)
  61. {
  62. mishvalue = 0;
  63. arr[px,py].BackColor = Color.Green;
  64. arr[px, py].Enabled = false;
  65. }
  66.  
  67. if (rndmcus == 1)
  68. {
  69. mishvalue = 1;
  70. arr[px, py].BackColor = Color.Blue;
  71. arr[px, py].Enabled = false;
  72. }
  73. ((Button)sender).Text = " ";
  74. scanner();
  75. }
  76.  
  77. public void scanner()
  78. {
  79. int counter=0;
  80. for (int i = 0; i < arr.GetLength(0); i++)
  81. {
  82. for (int j = 0; j < arr.GetLength(0); j++)
  83. {
  84. if (arr[i, j].Text == " ")
  85. {
  86. counter++;
  87. }
  88. }
  89. }
  90. if (counter == boardsize * boardsize) // מה קורה כאשר כל הלוח מלא בתשובות נכונות?
  91. {
  92. this.Close();
  93.  
  94. }
  95. }
  96.  
  97. //public int Linescan(int px)
  98. //{
  99. // if (px == boardsize)
  100. // {
  101.  
  102. // return px; //CHANGEEEEE
  103. // }
  104. //}
  105. }
  106. }
  107.  
  108. //Class Place:
  109. class Place
  110. {
  111. private int r;
  112. private int c;
  113.  
  114. public Place(int r, int c)
  115. {
  116. this.r = r;
  117. this.c = c;
  118. }
  119.  
  120. public int GetR()
  121. {
  122. return this.r;
  123. }
  124.  
  125. public int GetC()
  126. {
  127. return this.c;
  128. }
  129.  
  130. public void SetR(int r)
  131. {
  132. this.r = r;
  133. }
  134.  
  135. public void SetC(int c)
  136. {
  137. this.c = c;
  138. }
  139. }
  140.  
  141. for (int j = 0; j < arr.GetLength(1); j++)
  142. {
  143. value = rnd.Next(0, 2);
  144. t = new Button();
  145. t.ID = j.ToString();
  146.  
  147. Button button = (Button)sender;
  148. string buttonId = button.ID;
Add Comment
Please, Sign In to add comment