C语言练习打字小游戏Word下载.docx

上传人:b****4 文档编号:18168013 上传时间:2022-12-13 格式:DOCX 页数:25 大小:510.64KB
下载 相关 举报
C语言练习打字小游戏Word下载.docx_第1页
第1页 / 共25页
C语言练习打字小游戏Word下载.docx_第2页
第2页 / 共25页
C语言练习打字小游戏Word下载.docx_第3页
第3页 / 共25页
C语言练习打字小游戏Word下载.docx_第4页
第4页 / 共25页
C语言练习打字小游戏Word下载.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

C语言练习打字小游戏Word下载.docx

《C语言练习打字小游戏Word下载.docx》由会员分享,可在线阅读,更多相关《C语言练习打字小游戏Word下载.docx(25页珍藏版)》请在冰豆网上搜索。

C语言练习打字小游戏Word下载.docx

1要求

(1)要求使用多文件方式实现设计;

(2)要求在各个文件内实现结构化设计;

(3)每个模块作为一个单独的C文件。

2文件及函数组成

自定义函数

系统函数

welcome()

实现欢迎界面

textbackground()

Textcolor()

gotoxy()

Window()

sleep()

randomize()

clock()

time(NULL)

getch()

putchar()

sound()

delay()

nosound()

kbhit()

random()

difftime(int,int)

exit()

cputs()

menu()

window的窗口界面

DrawFrame(intl,intu,intr,intd,inttcolor,intbcolor)

画边框函数

Enter(intm,intn)

菜单选项的具体功能

Start()

开始打字

Bgcolor()

背景颜色

Ccolor()

字体颜色

Time()

设定时间

Help()

系统帮助

About()

系统信息

Qutigame()

退出系统

3函数设计

(1)头文件

#include<

stdio.h>

graphics.h>

conio.h>

bios.h>

dos.h>

time.h>

这里的include称为文件,因此也称为头文件或首部文件。

C语言的头文件中包括了各个标准库函数的函数原型。

因此,凡是在程序中调用一个库函数时,都必须包含该函数原型所在的头文件。

scanf和printf是标准输入输出函数,其头文件为stdio.h,在主函数前也用include命令包含了stdio.h文件。

stdio.h是输入输出头文件,所有有关输入输出的语句如"

printf"

"

scanf"

putchar"

getchar"

等,都要用该头文件,头文件其实就是定义了这些函数的文件,它是系统提供给我们的接口

conio.h是TC特有的,用于输入输出图形方面

conio.h是字符屏幕操作函数啊!

常用的getch()clrscr()清屏函数啊!

清除正文窗口都在这里面定义

<

是TC里面的图形库,如果要用的话应该用TC来编译,VC++有他自己的另外图形库。

含有一下系列的函数:

(2)变量参数

defineMAXCHAR100

#defineESC0x011b/*退出程序键,调用quitgame()函数*/

#defineF10x3b00/*查看帮助信息,调用Help()函数*/

#defineF20x3c00/*查看关于...信息,调用About()函数*/

#defineF30x3d00/*以下功能键暂时保留,如果增加功能可使用*/

这些是一些定义变量及参数

(3)相关函数

函数名:

outtextxy

 功能:

在指定位置显示一字符串

settextstyle

  功能:

:

为图形输出设置当前的文本属性

  用法:

voidfarsettextstyle(intfont,intdirection,charsize);

  fornt为字体:

DEFAULT_FONT,TRIPLEX_FONT,SMALL_FONT,SANSSERIF_FONT,GOTHIC_FONT,也可以用0~4代替。

  direction为字符的排列方向:

横向和竖向,0为横向排列,1为竖向排列。

  size为字体大小:

可用interger做参数。

函数名:

gotoxy

原型:

externvoidgotoxy(intx,inty);

  用法:

system.h>

功能:

将光标移动到指定位置说明:

gotoxy(x,y)将光标移动到指定行y和列x。

设置光标到文本屏幕的指定位置,其中参数x,y为文本屏幕的坐标。

时间控制函数

intTime_control()

利用<

和<

文件,得到玩游戏的总时间,计算游戏积分。

参数:

void

返回值:

intTime:

游戏前后的时间差异

/*

练习训练游戏

*/

#defineMAXCHAR100

#defineF30x3d00/*以下功能键暂时保留,如果增加功能可使用*/

#defineF40x3e00

#defineF50x3f00

#defineF60x4000

#defineF70x4100

#defineF80x4200

#defineF90x4300

#defineF100x4400

#defineKEY10x0231

#defineKEY20x0332

#defineKEY30x0433

#defineKEY40x0534

#defineKEY010x4f31

#defineKEY020x5032

#defineKEY030x5133

#defineKEY040x4b34

charstring[MAXCHAR+1];

intLittleWin(intWinType/*=1,quitgame;

=2,Help;

=3,About;

=4,others;

*/);

/*whenWinType=1,return0,quit,return1,notquit*/

voidquitgame();

voidWelcome();

voiddrawframe();

voidFrame();

voidGetCharacter();

voidTyping();

*/)

{

inti;

charch;

window(18,6,62,20);

textbackground(LIGHTGRAY);

textcolor(BLACK);

clrscr();

清除把之前显示出的文字自负去掉

gotoxy(1,1);

将光标移动到指定位置

cprintf("

%c"

201);

送格式化输出至屏幕for(i=0;

i<

43;

i++)

cprintf("

205);

187);

for(i=0;

13;

{

gotoxy(1,i+2);

186);

gotoxy(45,i+2);

}

