-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
145 lines (145 loc) · 2.13 KB
/
main.cpp
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
#include <bits/stdc++.h>
#include <graphics.h>
#include <conio.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace std;
double bx=650,by=300,dx=-1,dy,s=300,cn;
int yy;
void init()
{
initgraph(800,600);
setbkcolor(WHITE);
cleardevice();
settextcolor(RED);
settextstyle(50, 0, _T("黑体"));
outtextxy(300,200,"电子乒乓");
settextcolor(BLUE);
settextstyle(30, 0, _T("楷体"));
outtextxy(310,300,"按任意键继续");
getch();
}
void f1()
{
while(bx<=1000&&bx>=-200)
{
MOUSEMSG m;
m=GetMouseMsg();
if(m.y<50)
{
yy=50;
}
else if(m.y>550)
{
yy=550;
}
else
{
yy=m.y;
}
}
}
void p()
{
BeginBatchDraw();
cleardevice();
setlinestyle(PS_DASH,5);
setlinecolor(BLUE);
line(400,100,400,500);
setfillcolor(RED);
solidrectangle(720,yy-50,740,yy+50);
solidrectangle(80,s-50,60,s+50);
bx+=dx;
by+=dy;
if(bx==710&&by>=yy-50&&by<=yy+50)
{
cn++;
dx=-dx;
dy=(double)rand()/RAND_MAX-0.2;
if(cn<=10)
{
s=dy*620+by;
if(s<0)
{
s=-s;
}
else if(s>600)
{
s=1200-s;
}
if(s<50)
{
s=50;
}
else if(s>550)
{
s=550;
}
}
}
if(bx==90&&by>=s-50&&by<=s+50)
{
dx=-dx;
dy=(double)rand()/RAND_MAX-0.2;
}
if(by<=0||by>=600)
{
dy=-dy;
}
setfillcolor(CYAN);
solidcircle(bx,by,10);
FlushBatchDraw();
}
int main()
{
srand(time(0));
dy=(double)rand()/RAND_MAX-0.2;
init();
cleardevice();
setlinestyle(PS_DASH,5);
setlinecolor(BLUE);
line(400,100,400,500);
setfillcolor(RED);
solidrectangle(720,250,740,350);
solidrectangle(80,250,60,350);
setfillcolor(CYAN);
solidcircle(650,300,10);
outtextxy(310,50,"按任意键发球");
getch();
s=dy*540+300;
if(s<0)
{
s=-s;
}
else if(s>600)
{
s=1200-s;
}
if(s<50)
{
s=50;
}
else if(s>550)
{
s=550;
}
thread t1(f1);
t1.detach();
while(bx<=1000&&bx>=-200)
{
p();
}
if(bx>1000)
{
outtextxy(350,50,"你输了!");
}
else
{
outtextxy(350,50,"你赢了!");
}
outtextxy(310,500,"按任意键退出");
FlushBatchDraw();
getch();
closegraph();
return 0;
}