ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:299.95KB ,
资源ID:5433847      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-5433847.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言小游戏俄罗斯方块代码及结果.docx)为本站会员(b****3)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

C语言小游戏俄罗斯方块代码及结果.docx

1、C语言小游戏俄罗斯方块代码及结果C语言小游戏俄罗斯方块代码及结果代码(结过在下面)#include #include #include #include #include #define BLKCHAR #define NUCHAR #define P_X 8#define P_Y 5#define M_X 10#define M_W 58#define M_Y 13#define M_H 11#define NEXTBLOCK_X 29#define NEXTBLOCK_Y 10#define PL_W 12#define PL_H 20#define N_S 4#define N_T 7#

2、define B_W 4#define B_H 4#define INFO_NAME_X 32#define INFO_NAME_Y 20#define INFO_LEVEL_X 32#define INFO_LEVEL_Y 23#define INFO_MARK_X 32#define INFO_MARK_Y 26#define TIME_WAIT 10#define TIME_FALL 50/curuser.level#define WIN_CWSIZE mode con cols=80 lines=30#define FILE_WELCOME welcome#define FILE_OU

3、TLINE outline#define FILE_GAMEOVER gameover#define FILE_BLOCKS blocks#define FILE_PROGRESS progress#define FILE_HELP help#define DEF_NAME NOMANEstruct tpblk int x, y; int type; int state;struct tpuser long level; long mark; char name30;curuser;int panelPL_HPL_W=0;int blocksN_TN_SB_HB_W;void gotoxy(i

4、nt x,int y) COORD c; c.X = x*2, c.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c); struct tpblk initblock() struct tpblk rdblk; rdblk.x=PL_W/2; rdblk.y=-B_H+2; rdblk.type=rand()%N_T; rdblk.state=rand()%N_S; return rdblk;void prtfiletoscr(char *file) FILE *fp; char str100; system(

5、cls); gotoxy(0,0); if(fp=fopen(file,r)=NULL) printf(打开文件:%s失败!n,file); getch(); exit(0); while(fgets(str,100,fp)!=NULL) printf(%s,str); fclose(fp);/下一个方块void prtnxtblk(struct tpblk nxtblock) int i,j; for(i=0;iB_H;i+) for(j=0;jB_W;j+) gotoxy(NEXTBLOCK_X+j,NEXTBLOCK_Y+i); printf(%s,blocksnxtblock.type

6、nxtblock.stateij?BLKCHAR:NUCHAR); /打印面板void prtpanel() int i,j; for(i=0;iPL_H;i+) gotoxy(P_X,P_Y+i); for(j=0;jx-;break; case 77: block-x+;break; case 72: case : case 13: if(block-state=N_S-1)block-state=0; else block-state+;break; case -1:/自动下落 case 80: block-y+;break; case p:/暂停 gotoxy(5,3); printf

7、(暂停中.按任意键恢复。); getch(); gotoxy(5,3); printf( ); return 2; break; case 27:/esc return -1; break; default: return 2; for(i=0;iB_H;i+) for(j=0;jtypeblock-stateij)/保证有点 if(block-x+jx+j=PL_W)return 1;/左右边界 if(block-y+i=PL_H)return 1;/是否到底 if(block-y+i=0&panelblock-y+iblock-x+j)return 1;/与其他块碰撞 return 0;v

8、oid moveblock(struct tpblk oldblock,struct tpblk newblock) int i,j; /清除原有的方块 for(i=0;iB_H;i+) for(j=0;j=0) gotoxy(P_X+oldblock.x+j,P_Y+oldblock.y+i); printf(%s,NUCHAR); /画新方块 for(i=0;iB_H;i+) for(j=0;j=0) /面板中 gotoxy(P_X+newblock.x+j,P_Y+newblock.y+i); printf(%s,BLKCHAR); void loadblocks() FILE *fp;

9、 int i,j,cx,cy,ch; /blocks初始化 if(fp=fopen(FILE_BLOCKS,rt)=NULL) gotoxy(0,0); printf(打开文件:%s失败n,FILE_BLOCKS); getch(); exit(0); for(i=0;iN_T;i+) for(j=0;jN_S;j+) for(cy=0;cyB_H;cy+) for(cx=0;cxB_W;cx+) while(ch=fgetc(fp)-48)!=0&ch!=1) if(ch=EOF) gotoxy(0,0); printf(读取文件:%s错误!n,FILE_BLOCKS); getch();e

