-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
124 lines (110 loc) · 3.09 KB
/
MainForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BallCollision
{
public partial class MainForm : Form
{
public Scene Scene { get; set; }
public MainForm()
{
InitializeComponent();
Start();
}
private void Start()
{
Scene = new Scene(this.Width, this.Height);
GeneratePlayerScreen();
Generator.Interval = 5000;
Generator.Start();
BallShrink.Interval = 3000;
BallShrink.Start();
status.Interval = 1000;
status.Start();
DoubleBuffered = true;
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
Scene.DrawAll(e.Graphics);
lblPoints.Text = Scene.Points.ToString();
}
private void GeneratePlayerScreen()
{
Scene.GenerateBalls();
Invalidate();
}
private void MainForm_MouseClick(object sender, MouseEventArgs e)
{
Scene.AddPlayerBall(e.Location);
Invalidate();
}
private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
{
if (Scene.PlayerBall == null)
return;
char pressed_key = Char.ToLower(e.KeyChar);
switch(pressed_key)
{
case 'w':
Scene.MoveUp();
break;
case 's':
Scene.MoveDown();
break;
case 'a':
Scene.MoveLeft();
break;
case 'd':
Scene.MoveRight();
break;
default: break;
}
Invalidate();
}
private void Generator_Tick(object sender, EventArgs e)
{
Scene.GenerateBall();
Invalidate();
}
private void BallShrink_Tick(object sender, EventArgs e)
{
Scene.Shrink();
Invalidate();
}
private void checkStatus(object sender, EventArgs e)
{
if (Scene.GameOver)
{
Scene.GameOver = false;
status.Stop();
var result = MessageBox.Show("Играта заврши, изгубивте","Game Over",MessageBoxButtons.RetryCancel);
if (result == DialogResult.Cancel)
{
this.Close();
}
else {
NewGame();
}
}
}
private void Reset()
{
lblPoints.Text = "0";
Scene = new Scene(this.Width, this.Height);
Generator.Stop();
BallShrink.Stop();
}
private void NewGame()
{
Reset();
Start();
Invalidate();
}
}
}