gotoxy(1,14);

200);

188);

gotoxy(20,1);

switch(WinType)

case1:

cprintf("

Exit"

);

textcolor(LIGHTRED);

gotoxy(18,3);

Warning!

"

textcolor(LIGHTBLUE);

gotoxy(5,5);

Thisoperationwillexittheprogram!

gotoxy(10,7);

Doyoureallywanttoquit?

textcolor(LIGHTGREEN);

gotoxy(18,9);

OK?

[Y/N]"

/*window(18,20,62,20);

textbackground(LIGHTBLUE);

textcolor(YELLOW);

clrscr();

window(19,18,61,18);

textcolor(WHITE);

gotoxy(5,1);

PressYtoquit,pressNtoreturn."

while

(1)

{

ch=getch()从键盘输入一个字符赋给对应的字符变量;

if(ch=='

Y'

||ch=='

y'

return0;

elseif(ch=='

N'

n'

return1;

}

break;

case2:

Help"

case3:

About"

case4:

Info"

default:

}

voidquitgame()

if(LittleWin

(1))

Frame();

return;

window(1,1,80,25);

textbackground(BLACK);

textcolor(LIGHTGRAY);

exit(0);

voidWelcome()

intdriver=VGA,mode=VGAHI;

/*定义变量*/

intx1=20,y1=20,r=10,num,i;

intx2=20,y2=450;

intcolor1=10,color2=10;

/*在此设置颜色,一改全改*/

staticcharch1[28][2]={"

W"

e"

l"

c"

o"

m"

"

t"

h"

T"

y"

p"

i"

n"

g"

r"

d"

!

};

initgraph(&

driver,&

mode,"

C:

\\tc"

/*初始化图形模式*/

setbkcolor(LIGHTBLUE);

setcolor(color1);

/*步骤一、设置当前颜色用于绘图*/

for(num=0;

num<

30;

num++)

circle(x1,y1,r);

/*步骤二、使用当前颜色绘制一个闭合图形*/

setfillstyle(num%12,color1);

/*步骤三、设置填充方式*/

floodfill(x1,y1,color1);

/*步骤四、对闭合图形进行填充*/

x1+=20;

sound(300);

/*输出声音*/

delay(3000);

nosound();

setcolor(color2);

circle(x2,y2,r);

setfillstyle(num%12,color2);

floodfill(x2,y2,color2);

x2+=20;

settextstyle(0,0,2);

setcolor(LIGHTRED);

sound(300);

delay(3000);

nosound();

outtextxy(180,90,"

^o^Hello!

^o^"

setcolor(YELLOW);

gotoxy(50,150);

28;

outtextxy(50+i*16,150,ch1[i]);

/*outtextxy(50,150,"

WelcometotheTypingWorld!

setcolor(WHITE);

outtextxy(50,200,"

Thisisalittle"

delay(6000);

outtextxy(100,250,"

TypingTraining"

outtextxy(150,300,"

Software...^_^"

setcolor(LIGHTMAGENTA);

outtextxy(100,350,"

Ver.2004-04-30"

setcolor(LIGHTGREEN);

outtextxy(100,400,"

Pressanykeytostart..."

getch();

closegraph();

/*关闭图形*/

voiddrawframe()

window(1,1,80,1);

gotoxy(7,1);

FileEditRunCompileProjectOptionsDebugHelp"

textcolor(RED);

F"

gotoxy(14,1);

E"

gotoxy(21,1);

R"

gotoxy(27,1);

C"

gotoxy(37,1);

P"

gotoxy(47,1);

O"

gotoxy(57,1);

D"

gotoxy(65,1);

H"

window(1,25,80,25);

printf("

F1-HelpF2-AboutF3-OpenF4-RestartCtrl+F9-RunESC-Quit"

F1"

gotoxy(17,1);

F2"

gotoxy(28,1);

F3"

F4"

gotoxy(50,1);

Ctrl+F9"

gotoxy(64,1);

ESC"

window(1,2,80,24);

textbackground(LIGHTBLUE);

gotoxy(1,2);

213);

78;

184);

21;

gotoxy(1,i+3);

179);

gotoxy(80,i+3);

gotoxy(1,22);

192);

196);

217);

textcolor(WHITE);

Type"

voidFrame()/*设置菜单函数*/

drawframe();

window(2,3,79,22);

textcolor(YELLOW);

gotoxy(25,2);

TheTypingWorldMenu\n"

gotoxy(12,4);

1:

PracticeOnlyENGLISHCharacters."

gotoxy(12,6);

2:

PracticeOtherCharcters."

gotoxy(12,8);

3:

PracticeAllCharcters."

gotoxy(12,10);

4:

Quitatonce!

GetCharacter();

voidGetCharacter(void)/*设置得到字符函数*/

voidTyping();

/*声明typing()函数*/

FILE*in;

inti,t,choice;

t=abs(time(0))%700;

/*获取随机数来指定下面指针的位*/

gotoxy(12,12);

Pleaseinputyourchoice:

while

(1)

gotoxy(38,12);

choice=bioskey(0);

if(choice==ESC||choice==KEY4||choice==KEY04)

{

quitgame();

}

elseif(choice==KEY1||choice==KEY01)

in=fopen("

english.dat"

elseif(choice==KEY2||choice==KEY02)

others.dat"

elseif(choice==KEY3||choice==KEY03)

typeall.dat"

/*清屏*/

fseek(in,t*1l,0);

fgets(string,MAXCHAR+1,in);

******************************************************************************"

MAXCHAR;

%

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > 财会金融考试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1