-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayControl.cs
159 lines (141 loc) · 4.13 KB
/
PlayControl.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using TitaniumControlsApp.Properties;
using System.Media;
namespace TitaniumControlsApp
{
public partial class PlayControl : UserControl
{
private int timeMins, timeSecs, readySecs, searchTime = 10;
private bool isActive = false, isReady = false,searchingGame = false;
private SoundPlayer gameReady;
public PlayControl()
{
InitializeComponent();
}
#region TimerSearch
private void RestartTimer()
{
timeMins = 0;
timeSecs = 0;
isActive = false;
ShowTime();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (isActive)
{
timeSecs++;
if (timeSecs >= searchTime)
{
GameReady();
}
if (timeSecs >= 60)
{
timeMins++;
timeSecs = 0;
if (timeMins >= 60)
{
timeMins = 0;
}
}
}
ShowTime();
}
private void ShowTime()
{
secsLbl.Text = String.Format("{0:00}", timeSecs);
minsLbl.Text = String.Format("{0:00}", timeMins);
}
#endregion
private void GameReady()
{
var form = Application.OpenForms["MainWindow"];
if (form.WindowState == FormWindowState.Minimized)
{
form.WindowState = FormWindowState.Normal;
form.Focus();
}
//starting couting
readySecs = 30;
readyTimer.Text = readySecs + "";
isReady = true;
readyTimer.Visible = true;
acceptBtn.Visible = true;
GameReadyLbl.Visible = true;
isActive = false;
gameReady.Play();
}
private void StopSearch()
{
isActive = false;
searchingGame = false;
minsLbl.Visible = false;
secsLbl.Visible = false;
labelDots.Visible = false;
acceptBtn.Visible = false;
GameReadyLbl.Visible = false;
readyTimer.Visible = false;
PlayButton.Image = Resources.play_button1;
RestartTimer();
}
private void StartSearch()
{
isActive = true;
searchingGame = true;
minsLbl.Visible = true;
secsLbl.Visible = true;
labelDots.Visible = true;
searchTime = new Random().Next(3, 16);
PlayButton.Image = Resources.cancel;
}
private void ReadyUp_Tick(object sender, EventArgs e)
{
if (isReady)
{
readySecs--;
readyTimer.Text = String.Format("{00}", readySecs);
if (readySecs < 0)
{
StopSearch();
isReady = false;
}
}
}
private void ReadyUpBtn_Click(object sender, EventArgs e)
{
isActive = false;
isReady = false;
acceptBtn.Visible = false;
gameReady.Stop();
StopSearch();
MessageBox.Show("Znaleziono serwera!\nconnect 168.0.0.1:27015", "Serwer znaleziony!", MessageBoxButtons.OK);
}
private void PlayControl_Leave(object sender, EventArgs e)
{
StopSearch();
}
private void PlayButton_Click(object sender, EventArgs e)
{
if (searchingGame)
{
gameReady.Stop();
StopSearch();
}
else
{
StartSearch();
}
}
private void PlayControl_Load(object sender, EventArgs e)
{
gameReady = new SoundPlayer(Resources.game_ready);
StopSearch();
}
}
}