当前位置: 代码迷 >> C语言 >> [原创]我用C写的类似劲舞团的东西(有点烂)
  详细解决方案

[原创]我用C写的类似劲舞团的东西(有点烂)

热度:354   发布时间:2006-04-29 21:21:00.0
[原创]我用C写的类似劲舞团的东西(有点烂)

主要为了检验一下自己!写的不好,希望大家指证呀!
#include<graphics.h> //图形库
#include<stdio.h>
#include<dos.h>
#include<bios.h>
#include<conio.h>
#include<stdlib.h>

#define up 72
#define left 75
#define right 77
#define enter 2
#define down 80
#define esc 1
#define space 57

void init_graph(); //初始化图形系统
void init(); //初始界面的绘制
int getkey(); //获取键盘动作
void drawbox(int total); //画圆圈箭头
void makebox(int total); //产生圆圈箭头(total为产生的个数)
void clearbox(); //消去界面上的圆圈
int timecome(); //定时
int testbox(int test); //测试你按的方向是否和界面上的相同
int timeout(); //总时间
void drawbar(); //绘制时间条
int timecome1(); //在TIMEOUT()函数中用到的时间函数
void clearbar(); //消去时间条
void outnum(int x,int y,int num); //输出数字用的函数
void scoretest(); //根据你完成的时间决定分数
void andyss(); //个人标识

int a[4][12];
int direct,b,c,temp,total=3,m[7],t,flag=1,score=0,i=0;
a[4][12]={{4,10,16,10,13,4,16,10,13,16,16,10},
{4,10,16,10,7,4,4,10,7,16,4,10},
{10,4,10,16,4,13,10,16,16,13,10,16},
{10,4,10,16,4,7,10,4,16,7,10,4}};
m[7]={0,0,0,0,0,0,0};


void init_graph(){
int gdrive=9,gmode=2,errorcode;
int i,j,flag,k,m,key;
initgraph(&gdrive,&gmode,"c:\\tc");
errorcode=graphresult();
if(errorcode!=0)
{printf("the graph error:%s",grapherrormsg(errorcode));
printf("press any key to halt");
getch();
exit(1);
}
}

void init(){
cleardevice();
andyss();
setbkcolor(GREEN);
setcolor(RED);
rectangle(200,40,400,440);
rectangle(300,260,400,280);
setfillstyle(1,4);
bar(375,260,385,280);
setfillstyle(1,6);
bar(201,150,399,300);
outtextxy(210,180,"would you like to ");
outtextxy(210,190," play the game?");
outtextxy(210,200," 'y' to start game");
outtextxy(210,210," 'n' to exit game");
c=getche();
if(c=='y'||c=='Y'){ i=1;
setfillstyle(1,2);
bar(201,150,399,300);}
else if(c=='n'||c=='N') i=0;
}

void outnum(int x,int y,int num){
char string[8];
itoa(num,string,10);
setcolor(RED);
outtextxy(x,y,string);
}

void scoretest(){
setcolor(RED);
if(b<75&&direct==total){
outtextxy(420,260,"very good!");
score=score+1000;
}
else if(b>=75&&b<=85&&direct==total){
outtextxy(420,260,"perfict");
score=score+1500;
}
else if(b>85&&b<100&&direct==total){
outtextxy(420,260,"bad");
score=score+500;
}
else outtextxy(420,260,"miss!");
}

int getkey(){
union REGS rg;
rg.h.ah=0;
int86(0x16,&rg,&rg);
return rg.h.ah;
}

void drawbox(int total){
int i;
temp=300-total*10;
for(i=0;i<total;i++){
circle(temp+10,310,10);
line(a[m[i]][0]+temp,a[m[i]][1]+300,a[m[i]][2]+temp,a[m[i]][3]+300);
line(a[m[i]][4]+temp,a[m[i]][5]+300,a[m[i]][6]+temp,a[m[i]][7]+300);
line(a[m[i]][8]+temp,a[m[i]][9]+300,a[m[i]][10]+temp,a[m[i]][11]+300);
temp=temp+20;
}
temp=300-total*10;
}

void makebox(int total){
int i;
for(i=0;i<total;i++){
m[i]=rand()%4;
}
setcolor(WHITE);
drawbox(total);
}

void clearbox(){
setfillstyle(1,2);
bar(201,300,399,340);
}

int timecome(){
static long tm,old;
tm=biostime(0,tm);
if(tm-old<1) return(0);
else{ old=tm;
return(1);
}
}
int timecome1(){
static long tm,old;
tm=biostime(0,tm);
if(tm-old<50) return(0);
else{ old=tm;return(1); }
}
int timecome2(){
static long tm,old;
tm=biostime(0,tm);
if(tm-old<25) return(0);
else{ old=tm;return(1);}
}

int testbox(int test){
if(m[direct]==test){
setcolor(RED);
circle(temp+10+20*direct,310,10);
line(a[m[direct]][0]+temp+20*direct,a[m[direct]][1]+300,a[m[direct]][2]+temp+20*direct,a[m[direct]][3]+300);
line(a[m[direct]][4]+temp+20*direct,a[m[direct]][5]+300,a[m[direct]][6]+temp+20*direct,a[m[direct]][7]+300);
line(a[m[direct]][8]+temp+20*direct,a[m[direct]][9]+300,a[m[direct]][10]+temp+20*direct,a[m[direct]][11]+300);
return(1);
}
else return(0);
}

int timeout(){
int j;
outtextxy(410,400,"time:");
j=timecome2();
if(j){
setfillstyle(1,2);
bar(450,400,480,420);
t--;
}
outnum(450,400,t);
return(t);
}

