-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLobby.cs
96 lines (83 loc) · 2.85 KB
/
Lobby.cs
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
//using GameServer;
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace AzulApp
{
public partial class Lobby : Form
{
private readonly TextBox[] txtName;
public Lobby()
{
InitializeComponent();
host = new BackgroundWorker();
host.DoWork += backgroundWorker1_DoWork;
if (!pnlGameType.Enabled)
pnlGameType.Text = "Not yet implemented.";
// Load textboxes into an array for easier access as a "list"
txtName = new TextBox[4];
txtName[0] = txtName0;
txtName[1] = txtName1;
txtName[2] = txtName2;
txtName[3] = txtName3;
}
// Start a new game with the current settings
private void btnStart_Click(object sender, EventArgs e)
{
int numPlayers = (int)spnrNumPlayers.Value;
string[] names = new string[numPlayers];
for (int i = 0; i < numPlayers; i++)
{
names[i] = txtName[i].Text.Trim().Length > 0 ? txtName[i].Text.Trim() : defaultNames[i];
}
Enabled = false;
Game g = new Game(numPlayers, names);
g.FormClosed += OnGameOver;
g.Show();
}
// Only enough name boxes for the number of players are enabled
private void NumPlayersChanged(object sender, EventArgs e)
{
int count = (int)spnrNumPlayers.Value;
int i = 2;
while (i < count)
{
txtName[i++].Enabled = true;
}
while (i < 4)
{
txtName[i++].Enabled = false;
}
}
// Can only open lobby if hosting a network game
private void rbHost_CheckedChanged(object sender, EventArgs e)
{
btnOpen.Enabled = rbHost.Checked;
}
// Starts the server proccess in another thread
private void btnOpen_Click(object sender, EventArgs e)
{
host.RunWorkerAsync();
}
// Can only join a lobby if joining a network game
private void rbJoin_CheckedChanged(object sender, EventArgs e)
{
btnJoin.Enabled = rbJoin.Checked;
}
private void btnJoin_Click(object sender, EventArgs e)
{
// IDK, some kind of search/address input dialog?
}
// Game is over (someone won or game abandoned, either way game windows have closed)
public void OnGameOver(object sender, EventArgs e)
{
Enabled = true;
Focus();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
//new Server();
}
private static readonly string[] defaultNames = { "Player 1", "Player 2", "Player 3", "Player 4" };
}
}