(100分)策划 俄罗斯方块 完整的游戏过程 (可以的话还加50分,谢谢)
答案:6 悬赏:30 手机版
解决时间 2021-02-23 01:26
- 提问者网友:你挡着我发光了
- 2021-02-22 22:21
(100分)策划 俄罗斯方块 完整的游戏过程 (可以的话还加50分,谢谢)
最佳答案
- 五星知识达人网友:山河有幸埋战骨
- 2021-02-22 22:48
网上下载的CSDN里面的代码^^^
分享…………
我用TC调试成功了
因为头文件里有 所以不能在VC中运行
#include
#include
#include
#include
#include
#define MAX_X 14
#define MAX_Y 21
#define MAX_C 7
#define KEY_UP 'w'
#define KEY_DOWN 's'
#define KEY_LEFT 'a'
#define KEY_RIGHT 'd'
#define KEY_ESC 27
typedef int BOOL;
#define FALSE 0
#define TRUE 1
typedef struct {
BOOL enabled;
unsigned int intervel;
unsigned int lasttime;
} Timer;
int GetTickCount();
int setTimer(Timer *t, unsigned int intv, BOOL en);
BOOL testTimer(Timer *t);
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 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
Timer tDown;
Timer tFast;
#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();
}
}
分享…………
我用TC调试成功了
因为头文件里有
#include
#include
#include
#include
#include
#define MAX_X 14
#define MAX_Y 21
#define MAX_C 7
#define KEY_UP 'w'
#define KEY_DOWN 's'
#define KEY_LEFT 'a'
#define KEY_RIGHT 'd'
#define KEY_ESC 27
typedef int BOOL;
#define FALSE 0
#define TRUE 1
typedef struct {
BOOL enabled;
unsigned int intervel;
unsigned int lasttime;
} Timer;
int GetTickCount();
int setTimer(Timer *t, unsigned int intv, BOOL en);
BOOL testTimer(Timer *t);
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 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
Timer tDown;
Timer tFast;
#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();
}
}
全部回答
- 1楼网友:夜余生
- 2021-02-23 04:10
你的要求真多
- 2楼网友:执傲
- 2021-02-23 03:17
问下应聘用还是别的~~我写过这方面的策划案
- 3楼网友:封刀令
- 2021-02-23 01:54
好难哦!
- 4楼网友:不甚了了
- 2021-02-23 01:21
二楼 你忒牛咯!!!
- 5楼网友:过活
- 2021-02-23 00:02
100分就想买?你白日梦型的?这种设计一般是人名币算的
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