c打字游戏课程设计
1. 急!!!求C语言课程设计之打字游戏代码!
给你个.因分少就不改动了,
这个是给别的朋友定过的.
只有练习数字和字母.而且可以调速度,并配着简单的动画哦.如觉得好要加功能, 加我网络好友,再加分.哈哈.
#include<time.h>
#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
#define R 10
#define ESC 0x011b
#define LOW 0x5000
#define FAST 0x4800
int draw_car(int x,int y,char *ch);
double dalta=20,angle;
void *image;
int step=20;
main()
{
int gdriver=DETECT,gmode;
static int startx=60;
static int starty=20;
int maxy,maxx,l=1,n=1;
char ch,play, str[2];
int size,temch;
int ok,y=50;
clrscr();
printf("\n\n\n\n\n*****************************************\n");
printf(" 1.play only number 0-9 .\n");
printf(" 2.play only char a-z .\n");
printf(" 3.exit\n");
printf("*****************************************\n");
while(1){
printf("\nPls enter choice:");
play=getche();
if((play=='1')||(play=='2'))
break;
if(play=='3')
return;
}
registerbgidriver( EGAVGA_driver ); /*注册vga驱动*/
initgraph(&gdriver,&gmode,"d:\\tc3\\bgi"); /*初始化图形界面*/
cleardevice(); /*清除屏幕*/
setbkcolor(BLUE); /*将背景色设置成蓝色*/
size=imagesize(startx,starty,startx+60,starty+60); /*计算生成60×60个象素的图需要的字节数*/
image=(unsigned char *)malloc(size); /*分配内存*/
maxx=getmaxx();
maxy=getmaxy();
randomize();
printf("Press ESC to exit game! ");
printf(" %c to fast speed,%c to low speed!",24,25);
do{
ok=0;
if(play=='1')
ch=random(9)+48;
if(play=='2')
ch=random(26)+65;
str[0]=ch;
do{
while(bioskey(1)==0) /*如果没有按键就不停的循环*/
{
if(l==1) /*从左到右*/
{
n++;
angle=-1*(n*step)/M_PI*180/R;
if((int)(-1*angle)%360<dalta)
angle-=dalta;
if(n>(maxx-180)/step){
if(starty>maxy-100)
starty=20;
else
starty+=y;
l=0;
}
}
if(l==0) /*从右到左*/
{
--n;
angle=-1*(n*step)/R/M_PI*180;
if((int)(-1*angle)%360<dalta)
angle-=dalta;
if(n==1){
if(starty>maxy-100)
starty=20;
else
starty+=y;
l=1;
}
}
draw_car(startx+n*step,starty,str);
}
temch=bioskey(0);
if(temch==FAST){
step+=10;
y+=10;
}
if(temch==LOW){
step-=10;
y-=10;
}
ok=temch&0x00ff;
if((ok==ch)||(ok==ch+32)){
ok=1;
starty=20;
break;
}
}while(temch!=ESC);
if(ok!=1)
break;
}while(1);
free(image);
closegraph();
return;
}
int draw_car(int x,int y,char *ch){
setcolor(YELLOW); /*设置前景色为黄色*/
rectangle(x,y,x+60,y+40); /*画车厢*/
pieslice(x+15,y+50,angle,angle-dalta,10); /*画轮上的小片扇形部分*/
pieslice(x+45,y+50,angle,angle-dalta,10);
setfillstyle(SOLID_FILL, YELLOW); /*设置填充模式为实填充,颜色为黄色*/
circle(x+15,y+50,10); /*画车轮*/
circle(x+45,y+50,10);
circle(x+15,y+50,3);
circle(x+45,y+50,3);
setcolor(WHITE);
settextstyle(1,0,4);
outtextxy(x+25,y,ch);
getimage(x,y,x+60,y+60,image); /*获取当前的图片*/
delay(200);
putimage(x,y,image,XOR_PUT); /*使用异或模式将图片显示上去*/
return;
}
2. C++编一个打字游戏
分太少了,懒得写,给你第二个提示,监听键盘按下事件,判断按键是否与界面中正在落的字符一样。
第三个提示:全局变量统计总字数,打掉的字数,错过的字数。
3. c语言打字游戏
想到了小霸王学习机,呵呵.
4. C++有个简单的课程设计是打字游戏
#include<iostream>
#include<conio.h>
#include<time.h>
usingnamespacestd;
intmain()
{
cout<<"打字游戏"<<endl;
cout<<"按1开始游戏,按0结束游戏"<<endl;
intgo;
cin>>go;
if(go==1)
{
clock_tstart,finish;
system("color3");
chars[100]={"howareyou"};
cout<<s<<endl;
start=clock();//游戏开始时间
charch;
inti=0;
while(i<11)
{
ch=getch();
if(ch==s[i])
{
cout<<ch;
system("color4");
i++;
}
else
{
cout<<'a';//响铃提示输入错误
}
}
finish=clock();//游戏结束时间
cout<<endl;
inttime=finish-start;
system("color5");
cout<<"游戏结束"<<endl;
cout<<"用时"<<time<<"毫秒"<<endl;
}
else
if(go==0)
{
cout<<"谢谢"<<endl;
}
return0;
}
5. c语言打字游戏
#include<stdio.h>
#include<stdlib.h>
main()
{
int i;
int line=0,col=0,num=0;
int score=0,times=1;
char one[26];
char c;
for(i=0,c='a';i<26;i++,c++) /* 把a~z赋给数组 */
{
one[i]=c;
}
center();
printf("press anykey to start");
getch();
while(1)
{ system("cls");
printf("times:%d ",times); /* 打印关数 */
printf(" score: %d",score); /* 打印分数 */
printf(" 1----Pause,0----exit");
printf("\n");
printf("________________________________________________________________________");
printf("\n");
line=0;
randomize();
col=random(60);
randomize();
num=random(26);
while(1) /* 开始下落 */
{
space(col);
printf("%c",one[num]); /* 打印出字母 */
delay_x(10-times);
printf("\b \n");
line++;
if(line>45)
{
score-=10;
break;
}
if(score<0)
{
center();
printf("sorry,you faile!");
getch();
exit(0);
}
if(kbhit()) /* 如果有键按下 */
{
c=getch(); /* 接收输入的字符 */
if(c==one[num])
{
score+=10;
break;
}
switch(c)
{
case '0': exit(0);
case '1': getch();
default : ;
}
}
}
if(score>=100*times) /* 一关完毕 */
{
times++;
center();
if(times>9)
{
printf("congratulation,you win!");
}
printf("If you go to the %d:(y/n)",times);
if((getch())=='n')
{
center();
printf("I am sorry for you give up!");
getch();
break;
}
}
} /* end of while */
} /* end of main */
/*************************** 定义换行函数 *********************************/
change_line(int k)
{ int i;
for(i=0;i<k;i++)
{
printf("\n");
}
}
/**************************** 打印空格函数 ********************************/
space(int k)
{ int i;
for(i=0;i<k;i++)
{
printf(" ");
}
}
/************************** 延时函数 ************************************/
delay_x(int k)
{
int i;
for(i=0;i<k;i++)
{
delay(5000);
}
}
/******************* 让光标居中(偏左)函数 ************************/
center()
{
system("cls");
change_line(20);
space(25);
}
6. c语言课程设计打字测验
课程抄计划,体现国家对学校的统一要求是编写,哥哥。课程标准和教材的主要依据,课程标准是课程计划的分科分,学科展开,每门科学都对应的,课程标准,教材是课程标准的,具体化。课程标准中规定的各门学科,一般都有相应的教材。
7. 课程设计之打字游戏(c语言或c++),要详细的实验报告
分少就算了,还只有一句话。
你要的是怎样的打字游戏呢?
8. 求纯C语言打字游戏源代码及解析
# include "Typer.h"
# include <stdio.h>
# include <stdlib.h>
# include <graphics.h>
//download by http://www.codefans.net
void main()
{
BOOL bQuit=FALSE; /* 是否退出 */
BOOL bPause=FALSE; /* 是否暂停 */
int tm1,tm2;
BYTE Key;
randomize(); /* 初始化随机数种子 */
SetGraphMode();
SelectLevel();
ShowBar();
tm1=CreateTimer(1,MoveLetter); /* 创建移动字符对象时钟 */
tm2=CreateTimer(Interval,CreateLetter); /* 创建产生字符对象时钟 */
CreateLetter();
Key=AscKey();
while (!bQuit)
{
TimerEvent();
switch (Key)
{
case NULL:
break;
case KEY_ESC:
bQuit=TRUE;
break;
case KEY_SPACE:
bPause=!bPause;
tmTM[tm1].Enable=!bPause;
tmTM[tm2].Enable=!bPause;
break;
default:
if (!bPause) Check(Key);
}
Key=AscKey();
}
CloseGraphMode();
}
void SetGraphMode()
{
int Device=VGA,Mode=VGAHI;
initgraph(&Device,&Mode,"");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,1);
setfillstyle(SOLID_FILL,0);
setcolor(7);
}
void CloseGraphMode()
{
restorecrtmode();
}
/* 从键盘缓冲区内直接读出ASC码 */
BYTE AscKey(void)
{
int start,end;
WORD key=0;
start=peek(0,0x41a);
end=peek(0,0x41c);
if (start==end) return(0);
else
{
key=peek(0x40,start);
start+=2;
if (start==0x3e) start=0x1e;
poke(0x40,0x1a,start);
return(key&0xff);
}
}
void MoveLetter(void)
{
int i;
for (i=0;i<MAX_LETTER;i++)
{
if (Letter[i].Used)
{
HideLetter(i);
Letter[i].y+=Step;
ShowLetter(i);
/* 字符对象下落到最底部 */
if (Letter[i].y>MAX_HEIGHT) KillLetter(i);
}
}
}
void KillLetter(int LetterID)
{
if (Letter[LetterID].Used)
{
Letter[LetterID].Used=FALSE;
LetterUsed--;
HideLetter(LetterID);
}
/* 删除字符对象后马上再创建一个 */
CreateLetter();
}
void CreateLetter()
{
int i=0;
int x;
BYTE val;
if (LetterUsed==MAX_LETTER) return; /* 无字符对象可用则返回 */
while (Letter[++i].Used); /* 找到第一个空闲的字符对象,产生一个字符对象 */
x=i;
Letter[i].x=x*640/MAX_LETTER;
Letter[i].y=0;
Letter[i].val=random(26)+'A';
Letter[i].Used=TRUE;
LetterUsed++;
}
void HideLetter(int ID)
{
/* 用填充矩形来消隐字符 */
bar(Letter[ID].x,Letter[ID].y,Letter[ID].x+16,Letter[ID].y+20);
}
void ShowLetter(int ID)
{
char str[2]={0,0};
str[0]=Letter[ID].val;
outtextxy(Letter[ID].x,Letter[ID].y,str);
}
void Check(BYTE Key)
{
int i;
char str[6];
Hits++;
for (i=0;i<MAX_LETTER;i++)
/* 击中 */
if (Letter[i].Used&&Letter[i].val==toupper(Key))
{
sound(1000);
delay(10);
KillLetter(i);
Right++;
nosound();
}
/* 显示状态 */
setfillstyle(SOLID_FILL,5);
bar(260,430,320,450);
bar(410,430,470,450);
setcolor(2);
sprintf(str," %4ld",Hits);
outtextxy(260,430,str);
sprintf(str," %4ld",Right);
outtextxy(410,430,str);
setcolor(7);
setfillstyle(SOLID_FILL,0);
}
void ShowBar()
{
FILE *bmp;
BYTE r,g,b,t;
int i,x,y;
bmp=fopen("bar.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i<16;i++)
{
setpalette(i,i);
b=fgetc(bmp)>>2;
g=fgetc(bmp)>>2;
r=fgetc(bmp)>>2;
t=fgetc(bmp)>>2;
setrgbpalette(i,r,g,b);
}
for (y=0;y<80;y++)
for (x=0;x<320;x++)
{
t=fgetc(bmp);
putpixel(x*2,479-y,t>>4);
putpixel(x*2+1,479-y,t&15);
}
fclose(bmp);
}
void SelectLevel()
{
int Steps[3]={1,2,4};
int Intervals[3]={18,9,5};
int Sel=0;
FILE *bmp;
BYTE r,g,b,t,Key;
int i,x,y;
bmp=fopen("sel.bmp","rb");
fseek(bmp,54,SEEK_SET);
for (i=0;i<16;i++)
{
setpalette(i,i);
b=fgetc(bmp)>>2;
g=fgetc(bmp)>>2;
r=fgetc(bmp)>>2;
t=fgetc(bmp)>>2;
setrgbpalette(i,r,g,b);
}
for (y=0;y<200;y++)
for (x=0;x<160;x++)
{
t=fgetc(bmp);
putpixel(x*2+160,339-y,t>>4);
putpixel(x*2+161,339-y,t&15);
}
fclose(bmp);
while (TRUE)
{
Key=toupper(AscKey());
if (Key=='A') Sel=1;
if (Key=='B') Sel=2;
if (Key=='C') Sel=3;
if (Sel) break;
}
Step=Steps[Sel-1];
Interval=Intervals[Sel-1];
cleardevice();
}
/*********************************************************/
/* 文件:TIMER.H */
/*********************************************************/
/*********************************************************/
/* 系统可用计时器的最大数目 */
# define MAXTIMER 10
# ifndef NULL
# define NULL 0
# endif
/* 计时器结构 */
struct TM
{
DWORD Interval; /* 间隔 */
DWORD LastTimer; /* 上次事件发生时间*/
BOOL Enable; /* 活动 */
BOOL Used; /* 可用 */
void (*Pointer)(); /* 事件远指针 */
};
struct TM tmTM[MAXTIMER+1];
int TimerUsed=0;
/* 获取BIOS计数器数值 */
DWORD BiosTimer(void)
{
DWORD BIOSTIMER=0;
BIOSTIMER=peek(0x0,0x46e);
BIOSTIMER<<=8;
BIOSTIMER+=peek(0x0,0x46c);
return (BIOSTIMER);
}
/* 时间事件(时钟系统核心) */
void TimerEvent()
{
int i;
DWORD TimerDiff;
for (i=1;i<=MAXTIMER;i++)
{
if (tmTM[i].Used&&tmTM[i].Enable)
{
TimerDiff=BiosTimer()-tmTM[i].LastTimer;
if (tmTM[i].Interval<=TimerDiff)
{
tmTM[i].Pointer();
tmTM[i].LastTimer=BiosTimer();
}
}
}
}
/* 创建一个时钟(成功返回时钟的句柄,否则返回NULL) */
int CreateTimer(DWORD Interval,void (*Pointer)())
{
int i=0;
if (TimerUsed==MAXTIMER) return NULL;
while (tmTM[++i].Used);
tmTM[i].Pointer=Pointer;
tmTM[i].Interval=Interval;
tmTM[i].Enable=TRUE;
tmTM[i].Used=TRUE;
tmTM[i].LastTimer=BiosTimer();
TimerUsed++;
return i;
}
/* 删除一个时钟 */
void KillTimer(int *TimerID)
{
if (tmTM[*TimerID].Used)
{
TimerUsed--;
tmTM[*TimerID].Used=FALSE;
}
*TimerID=0;
}
/* 删除所有时钟 */
void KillAllTimer()
{
int i;
for (i=0;i<=MAXTIMER;i++) tmTM[i].Used=FALSE;
TimerUsed=0;
}
9. c语言课程设计(打字测验平台)
void Type(int num)
{
FILE *fp;
FILE *userfp;
int i,j,k;
char chose;
clock_t c1,c2;
char fname[30];
char read[51];
char type[51];
char error[200];
//char wrong[51];
char etype[200];
float time,percent,speed;
i=0;j=0;k=0;
loop4: printf("\t=============\n");
//printf("\t1.选择课文\n");
printf("\t2.自定义文章\n");
printf("\t3.错误练习\n");
printf("\t=============\n");
chose=getch();
/*if(chose=='1')
{
printf("\n");
printf("\n");
chose=getch();
switch(chose)
{
case '1':
str(fanme,"");
default :
printf("输入错误,重新选择!\n");
goto loop4;
}
}*/
//else
//{
if(chose==2)
{
printf("\n");
for(j=0;j<30;j++)
scanf("%c",fname[j]);
}
else
{
if((fuser=fopen(FUSER,"rb+"))==NULL)
{
printf("用户文件无法打开!\n");
goto end;
}
fseek(fuser,num*SIZE,SEEK_SET);
fread(&A,SIZE,1,fuser);
for(i=0;A.error[i]!='\0';i++)
printf("\tA.error[i]");
for(j=0;j<=i;j++)
scanf("%c",etype[j]);
fclose(fuser);
}
// }
if((fp=(fopen(fname,"r")))==NULL)
{
printf("\n文件打开失败!");
goto end;
}
c1=clock();
while(!feof(fp))
{
fread(&read,sizeof(char),50,fp);
for(i=0;i<50;i++)
{
printf("%c",read[i]);
k++;
}
printf("type this line\n");
for(i=0;i<51;i++)
scanf("%c",type[i]);
type[51]='\0';
for(i=0;i<51;i++)
if(read[i]!=type[i])
{
error[j]=read[i];
j++;
}
}
c2=clock();
percent=(float)(j)/(float)(k);
printf("您的错误率是%f\n",percent);
time=(float)(c2-c1)/CLOCKS_PER_SEC;
printf("您所用时间是%f\n",time);
speed=float(k)/time;
printf("您的打字速度是%4f个/s\n",speed);
if((fuser=fopen(FUSER,"rb+"))==NULL)
{
printf("用户文件无法打开!\n");
goto end;
}
}
10. c语言打字游戏编程vc6.0
Status BeforeElem(LinkList L,ElemType choose,ElemType *before)
{
LinkList q,p = L ->next;
while(p ->next)
{
q = p ->next;
//判断p的后继是否为choose,是的话返回内OK,否则继续后容移
if(q ->data == choose)
{
before = p ->data;
return OK;
}
p = q;
}
return ERROR;
}