迷宫代码如下:

#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
void print(char a[10][10]){
system("cls");
for(int i=0;i<5;i++)
cout<<a[i]<<endl;
}
int main(){
int x=1,y=1;
int ch;
char a[10][10] = {
"######",
"#0 #",
"# #",
"# # ",
"######"
};
print(a);
while(x != 3 || y != 5){
if (_kbhit()){
ch = _getch();
if (ch == 27){ break; }
if (ch == 97 && a[x][y-1] == ' '){
a[x][y] = ' ';
y--;
a[x][y] = '0';
print(a);
}
if (ch == 100 && a[x][y+1] == ' '){
a[x][y] = ' ';
y++;
a[x][y] = '0';
print(a);
}
if (ch == 115 && a[x+1][y] == ' '){
a[x][y] = ' ';
x++;
a[x][y] = '0';
print(a);
}
if (ch == 119 && a[x-1][y] == ' '){
a[x][y] = ' ';
x--;
a[x][y] = '0';
print(a);
}
}
}
system("cls");
cout<<"you win";
return 0;
}

  运行如下:

用a,s,w,d按键控制小球:

移动代码如下:

#include <iostream>
#include <conio.h>
using namespace std;
void print(){
cout<<"12345"<<endl<<"|||||"<<endl;
}
int main(){
int ch,x=0;
print();
cout<<"*";
while(true){
if (_kbhit()){
ch = _getch();
if(ch==100 && x < 4){
x++;
system("cls");
print();
for(int i = 0;i < x;i++){
cout<<" ";
}
cout<<"*";
}
if(ch==97 && x > 0){
x--;
system("cls");
print();
for(int i = 0;i < x;i++){
cout<<" ";
}
cout<<"*";
}
}
}
return 0;
}

运行如下:

用a,d按键控制小球

最新文章

  1. 【转】[教程]在 win7 / win8 下安装苹果系统 (懒人版)
  2. iOS 视图,动画渲染机制探究
  3. Java 的世界,我不懂:奇葩的 json 序列化
  4. SQL Server数据库性能优化(一)之 优化SQL 语句
  5. Error opening trace file: No such file or directory (2)
  6. delphi HTML代码
  7. IOS多线程的小总结
  8. css 动画 transform transition animation
  9. Android图片与旋转
  10. 深入解析_Android的自定义布局
  11. github用法小结
  12. JVM菜鸟进阶高手之路三
  13. C语言 字符串前加L的意义 如:L“A”
  14. gif文件解析
  15. Groovy入门(2-2)Groovy的eclipse插件安装
  16. .NET Core 学习笔记3&mdash;&mdash;EF Core
  17. 别人的Linux私房菜(7)文件与目录管理
  18. psp本周
  19. youtube高清视频下载方法
  20. go语言中strings包中的Trim函数的作用是什么

热门文章

  1. python中两种拷贝目录方法的比较
  2. 慕慕生鲜上线&amp;&amp;腾讯云服务器配置准备
  3. ECC(Ellipse Curve Cryptography)+AES(Advanced Encryption Standard)前端通讯加密模拟(使用eccrypto-js)
  4. COM笔记-动态链接
  5. SpringBoot使用@Scheduled创建定时任务
  6. Spring之属性注入
  7. 解决 conda tensorflow failed to create cublas handle: CUBLAS_STATUS_NOT_INITIALIZED
  8. jQuery mobile网格布局
  9. 取消Ubuntu开机硬盘自检
  10. 786. 第k个数