-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnake_function.cpp
126 lines (126 loc) · 3.56 KB
/
snake_function.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
void snake(int score,int i)
{
int x,y,j;
j=score1;
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
player1posX=player1posX+61+61;
else
player1posX=player1posX-61-61;
while(j>=score+1)
{
score1--;
paint(chance,i);
if(score2!=0)
{
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
drawcircle1(player2posX+61,player2posY,1);
else
drawcircle(player2posX-61,player2posY,1);
}
if((player1posX>590)||(player1posX<40))
{
player1posY=player1posY+38;
if(player1posX>590)
player1posX=589;
else
player1posX=40;
}
if(score1==score2)
{
y=player2posY;
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
x=player2posX+61;
else
x=player2posX-61;
paint(chance,i);
setcolor(1);
circle(player1posX-15,player1posY,10);
setfillstyle(SOLID_FILL,GREEN);
floodfill(player1posX-15,player1posY,1);
setcolor(1);
circle(x+15,y,10);
setfillstyle(SOLID_FILL,RED);
floodfill(x+15,y,1);
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
player1posX=player1posX+61;
else
player1posX=player1posX-61;
}
else
{
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
drawcircle(player1posX,player1posY,0);
else
drawcircle1(player1posX,player1posY,0);
}
j--;
delay(200);
}
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
player1posX=player1posX-61-61;
else
player1posX=player1posX+61+61;
}
void snake1(int score,int i)
{
int x,y,j;
j=score2;
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
player2posX=player2posX+61+61;
else
player2posX=player2posX-61-61;
while(j>=score+1)
{
score2--;
paint(chance,i);
if(score1!=0)
{
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
drawcircle1(player1posX+61,player1posY,0);
else
drawcircle(player1posX-61,player1posY,0);
}
if((player2posX>590)||(player2posX<40))
{
player2posY=player2posY+38;
if(player2posX>590)
player2posX=589;
else
player2posX=40;
}
if(score1==score2)
{
y=player1posY;
if((player1posY==332)||(player1posY==256)||(player1posY==180)||(player1posY==104)||(player1posY==28))
x=player1posX+61;
else
x=player1posX-61;
paint(chance,i);
setcolor(1);
circle(x-15,y,10);
setfillstyle(SOLID_FILL,GREEN);
floodfill(x-15,y,1);
setcolor(1);
circle(player2posX+15,player2posY,10);
setfillstyle(SOLID_FILL,RED);
floodfill(player2posX+15,player2posY,1);
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
player2posX=player2posX+61;
else
player2posX=player2posX-61;
}
else
{
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
drawcircle(player2posX,player2posY,1);
else
drawcircle1(player2posX,player2posY,1);
}
j--;
delay(200);
}
if((player2posY==332)||(player2posY==256)||(player2posY==180)||(player2posY==104)||(player2posY==28))
player2posX=player2posX-61-61;
else
player2posX=player2posX+61+61;
}