3 Colores aleatorios
Publicado por Flash (21 intervenciones) el 22/09/2016 22:08:13
Buenos dias/Tardes/Noches
Tengo que problema que a lo mejor es una tonteria pero,el caso es que para practicar cosas propias queria hacer un pequeño jueguecillo en donde debia decir cuantas cajas rojas ahi(ni terminado esta falta el boton comprobar)
La cosa es que le he puesto que sea aleatorio pero solo es aleatorio si lo hago con F11(Debugger), os adjunto el codigo
P.D: El echo de que sean botones es porque no se hacer recuadros manualmente
Tengo que problema que a lo mejor es una tonteria pero,el caso es que para practicar cosas propias queria hacer un pequeño jueguecillo en donde debia decir cuantas cajas rojas ahi(ni terminado esta falta el boton comprobar)
La cosa es que le he puesto que sea aleatorio pero solo es aleatorio si lo hago con F11(Debugger), os adjunto el codigo
P.D: El echo de que sean botones es porque no se hacer recuadros manualmente
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace Laberinto
{
partial class Form1
{
///
/// Variable del diseñador requerida.
///
private System.ComponentModel.IContainer components = null;
///
/// Limpiar los recursos que se estén utilizando.
///
/// true si los recursos administrados se deben eliminar; false en caso contrario, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Código generado por el Diseñador de Windows Forms
///
/// Método necesario para admitir el Diseñador. No se puede modificar
/// el contenido del método con el editor de código.
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.TextBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "Reiniciar";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(130, 480);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(300, 23);
this.button2.TabIndex = 1;
this.button2.Text = "Comprobar";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
//textbox1
this.TextBox1.Location = new System.Drawing.Point(100, 450);
this.TextBox1.Name = "Resultado";
this.TextBox1.Size = new System.Drawing.Size(100, 100);
this.TextBox1.TabIndex = 2;
this.TextBox1.Text = "Respuesta aqui";
// Form1
// ;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 600);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Controls.Add(this.TextBox1);
this.Name = "1Ejemplo";
this.Text = "1Ejemplo";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox TextBox1;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Laberinto
{
public partial class Form1 : Form
{
private Button[,] col;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int x = 12;
int y = 38;
//Este sera el array con las dos filas
col = new Button[3, 3];
for (int fil = 0; fil < col.GetLength(0); fil++)
{
for (int lug = 0; lug < col.GetLength(1); lug++)
{
col[fil, lug] = new Button();
col[fil, lug].Location = new Point(x, y);
col[fil, lug].Size = new Size(100, 100);
Controls.Add(col[fil, lug]);
x = x + 120;
}
y = y + 100;
x = 12;
}
}
void Reiniciar(){
for(int f=0; f<3;f++)
{
for(int l=0;l<3;l++)
{
Random ale = new Random();
int color = ale.Next(0, 30);
if(color>=0&&color<=10){
col[f,l].BackColor=Color.Red;
}
if(color>11&&color<20){
col[f,l].BackColor=Color.Blue;
}
if(color>20)
col[f,l].BackColor=Color.Yellow;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Reiniciar();
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}
Valora esta pregunta


0