应天论坛

 找回密码
 参与我们

QQ登录

只需一步,快速开始

搜索
查看: 950|回复: 0

用C写的类似劲舞团的东西

[复制链接]

68

主题

72

帖子

451

积分

少校

勘查大队长

Rank: 6Rank: 6

积分
451
发表于 2017-4-29 21:44:42 | 显示全部楼层 |阅读模式
用C写的类似劲舞团的东西

[mw_shl_code=c,true]#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][0]+temp,a[m][1]+300,a[m][2]+temp,a[m][3]+300);
line(a[m][4]+temp,a[m][5]+300,a[m][6]+temp,a[m][7]+300);
line(a[m][8]+temp,a[m][9]+300,a[m][10]+temp,a[m][11]+300);
temp=temp+20;
}
temp=300-total*10;
}

void makebox(int total){
int i;
for(i=0;i<total;i++){
m=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();
}[/mw_shl_code]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 参与我们

本版积分规则

QQ|Archiver|手机版|小黑屋|应天社区 ( 湘ICP备17015224号 )

GMT+8, 2024-12-22 18:10 , Processed in 0.062500 second(s), 26 queries .

Powered by Discuz!

© 2001-2017 Comsenz Inc.


免责声明:
本站所发布的第三方软件及资源(包括但不仅限于文字/图片/音频/视频等仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢某程序或某个资源,请支持正版软件及版权方利益,注册或购买,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To: admin@yzqz.cn

快速回复 返回顶部 返回列表