?? c語(yǔ)言寫(xiě)的《泡泡堂》游戲.txt
字號(hào):
#include <stdio.h>
#include <stdlib.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <alloc.h>
#define TIME_DELAY 3/* 人物移動(dòng)的延時(shí)*/
#define WIN_DELAY 18
#define MAXQSIZE 100
#define PAO_TIME 50 /*放泡泡后,等待泡泡爆炸的時(shí)間*/
#define BLAST_TIME 10 /*爆炸消失的時(shí)間*/
#define PAOMAN_DELAY 60 /* 人被炸后恢復(fù)需要的時(shí)間 */
/* 鍵盤(pán)中斷函數(shù)(借用一個(gè)TC做的CS游戲中的) */
#define KEY_Y 0x15
#define KEY_N 0x31
#define KEY_A 0x1E
#define KEY_D 0x20
#define KEY_S 0x1f
#define KEY_W 0x11
#define KEY_ESC 0x01
#define KEY_ENTER 0x1c
#define KEY_SPACE 0x39
#define KEY_UP 0x48
#define KEY_LEFT 0x4b
#define KEY_RIGHT 0x4d
#define KEY_DOWN 0x50
#define PLAY1UP KEY_W
#define PLAY1LEFT KEY_A
#define PLAY1DOWN KEY_S
#define PLAY1RIGHT KEY_D
#define PLAY1FIRE KEY_SPACE
#define PLAY2UP KEY_UP
#define PLAY2DOWN KEY_DOWN
#define PLAY2LEFT KEY_LEFT
#define PLAY2RIGHT KEY_RIGHT
#define PLAY2FIRE KEY_ENTER
void InstallKeyboard(void);
void ShutDownKeyboard(void);
void far interrupt NewInt9(void);
int GetKey(int ScanCode);
char key_state[128],key_pressed[128];
void interrupt far (*OldInt9Handler)();
void InstallKeyboard(void) /*鍵盤(pán)中斷程序*/
{
int i;
for(i=0;i<128;i++)
key_state=key_pressed=0;
OldInt9Handler = getvect(9); /*中斷向量值*/
setvect(9,NewInt9); /*中斷程序NewInt9地址存入指定的中斷向量表中INT 09H*/
}
void ShutDownKeyboard(void)
{
setvect(9,OldInt9Handler);
}
void far interrupt NewInt9(void)
{
unsigned char ScanCode,temp;
ScanCode=inportb(0x60);
temp=inportb(0x61);
outportb(0x61,temp | 0x80);
outportb(0x61,temp & 0x7f);
if(ScanCode&0x80)
{
ScanCode&=0x7f;
key_state[ScanCode]=0;
}
else
{
key_state[ScanCode]=1;
key_pressed[ScanCode]=1;
}
outportb(0x20,0x20);
}
int GetKey(int ScanCode)
{
int res;
res=key_state[ScanCode]|key_pressed[ScanCode];
key_pressed[ScanCode]=0;
return res;
}
/*>>>>>>>>>>>> Man function -- copyright Wonderful and
WangChengBo <<<<<<<<<<<<<*/
typedef enum
{
PLAY1=1, PLAY2
}which_play;
typedef enum
{
CAN,
CANNOT
}MOVE;
typedef struct
{
int x, y; /*the position of the man */
which_play which; /* play1 or play2?*/
MOVE can_move; /* can man move? */
int len; /*paopao's length*/
int pao_num; /* how many pao can the man fire?*/
int old_time; /* 人被泡泡炸后,恢復(fù)的時(shí)間 */
}man;
/*畫(huà)人函數(shù)*/
DrawMan(man m)
{
gotoxy(m.x+15, m.y+6);
if (m.which == PLAY1)
{
textcolor(YELLOW);
}
else
{
textcolor(LIGHTRED);
}
putch(2);
}
/*畫(huà)空心的人的函數(shù)*/
DrawPaoMan(man m)
{
gotoxy(m.x+15, m.y+6);
if (m.which == PLAY1)
{
textcolor(YELLOW);
}
else
{
textcolor(LIGHTRED);
}
putch(1);
}
/*擦除人的函數(shù)*/
EraseMan(man m)
{
gotoxy(m.x+15, m.y+6);
textcolor(BLACK);
putch(' ');
}
/*畫(huà)泡泡的函數(shù)*/
DrawPao(int x, int y)
{
gotoxy(x+15, y+6);
textcolor(LIGHTBLUE);
putch('O');
}
/*畫(huà)爆炸的#號(hào)的函數(shù)*/
DrawBlast1(int x, int y)
{
gotoxy(x+15, y+6);
textcolor(LIGHTBLUE);
putch('#');
}
/*游戲開(kāi)頭顯示的字符*/
char name[8][26] =
{
" O O O O ",
" O OOOOOO O OOOOOO",
" OOO O OOO O",
" O O O O O O O O",
" O OOO O O OOO O",
" O OO O OO",
" O O O O O O",
"O OOOOOO O OOOOOO"
};
int Name_X = 26;
int Name_Y = 8;
void DrawBegin()
{
int x, y;
for (y=0; y<Name_Y; ++y)
{
for(x=0; x<Name_X; ++x)
{
gotoxy(x+21, y+5);
textcolor(LIGHTBLUE);
putch(name[y][x]);
}
}
gotoxy(19, 20);
printf("Press any key to Enter the game!");
}
/*游戲地圖,#為墻壁,@為箱子,試著自己改改*/
char map1[8][17] =
{"#################",
"# @@@@ @ #@# ##",
"# #@#@#@ @@@ #",
"# @@@ @@ #@#@##",
"#@#@#@#@ @@@@@@#",
"#@@@@@ @@#@#@##",
"#@#@#@#@@ @@@@@#",
"#################"};
int Map_X = 17;
int Map_Y = 8;
char map[8][17];
void DrawMap()
{
int x, y;
for (y=0; y<Map_Y; ++y)
{
for(x=0; x<Map_X; ++x)
{
gotoxy(x+15, y+6);
if(map[y][x] == '#')
{
textcolor(GREEN);
putch(219);
}
else if(map[y][x] == '@')
{
textcolor(BROWN);
putch(178);
}
else
putch(' ');
}
}
textcolor(BLUE);
gotoxy(48, 4);
printf("Player1 key:");
gotoxy(48, 5);
printf(" UP----w");
gotoxy(48, 6);
printf(" DOWN--s");
gotoxy(48, 7);
printf(" LEFT--a");
gotoxy(48, 8);
printf(" RIGHT-d");
gotoxy(48, 9);
printf(" FIRE--space");
gotoxy(48, 11);
printf("Player2 key:");
gotoxy(48, 12);
printf(" UP----up");
gotoxy(48, 13);
printf(" DOWN--down");
gotoxy(48, 14);
printf(" LEFT--left");
gotoxy(48, 15);
printf(" RIGHT-right");
gotoxy(48, 16);
printf(" FIRE--ENTER");
gotoxy(48, 18);
printf("exit game:");
gotoxy(48, 19);
printf(" ESC");
gotoxy(38, 2);
textcolor(LIGHTRED);
putch('P');
putch('A');
putch('O');
putch('P');
putch('A');
putch('O');
}
/*炸箱子后,出寶物的函數(shù)*/
Treasure(int x, int y)
{
int i;
i = random(15);
if (i > 10)
{
switch (i)
{
case 11:
case 12:
map[y][x] = 'O';
gotoxy(x+15, y+6);
textcolor(YELLOW);
putch('o');
break;
case 13:
case 14:
map[y][x] = '-';
gotoxy(x+15, y+6);
textcolor(YELLOW);
putch(18);
break;
default:
break;
}
}
else
{
map[y][x] = ' ';
gotoxy(x+15, y+6);
putch(' ');
}
}
/*人物m向上移動(dòng)的函數(shù)*/
int MoveUp(man *m, man *p)
{
if (map[m->y - 1][m->x] == '#' || map[m->y - 1][m->x] == '@'
|| map[m->y - 1][m->x] == 'o' || m->can_move == CANNOT)
{
return 1;
}
EraseMan(*m);
if (map[m->y][m->x] == 'o')
{
DrawPao(m->x, m->y);
}
--(m->y);
DrawMan(*m);
switch (map[m->y][m->x])
{
case 'a':
case 'b':
m->can_move = CANNOT;
m->old_time = clock();
break;
case 'O':
++(m->pao_num);
map[m->y][m->x] = ' ';
break;
case '-':
++(m->len);
map[m->y][m->x] = ' ';
break;
default:
break;
}
if (m->x == p->x && m->y == p->y && p->can_move == CANNOT)
{
gotoxy(36, 3);
printf("Play%d Win!!", m->which);
return 0;
}
return 1;
}
/*人物m向下移動(dòng)的函數(shù)*/
int MoveDown(man *m, man *p)
{
if (map[m->y + 1][m->x] == '#' || map[m->y + 1][m->x] == '@'
|| map[m->y + 1][m->x] == 'o' || m->can_move == CANNOT)
{
return 1;
}
EraseMan(*m);
if (map[m->y][m->x] == 'o')
{
DrawPao(m->x, m->y);
}
++(m->y);
DrawMan(*m);
switch (map[m->y][m->x])
{
case 'a':
case 'b':
m->can_move = CANNOT;
m->old_time = clock();
break;
case 'O':
++(m->pao_num);
map[m->y][m->x] = ' ';
break;
case '-':
++(m->len);
map[m->y][m->x] = ' ';
break;
default:
break;
}
if (m->x == p->x && m->y == p->y && p->can_move == CANNOT)
{
gotoxy(36, 3);
printf("Play%d Win!!", m->which);
return 0;
}
return 1;
}
/*人物m向左移動(dòng)的函數(shù)*/
int MoveLeft(man *m, man *p)
{
if (map[m->y][m->x - 1] == '#' || map[m->y][m->x - 1] == '@'
|| map[m->y][m->x - 1] == 'o' || m->can_move == CANNOT)
{
return 1;
}
EraseMan(*m);
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -