-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFormLobby.cs
More file actions
123 lines (98 loc) · 3.04 KB
/
FormLobby.cs
File metadata and controls
123 lines (98 loc) · 3.04 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using System;
using System.Text;
using System.Windows.Forms;
namespace ChessMaster
{
public partial class FormLobby : Form
{
public FormLobby()
{
InitializeComponent();
lblCodigo.Text = "";
rbtnJug2Blancas.Enabled = false;
rbtnBlancas.Enabled = true;
rbtnJug1Negras.Enabled = true;
rbtnJug2Negras.Enabled = false;
}
private string GenerarCodigo()
{
int longitud = 5;
const string alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuilder token = new StringBuilder();
Random rnd = new Random();
for (int i = 0; i < longitud; i++)
{
int indice = rnd.Next(alfabeto.Length);
token.Append(alfabeto[indice]);
}
while (BD.ValidarCodigo(token.ToString()) == false)
{
for (int i = 0; i < longitud; i++)
{
int indice = rnd.Next(alfabeto.Length);
token.Append(alfabeto[indice]);
}
}
return token.ToString();
}
private void btnCrearLobby_Click(object sender, EventArgs e)
{
btnUnirse.Enabled = false;
string codigo = GenerarCodigo();
char colorJug1;
char colorJug2;
rbtnBlancas.Enabled = false;
rbtnJug1Negras.Enabled = false;
lblCodigo.Text = codigo;
btnCrearLobby.Enabled = false;
if (rbtnBlancas.Checked == true)
{
colorJug1 = 'b';
colorJug2 = 'n';
}
else
{
colorJug1 = 'n';
colorJug2 = 'b';
}
BD.CrearLobby(codigo, colorJug1, colorJug2);
}
private void rbtnBlancas_CheckedChanged(object sender, EventArgs e)
{
rbtnJug2Negras.Checked = true;
}
private void rbtnJug1Negras_CheckedChanged(object sender, EventArgs e)
{
rbtnJug2Blancas.Checked = true;
}
private void btnUnirse_Click(object sender, EventArgs e)
{
Lobby miLobby = new Lobby();
miLobby = BD.UnirseAlLobby(textBox1.Text.ToUpper().ToString());
rbtnBlancas.Enabled = false;
rbtnJug1Negras.Enabled = false;
if (miLobby != null)
{
if (miLobby.ColorJug1 == 'b')
{
rbtnBlancas.Checked = true;
}
else
{
rbtnJug1Negras.Checked = true;
}
}
else
{
MessageBox.Show("no se encontró la lobby");
}
}
private void btnVolver_Click(object sender, EventArgs e)
{
this.Close();
FormInicio formInicio = new FormInicio();
formInicio.Show();
}
//crear
}
}