请高手帮我看看下面的程序那里出错了!这是个俄罗斯方块的源码,运行平台:DOS+TC3.0
答案:2 悬赏:40 手机版
解决时间 2021-03-17 11:22
- 提问者网友:疯子也有疯子的情调
- 2021-03-16 12:16
请高手帮我看看下面的程序那里出错了!这是个俄罗斯方块的源码,运行平台:DOS+TC3.0
最佳答案
- 五星知识达人网友:迟山
- 2021-03-16 13:03
void render(void);
void initMap(void);
void newGame();
void rotateBox(int box1[5][5], int box2[5][5]);
void rebuidNext();
int drop();
void putBox();
void clear();
int move(int dir);
int test(int mx, int my, int box[5][5]);
int rotate();
int newfall();
int main();
int map[MAX_Y+4][MAX_X+4];
int curbox[5][5];
int curx, cury;
int nextbox[5][5];
int box[MAX_C][5][5] = {
{
{0,0,0,0,0},
{0,0,0,0,0},
{1,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,0,1,1,0},
{0,1,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,0,1,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{
{0,0,0,0,0},
{0,0,1,1,0},
{0,0,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
}
};
Timer tDown;
Timer tFast;
int speed = 13;
#define FAST_INTV 1
int GetTickCount() {
int ret;
ret = peek(0x0,0x46e);
ret <<= 8;
ret += peek(0x0,0x46c);
return (ret);
}
int setTimer(Timer *t, unsigned int intv, BOOL en) {
t -> enabled = en;
t -> intervel = intv;
t -> lasttime = GetTickCount();
return 0;
}
BOOL testTimer(Timer *t) {
unsigned int tmp, dt;
if (!(t -> enabled)) return FALSE;
tmp = GetTickCount();
dt = tmp - (t -> lasttime);
if(dt >= t -> intervel) {
t -> lasttime = tmp;
return TRUE;
}
return FALSE;
}
void render(void) {
int x, y;
static int cPage = 0;
#define STARTX 50
#define STARTY 0
#define LEN 18
setactivepage(cPage=(cPage == 0?1:0));
cleardevice();
setcolor(15);
rectangle( STARTX + LEN * 2 - 2,
STARTY + LEN * 3 - 2,
STARTX + LEN * (MAX_X - 2) + 2,
STARTY + LEN * (MAX_Y - 2) + 2);
setfillstyle(SOLID_FILL, 5);
for(y = 3; y < MAX_Y - 2; y++) {
for(x = 2; x < MAX_X - 2; x++) {
if(map[y][x]) {
rectangle( x * LEN + STARTX,
y * LEN + STARTY,
x * LEN + STARTX + LEN,
y * LEN + STARTY + LEN);
bar( x * LEN + STARTX + 1,
y * LEN + STARTY + 1,
x * LEN + STARTX + LEN - 2,
y * LEN + STARTY + LEN - 2);
}
}
}
for(y = 0; y < 5; y++) {
for(x = 0; x < 5; x++) {
if(curbox[y][x]) {
if(y + cury > 2) {
rectangle( (x + curx) * LEN + STARTX,
(y + cury) * LEN + STARTY,
(x + curx) * LEN + STARTX + LEN,
(y + cury) * LEN + STARTY + LEN);
bar( (x + curx) * LEN + STARTX + 1,
(y + cury) * LEN + STARTY + 1,
(x + curx) * LEN + STARTX + LEN - 2,
(y + cury) * LEN + STARTY + LEN - 2);
}
}
}
}
for(y = 0; y < 5; y++) {
for(x = 0; x < 5; x++) {
if(nextbox[y][x]) {
rectangle( x * LEN + 320,
y * LEN + 10,
x * LEN + 338,
y * LEN + 28);
bar( x * LEN + 321,
y * LEN + 11,
x * LEN + 336,
y * LEN + 26);
}
}
}
setvisualpage(cPage);
}
void initMap(void) {
int x, y;
for(y = 0; y < MAX_Y; y++) {
for(x = 0; x < MAX_X; x++) {
if(x < 2 || x > MAX_X - 3 || y > MAX_Y - 3)
map[y][x] = 1;
else map[y][x] = 0;
}
}
}
void newGame() {
int x, y;
initMap();
srand(GetTickCount());
rebuidNext();
setTimer(&tDown, speed, 1);
setTimer(&tFast, FAST_INTV, 1);
newfall();
}
void rotateBox(int box1[5][5], int box2[5][5]) {
int x, y;
for(x = 0; x < 5; x++)
for(y = 4; y >= 0; y--)
box2[y][x] = box1[x][4 - y];
}
void rebuidNext() {
int i, x, y;
i = random(MAX_C);
for(y = 0; y < 5; y++)
for(x = 0; x < 5; x++)
nextbox[y][x] = box[i][y][x];
}
int drop() {
int newy;
newy = cury + 1;
if(test(curx, newy, curbox)) {
cury = newy;
return 1;
}
return 0;
}
void putBox() {
int x, y;
for(y = 0; y < 5; y++)
for(x = 0; x < 5; x++)
if(curbox[y][x])
map[y + cury][x + curx] = curbox[y][x];
}
void clear() {
int x, y;
int dx, dy;
int fullflag;
for(y = 0; y < MAX_Y - 2; y++) {
fullflag = 1;
for(x = 2; x < MAX_X - 2; x++) {
if(!map[y][x]) {
fullflag = 0;
break;
}
}
if(fullflag) {
for(dy = y; dy > 0; dy--)
for(dx = 2; dx < MAX_X - 2; dx++)
map[dy][dx] = map[dy - 1][dx];
for(dx = 2; dx < MAX_X - 2; dx++)
map[0][dx] = 0;
}
}
}
int move(int dir) {
int newx;
if(dir) newx = curx + 1;
else newx = curx - 1;
if(test(newx, cury, curbox)) {
curx = newx;
return 1;
}
return 0;
}
int test(int mx, int my, int box[5][5]) {
int x, y;
for(y = 0; y < 5; y++)
for(x = 0; x < 5; x++)
if(map[y + my][x + mx] && box[y][x])
return 0;
return 1;
}
int rotate() {
int x, y;
int newbox[5][5];
rotateBox(curbox, newbox);
if(test(curx, cury, newbox)) {
for(y = 0; y < 5; y++)
for(x = 0; x < 5; x++)
curbox[y][x] = newbox[y][x];
return 1;
}
else return 0;
}
int newfall() {
int x, y;
curx = MAX_X / 2 - 2;
cury = 0;
for(y = 0; y < 5; y++)
for(x = 0; x < 5; x++)
curbox[y][x] = nextbox[y][x];
rebuidNext();
return test(curx, cury, curbox);
}
int main() {
char key;
int i;
int gd = VGA, gm = VGAMED;
Timer *ptDown;
Timer trender;
setTimer(&trender, 1, 1);
initgraph(&gd, &gm, "");
newGame();
while(1) {
if(kbhit()) {
key = getch();
}
else key = 0;
switch(key) {
case KEY_UP:
rotate();
break;
case KEY_DOWN:
ptDown = &tFast;
break;
case KEY_LEFT:
move(0);
break;
case KEY_RIGHT:
move(1);
break;
case KEY_ESC:
closegraph();
exit(0);
default:
ptDown = &tDown;
}
if(testTimer(ptDown)) {
if(!drop()) {
putBox();
clear();
if(!newfall()) {
closegraph();
exit(0);
}
}
}
if(testTimer(&trender))
render();
}
}。
我在Turbo C 中运行是它总说我语法错误。可是我就是不知道错在哪。请帮忙运行一下,帮我看看哪错了,本人不甚感激!!!!谢谢!
全部回答
- 1楼网友:雾月
- 2021-03-16 13:28
没看到你的问题追问问题还没问完呢,接下一个回答.......追答如果是语法错误,你根本不用把代码贴出来,直接把问题提出来即可,根据你的这种风格,我推断你说的语法错误,很可能是因为你拷贝导致的空格问题引起的,你看下是不是有些空格不是程序里面需要的。如果不是你贴错误提示吧。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