-
Notifications
You must be signed in to change notification settings - Fork 1
/
stage4.c
100 lines (81 loc) · 1.9 KB
/
stage4.c
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
#include "library.h"
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <unistd.h>
#include <signal.h>
#include <math.h>
#include <time.h>
#include <sys/types.h>
extern char number0[7][5];
extern int score;
extern int bestScore;
extern int bestStage;
void stage4()
{
int tab = 3;
int i;
int input;
int xPower = 0;
char ballCycle[10];
int ballIdx = 0;
char ch;
char startX = 7;
char startY = 11;
char stage[12][15] = { {"707000000000808"},
{"070500000006080"},
{"005080000080600"},
{"000806000708000"},
{"000060505070000"},
{"000000050000000"},
{"000000000000000"},
{"000000000000000"},
{"000000000000000"},
{"000000000000000"},
{"000000000000000"},
{"000000000000000"} };
char circle[CIR_MAX][CIR_MAX];
makeCircle(circle, CIR_SIZE);
clear();
printStageBorder();
initStage(circle, stage);
// loop shoot
srand(time(NULL));
for (i = 0; i < 10; i++)
ballCycle[i] = rand()%4 + '5';
while (!isEnd(stage))
{
xPower = 0;
printPower(xPower);
if (ballIdx > 9)
ballIdx = 0;
stage[startY][startX] = ballCycle[ballIdx++];
// print current and next ball
printCircle(circle, COLS/2 - CIR_SIZE * 8 + CIR_SIZE + startX/2 *CIR_SIZE*2, startY * CIR_SIZE * 2, stage[startY][startX] - '0');
printCircle(circle, COLS - CIR_SIZE * 3 , LINES - CIR_SIZE * 3 , ballCycle[ballIdx%10] - '0');
// choose power
input = getch();
while (input != KEY_UP)
{
if (input == KEY_RIGHT && xPower < 4)
xPower++;
else if (input == KEY_LEFT && xPower > -4)
xPower--;
printPower(xPower);
input = getch();
}
shoot(xPower, circle, stage, &tab);
if (isOver(stage))
{
system("say Game Over!");
return;
}
if (isEnd(stage))
{
system("say Winner Winner Chiken Dinner!");
if (bestStage < 4)
bestStage = 4;
return;
}
}
}