欢迎来到冰点文库! | 帮助中心 分享价值,成长自我!
冰点文库
全部分类
  • 临时分类>
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • ImageVerifierCode 换一换
    首页 冰点文库 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

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

    • 资源ID:5433847       资源大小:299.95KB        全文页数:24页
    • 资源格式: DOCX        下载积分:3金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    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;


    注意事项

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

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

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

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


    收起
    展开