小游戏"猫捉老鼠"
来源:互联网 发布:淘宝可靠长板店 编辑:程序博客网 时间:2024/04/30 02:40
#include<stdio.h>#include<windows.h>#include<conio.h>#include<stdlib.h>#include<time.h>void gotoxy(int x, int y);int main(){charb[25][40]={{"┏━━━━━━━━━━━━━━━━━━┓"},{"┃ "},{"┃ ■■■ ■■■■■■■■■■ ■■■ ┃"},{"┃ ■ ■ ┃"},{"┃ ■ ■■■■■■ ■ ■■■■■■ ■ ┃"},{"┃ ■ ■ ┃"},{"┃ ■ ■ ■■ ■■■■■■ ■■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■■ ■■■ ■■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■■■■■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■ ■■ ■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■■ ■■ ■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■■ ■■■ ■■ ■ ■ ┃"},{"┃ ■ ■ ■ ■ ┃"},{"┃ ■ ■ ■■ ■■■■■■ ■■ ■ ■ ┃"},{"┃ ■ ■ ┃"},{"┃ ■ ■■■■■■ ■ ■■■■■■ ■ ┃"},{"┃ ■ ■ ┃"},{"┃ ■■■ ■■■■■■■■■■ ■■■ ┃"},{" ┃"},{"┗━━━━━━━━━━━━━━━━━━┛"},};int sx,sy,mx,my;int flag=0;int i, j, k, d, n=0, f=0;int t;char c;for(i=0; i<25; i++){ for(j=0; j<40; j++) printf("%c", b[i][j]); printf("\n");}mx=0, my=23;sx=20, sy=11;gotoxy(mx,my); printf("M");gotoxy(sx,sy); printf("@");while(1){k=_kbhit(); if(k){ c=_getch(); gotoxy(mx, my); printf(" "); if(c=='i'&&b[my-1][mx]==' ') my--; if(c=='k'&&b[my+1][mx]==' ') my++; if(c=='j'&&b[my][mx-1]==' ') mx--; if(c=='l'&&b[my][mx+1]==' ') mx++; gotoxy(mx, my); printf("M");}//0right 1 down 2left 3 upgotoxy(sx,sy);printf(" ");switch(f)//f中存放移动方向,初始可为0{case 0:if(n!=2 && b[sy][sx+1]==' '){sx++;n=0;}if(rand()%2)f=3;elsef=1;break;case 1:if(n!=3 && b[sy-1][sx]==' '){sy--;n=1;}if(rand()%2)f=0;elsef=2;break;case 2:if(n!=0 && b[sy][sx-1]==' '){sx--;n=2;}if(rand()%2)f=3;elsef=1;break;case 3:if(n!=1 && b[sy+1][sx]==' '){sy++;n=3;}if(rand()%2)f=0;elsef=2;break;}gotoxy(sx,sy);printf("@");Sleep(20);if(mx==sx&&my==sy){ gotoxy(mx,my);printf("M");break;}if(sx==40&&sy==1){flag=1; break;}}if(flag) gotoxy(40,1), printf("you lost");elsegotoxy(40, 1), printf("you win");}void gotoxy(int x, int y) //定位到第y行的第x列 { int xx=0x0b; HANDLE hOutput; COORD loc; loc.X=x; loc.Y=y; hOutput = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOutput, loc); return; }
0 0
- 小游戏"猫捉老鼠"
- 1019猫捉老鼠
- 猫捉老鼠(1019)
- 猫捉老鼠
- fZU_1019 猫捉老鼠
- 猫捉老鼠
- 猫捉老鼠
- FZU1019-猫捉老鼠
- 猫捉老鼠 FZU
- FOJ 1019 猫捉老鼠
- FZU 1019 猫捉老鼠
- <FZU 1019>猫捉老鼠
- Problem 1019 猫捉老鼠
- FZU1019 猫捉老鼠 (BFS)
- 猫捉老鼠问题系列(一)
- 猫捉老鼠问题系列(二)
- 猫捉老鼠问题系列(三)
- 猫捉老鼠问题系列(四)
- 在struts下如果类改变了,在从jsp往action提交的时候,就会报ja
- oracle move表释放空间
- 90后程序员妹纸教你如何搞定无聊的工作和老板
- Ajax 动态加载内容
- 北京明远智睿的核心板,详细的开发资料,稳定可靠的性能,低廉的价格,赢得了广大客户的喜爱
- 小游戏"猫捉老鼠"
- getline
- leetcode题目:Sum Root to Leaf Numbers和Longest Consecutive Sequence
- PHP的安全问题
- mDNS
- C\C++代码优化的27个建议
- windows7 codeblocks 配置 GTK2.x\3.x
- 《仔仔细细分析Ext》 脚本,你的效率到底损失在哪里?:Ext对Array对象的扩展
- [spark学习]之spark shell 入门