10、xit(0); blocksijcycx=ch; fclose(fp); void saveprogress(struct tpuser user) FILE* fp; struct tpuser tmpuser10; int iffind=0,i; if(!strcmp(user.name,DEF_NAME) return; if(fp=fopen(FILE_PROGRESS,rb+)=NULL) printf(打开文件:%s失败!n,FILE_PROGRESS); getch(); exit(0); for(i=0;iffind=0&fread(&tmpuseri,sizeof(struc

11、t tpuser),1,fp);i+) if(!strcmp(user.name,tmpuseri.name) iffind=1; if(iffind) fseek(fp,-(long)sizeof(struct tpuser),1); else fseek(fp,0,2); fwrite(&user,sizeof(struct tpuser),1,fp); if(ferror(fp) printf(存档错误!忽略按Entern,FILE_PROGRESS); while(getch()!=13); fclose(fp);int onbumpbtm(struct tpblk block) in

12、t i,j,lf,nlf=0; /合并 for(i=0;iB_H;i+) for(j=0;jB_W;j+) if(blocksblock.typeblock.stateij) /游戏结束? if(block.y+i=0)return -1; /合并 panelblock.y+iblock.x+j=1; gotoxy(P_X+block.x+j,P_Y+block.y+i); printf(%s,BLKCHAR); /是否满行? for(i=0;iB_H;i+) lf=1; for(j=0;j0;i-) for(j=0;jPL_W;j+) panelij=paneli-1j; nlf+; cur

13、user.mark+=nlf*nlf; saveprogress(curuser); return lf;void prtinfo() gotoxy(INFO_NAME_X,INFO_NAME_Y); printf(%s,curuser.name); gotoxy(INFO_LEVEL_X,INFO_LEVEL_Y); printf(%d,curuser.level); gotoxy(INFO_MARK_X,INFO_MARK_Y); printf(%d,curuser.mark);void clspanel() int i,j; for(i=0;iPL_H;i+) for(j=0;jPL_W

14、;j+) panelij=0;struct tpuser loadprogress() struct tpuser user10=0; FILE* fp; int i,j,c,sel=0,alex=0; if(fp=fopen(FILE_PROGRESS,rb)=NULL) printf(打开文件:%s失败!n,FILE_PROGRESS); getch(); exit(0); for(i=M_Y;i=M_Y+M_H;i+) gotoxy(M_X/2,i); for(j=M_X/2;j=M_X/2+M_W;j+) putchar(); for(i=0;fread(&useri,sizeof(s

15、truct tpuser),1,fp);i+) gotoxy(M_X+5,M_Y+2+i); printf(NAME:%s LEVEL:%ld MARK:%ld,useri.name,useri.level,useri.mark); gotoxy(M_X+5,M_Y+2+i); printf(NEW USER); fclose(fp); gotoxy(M_X+3,M_Y+2+sel); printf(); while(1) c=getch(); switch(c) case 72:/up gotoxy(M_X+3,M_Y+2+sel); printf(); if(sel=i)sel=0; el

16、se sel+; gotoxy(M_X+3,M_Y+2+sel); printf(); break; case 27:/esc user0.level=-1; return user0; break; case 13:/enter if(sel=i)/New User gotoxy(M_X+5,M_Y+2+i+1); printf(Input Name:); scanf(%s,useri.name); for(j=0;ji&!alex;j+) if(!strcmp(userj.name,useri.name) gotoxy(M_X+5,M_Y+2+i+1); printf(%salready

17、exist!,useri.name); getch(); alex=1; if(!alex) useri.level=1L; useri.mark=0; saveprogress(useri); if(usersel.name=0|usersel.level=0|usersel.mark=100*curuser.level) clspanel(); curuser.mark=0; curuser.level+; prtinfo(); prtpanel(); /产生新的BLOCK curblock=nxtblock; nxtblock=initblock(); /画下一个方块 prtnxtblk

18、(nxtblock); if(c=80)timewait=TIME_WAIT/2; gotoxy(0,0); iskh=0; Sleep(timewait); timewait=TIME_WAIT; if(timec=TIME_FALL) c=-1; iskh=1; timec=0; else timec+; return 0;int showmenu() int i,j,c,cursel=0; gotoxy(M_X,M_Y); for(i=M_Y;i=M_Y+M_H;i+) gotoxy(M_X/2,i); for(j=M_X/2;j=M_X/2+M_W;j+) / putchar(b);

19、/ gotoxy(j,i); putchar(); gotoxy(M_X+5,M_Y+2); printf(快 速 游 戏); gotoxy(M_X+5,M_Y+4); printf(读 取 存 档); gotoxy(M_X+5,M_Y+6); printf(帮 助); gotoxy(M_X+5,M_Y+8); printf(退 出); gotoxy(M_X+3,M_Y+2+cursel*2); printf(); while(1) c=getch(); switch(c) case 72:/up gotoxy(M_X+3,M_Y+2+cursel*2); printf(); if(curse

20、l=3)cursel=0; else cursel+; gotoxy(M_X+3,M_Y+2+cursel*2); printf(); break; case 27:/esc return 3; break; case 13:/enter return cursel; break; default:; return 0;int main() int looprst=0,ch; CONSOLE_CURSOR_INFO cursor_info = 1, 0; struct tpuser tmpuser; system(color F8); SetConsoleCursorInfo(GetStdHa

21、ndle(STD_OUTPUT_HANDLE), &cursor_info); system(WIN_CWSIZE); loadblocks(); while(1) prtfiletoscr(FILE_WELCOME); if(getch()=27) break; switch(showmenu() case 0:/fast mode strcpy(curuser.name,DEF_NAME); curuser.level=1; curuser.mark=0; clspanel(); looprst=gameloop(); break; case 1:/read tmpuser=loadprogress(); if(tmpuser.level!=-1) curuser=tmpuser;

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2