-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRedBall.cs
104 lines (85 loc) · 2.49 KB
/
RedBall.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
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
class RedBall : Form
{
private int ballx = 150;
private int bally = 150;
private int ballxspeed = 7;
private int ballyspeed = 5;
private int pdellx = 50;
private int score = 0;
private int bestscore = 0;
private int finallscore = 0;
bool satrted, gameover;
// Jocker programming language...
public static void Main()
{
Application.Run(new RedBall());
}
public RedBall()
{
Text = "RedBall..";
ClientSize = new Size(800, 600);
ForeColor = SystemColors.WindowText;
BackColor = SystemColors.Window;
FormBorderStyle = FormBorderStyle.Fixed3D;
MaximizeBox = false;
//
//ResizeRedraw = true;
Timer timer = new Timer();
timer.Interval = 18;
timer.Tick += new EventHandler(TimerOn);
timer.Start();
}
protected override void OnMouseMove(MouseEventArgs e)
{
pdellx = e.X-10;
ResizeRedraw = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyData == Keys.Left)
{
pdellx = e.GetHashCode();
}
}
protected virtual void TimerOn(object obj, EventArgs ea)
{
Graphics graf = CreateGraphics();
Brush brush = new SolidBrush(Color.Cyan);
Point pt = new Point();
Rectangle rect = new Rectangle(0, 0,800, 600);
// graf.FillEllipse(brush, rect);
graf.FillRectangle(brush, rect);
graf.FillRectangle(new SolidBrush(Color.Green), new Rectangle(0, 550,800, 100));
graf.FillEllipse(new SolidBrush(Color.Red), new Rectangle(ballx, bally, 30, 30));
graf.FillRectangle(new SolidBrush(ForeColor), new Rectangle(pdellx, 520, 100, 20));
graf.Dispose();
ballx = ballx + ballxspeed;
bally = bally + ballyspeed;
if ((ballx >= pdellx) && (ballx <= pdellx + 100) && (bally >= 500))
{
ballyspeed = -7;
}
if (bally >= 600)
{
bally = 30;
gameover = true;
}
if (bally <= 0)
{
ballyspeed = 7;
}
if (ballx >= 775)
{
ballxspeed = -5;
}
if (ballx <= 0)
{
ballxspeed = 5;
}
// ResizeRedraw = true;
}
}