void drawbar(){
setfillstyle(1,15);
bar(300,260,300+b,280);
if(timecome()&&flag) b=b+2;
if(b>=100){
clearbar();
b=0;
}
}
void clearbar(){
setfillstyle(1,2);
bar(301,261,399,279);
bar(420,260,600,400);
setcolor(WHITE);
rectangle(300,260,400,280);
setfillstyle(1,4);
bar(375,260,385,280);
}

void andyss(){
outtextxy(0,200,"wrote by andyss in cqupt.");
outtextxy(0,220,"QQ:274839490");
outtextxy(0,240,"mail:ssvfhp21@163.com");
}

void gameover(){
setfillstyle(1,6);
bar(201,150,399,300);
outtextxy(210,180,"Gameover! Woule you");
outtextxy(210,190," like to continu?");
outtextxy(210,200," 'y' to restart game");
outtextxy(210,210," 'n' to exit game");
c=getche();
if(c=='y'||c=='Y'){
i=1;
setfillstyle(1,2);
bar(201,150,399,300);
b=0,c=27,direct=0,t=60,total=3,score=0;
clearbox();
makebox(3);
}
else if(c=='n'||c=='N') i=0;
}

void main(){
int key,test;
b=0,c=27,direct=0,t=60,total=3,score=0,i=1;
temp=300-total*10;
init_graph();
init();
while(i){
outnum(420,300,score);
test=timeout();
if(test==0){
gameover();
}
if(c<0) exit(0);
if(c<9&&c>0){
total=4;
if(c==8) total=7;
if(timecome1()){
direct=0;
clearbox();
makebox(4);
drawbar();
flag=1;
c--;
}
}
//产生BOX
if(c<12&&c>8){
total=7;
if(c==11) total=6;
if(timecome1()){
direct=0;
clearbox();
makebox(7);
clearbar();
drawbar();
flag=1;
c--;
}
}

if(c<15&&c>11)
{ total=6;
if(c==14) total=5;
if(timecome1()){
clearbox();
makebox(6);
direct=0;
clearbar();
drawbar();
flag=1;
c--;
}
}

if(c<19&&c>14){
total=5;
if(c==18) total=4;
if(timecome1()){
clearbox();
direct=0;
makebox(5);
clearbar();
drawbar();
flag=1;
c--;
}
}


if(c<24&&c>18){
total=4;
if(c==23) total=3;
if(timecome1()){
clearbox();
direct=0;
makebox(4);
clearbar();
drawbar();
flag=1;
c--;
}
}

if(c>23){
total=3;
if(timecome1()){
clearbox();
direct=0;
makebox(3);
clearbar();
drawbar();
flag=1;
c--;
}
}
drawbar();
if(bioskey(1)!=0)//获取键盘动作
{key=getkey();
switch(key)
{case left: if(testbox(1)) direct++;
else{ direct=0;
setcolor(WHITE);
drawbox(total); }
break;
case right:if(testbox(0)) direct++;
else{ direct=0;
setcolor(WHITE);
drawbox(total); }
break;
case up: if(testbox(3)) direct++;
else{ direct=0;
setcolor(WHITE);
drawbox(total); }
break;
case esc:exit(0);
case down: if(testbox(2)) direct++;
else{ direct=0;
setcolor(WHITE);
drawbox(total); }
break;
case space: clearbar();
scoretest();
flag=0;
b=0;
break;
default :break;
}
}

}

closegraph();
}


[此贴子已经被作者于2006-5-3 23:53:04编辑过]

搜索更多相关的解决方案: 劲舞团  define  include  void  图形  

----------------解决方案--------------------------------------------------------
劲舞团


是什么啊!我没玩过游戏,说说好玩不

----------------解决方案--------------------------------------------------------
挺强的!
----------------解决方案--------------------------------------------------------

高人,佩服!


----------------解决方案--------------------------------------------------------
谢谢哈!程序设计还是有点不好,在时间延迟方面不怎么好!
还有界面不怎么好看.
----------------解决方案--------------------------------------------------------

打不开呀
看看
Turbo C For Windows 3.0 正在编译....
f:\edt~1\kankan1.c:
正在汇编文件: kankan1.ASM
出错信息: 无
警告信息: 无
通过: 1
剩余内存: 209k
未定义的符号 '_initgraph' in module f:\edt~1\kankan1.c
未定义的符号 '_graphresult' in module f:\edt~1\kankan1.c
未定义的符号 '_grapherrormsg' in module f:\edt~1\kankan1.c
未定义的符号 '_cleardevice' in module f:\edt~1\kankan1.c
未定义的符号 '_setbkcolor' in module f:\edt~1\kankan1.c
未定义的符号 '_setcolor' in module f:\edt~1\kankan1.c
未定义的符号 '_rectangle' in module f:\edt~1\kankan1.c
未定义的符号 '_setfillstyle' in module f:\edt~1\kankan1.c
未定义的符号 '_bar' in module f:\edt~1\kankan1.c
未定义的符号 '_outtextxy' in module f:\edt~1\kankan1.c
未定义的符号 '_circle' in module f:\edt~1\kankan1.c
未定义的符号 '_line' in module f:\edt~1\kankan1.c
未定义的符号 '_closegraph' in module f:\edt~1\kankan1.c


可用内存 339372


----------------解决方案--------------------------------------------------------
强啊楼主,居然能写出劲舞团的游戏来
厉害啊最好 再写个劲乐团来
嘿嘿
----------------解决方案--------------------------------------------------------

你这个比较有意思~哈哈 不过TC 的做出来图确实不好看


----------------解决方案--------------------------------------------------------
牛B
----------------解决方案--------------------------------------------------------
确认是原创的话就加精华阿
我是看不了的了
没DOS/WINDOWS操作系统

----------------解决方案--------------------------------------------------------
  相关解决方案