实训第三天--数字迷宫
来源:互联网 发布:网游明星知乎 编辑:程序博客网 时间:2024/06/05 04:09
# include <stdio.h># include <string.h># include <stdlib.h># include <conio.h># include <time.h># include "windows.h"char c=1; int x,y,t1,t2; int count=7; int code[17][24]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,8,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0, 0,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,-1,0,0,0,0,0,-1,-1,-1,0,0, 0,-1,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,0, 0,-1,-1,-1,-1,-1,0,-1,-1,-1,-1,-1,0,-1,0,-1,-1,-1,-1,-1,-1,-1,0,0, 0,-1,0,0,-1,0,-1,0,0,0,0,-1,0,-1,-1,-1,0,0,0,0,0,0,0,0, 0,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0,0,-1,0,0,0,0,0,0,0,0, 0,-1,0,0,0,0,0,0,0,0,0,-1,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,0,-1,0,0,0,0, 0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,0,0,-1,0,0,0,0, 0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,-1,-1,-1,-1,0,-1,-1,0, 0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,0,0, 0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,-1,0,0, 0,0,-1,-1,-1,-1,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0, 0,-1,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0, 0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; void SetNum() { int i,x,y; srand((unsigned)time(NULL)); for(i=0;i<7;i++) { x=1+rand()%15; y=1+rand()%22; if(code[x][y]==-1) { code[x][y]=i+1; } else { i--; } }}void SetCode(int num) { if(num==0) printf("■"); else if(num==-1||num==8) printf(" "); else printf("%d ",num);}void GoToXY(int x, int y){ COORD pos={x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos); CONSOLE_CURSOR_INFO cursor_info = {1, 0}; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);} void GoToXYSpace(int x, int y) { GoToXY(x,y); printf(" ");}void SetWindow() { int i,j; for(i=0;i<17;i++) { for(j=0;j<24;j++) { SetCode(code[i][j]); } printf("\n"); } GoToXY(2,1); printf("%c ",c);}void UpKey() { t1=x; t2=y; x=x; y=y-1; if(code[y][x/2]==0) { x=t1; y=t2; } else { GoToXYSpace(t1,t2); GoToXY(x,y); printf("%c ",c); if(code[y][x/2]!=-1) { count--; code[y][x/2]=-1; } }}void DownKey() { t1=x; t2=y; x=x; y=y+1; if(code[y][x/2]==0) { x=t1; y=t2; } else { GoToXYSpace(t1,t2); GoToXY(x,y); printf("%c ",c); if(code[y][x/2]!=-1) { count--; code[y][x/2]=-1; } }}void LeftKey() { t1=x; t2=y; x=x-2; y=y; if(code[y][x/2]==0) { x=t1; y=t2; } else { GoToXYSpace(t1,t2); GoToXY(x,y); printf("%c ",c); if(code[y][x/2]!=-1) { count--; code[y][x/2]=-1; } }}void RightKey() { t1=x; t2=y; x=x+2; y=y; if(code[y][x/2]==0) { x=t1; y=t2; } else { GoToXYSpace(t1,t2); GoToXY(x,y); printf("%c ",c); if(code[y][x/2]!=-1) { count--; code[y][x/2]=-1; } }}int CheckLeftNum(int count) { if(count>=0) return count;}void Move() { char ch; x=2,y=1,count=7; while(ch=getch()) { if(ch==27) { count=100; break; } if(ch==72) UpKey(); else if(ch==80) DownKey(); else if(ch==75) LeftKey(); else if(ch==77) RightKey(); CheckLeftNum(count); if(count==0) { count=7; system("cls"); break; } }}int main() { char ch; while(count==7) { GoToXY(30,20); printf("按上下左右移动\n"); GoToXY(30,21); printf("按ESC退出\n"); GoToXY(0,0); SetNum(); SetWindow(); Move(); } GoToXY(0,17); return 0;}
0 0
- 实训第三天--数字迷宫
- 实训第一天--数字迷宫
- 数字迷宫
- 数字迷宫
- 数字迷宫
- 第三天 绘制数字
- 数字迷宫思考-上
- 数字迷宫思考-下
- 数字迷宫小游戏源代码
- 数字迷宫小游戏
- C语言---数字迷宫
- 实训第三天
- 实训第三天
- 实训第三天~
- 实训第三天
- 2016.7.10实训--数字迷宫
- 数字三角形(迷宫奖卷)dp
- 实训项目 数字迷宫小游戏
- CF 241E Flights
- 工厂方法(Factory Method)
- MX、SPF记录查询的方法
- Ubuntu server 14.04下安装hadoop-2.6.4 集群机
- git简单操作
- 实训第三天--数字迷宫
- POJ 3281 Dining(最大流)
- EventBus 3.0 使用介绍
- LeetCode 100. Same Tree
- 渲染路径-实时渲染中常用的几种Rendering Path
- Elastic cache
- 串(String)--基本概念
- CXF和spring整合实现webservice实例(二)
- MyEclipse8.5 环境中配置Tomcat7.X