当前位置:网站首页>php 迷宫游戏
php 迷宫游戏
2022-07-03 13:05:00 【古月的博客】
<?php
$data = [
['#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'],
['#','O','#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'],
['#',' ','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'],
['#',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','#'],
['#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#',' ','#'],
];
$row = 1;
$col = 1;
$rows = count($data) - 1;
$cols = count($data[0]) - 1;
show();
while(1){
$dir = fgets(STDIN);
move($dir);
// var_dump($data);
show();
}
function move($dir){
$dir = trim($dir);
switch($dir){
case 's':
$next_row = $GLOBALS['row'] + 1 > $GLOBALS['rows'] ?$GLOBALS['rows']:$GLOBALS['row'] + 1;
$next_col = $GLOBALS['col'];
break;
case 'd':
$next_row = $GLOBALS['row'];
$next_col = $GLOBALS['col'] + 1 > $GLOBALS['cols']?$GLOBALS['cols']:$GLOBALS['col']+1;
break;
case 'w':
$next_row = $GLOBALS['row'] - 1<0?0:$GLOBALS['row'] - 1;
$next_col = $GLOBALS['col'];
break;
case 'a':
$next_row = $GLOBALS['row'];
$next_col = $GLOBALS['col'] - 1<0?0:$GLOBALS['col'] - 1;
break;
case 'q':
die("=======游戏结束,智商真低=======");
default:
echo 22;
return;
}
// 是否结束了
if ($next_row == $GLOBALS['rows'] && $next_col == $GLOBALS['cols'] - 1) {
die("=======游戏结束,智商真高=======");
}
if($GLOBALS['data'][$next_row][$next_col] == ' '){
$GLOBALS['data'][$next_row][$next_col] = 'O';
$GLOBALS['data'][$GLOBALS['row']][$GLOBALS['col']] = ' ';
$GLOBALS['col'] = $next_col;
$GLOBALS['row'] = $next_row;
}
}
function show(){
// 清屏
echo chr(27)."[H".chr(27)."[2J";
echo "======迷宫游戏======\n";
foreach($GLOBALS['data'] as $val){
echo join(',',$val).PHP_EOL;
}
}
边栏推荐
- [colab] [7 methods of using external data]
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- R语言使用data函数获取当前R环境可用的示例数据集:获取datasets包中的所有示例数据集、获取所有包的数据集、获取特定包的数据集
- Reptile
- Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
- Logseq evaluation: advantages, disadvantages, evaluation, learning tutorial
- Resolved (error in viewing data information in machine learning) attributeerror: target_ names
- The reasons why there are so many programming languages in programming internal skills
- 双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
- Flink SQL knows why (12): is it difficult to join streams? (top)
猜你喜欢
Unity EmbeddedBrowser浏览器插件事件通讯
[sort] bucket sort
This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version
Flink SQL knows why (19): the transformation between table and datastream (with source code)
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
用户和组命令练习
Kivy tutorial how to automatically load kV files
Elk note 24 -- replace logstash consumption log with gohangout
MySQL constraints
Detailed explanation of multithreading
随机推荐
The reasons why there are so many programming languages in programming internal skills
【历史上的今天】7 月 3 日:人体工程学标准法案;消费电子领域先驱诞生;育碧发布 Uplay
File uploading and email sending
Flink SQL knows why (13): is it difficult to join streams? (next)
This math book, which has been written by senior ml researchers for 7 years, is available in free electronic version
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter IV exercises]
JSON serialization case summary
Realize the recognition and training of CNN images, and process the cifar10 data set and other methods through the tensorflow framework
Disruptor -- a high concurrency and high performance queue framework for processing tens of millions of levels
Anan's doubts
Students who do not understand the code can also send their own token, which is easy to learn BSC
研发团队资源成本优化实践
Logback 日志框架
Internet of things completion -- (stm32f407 connects to cloud platform detection data)
February 14, 2022, incluxdb survey - mind map
Unity EmbeddedBrowser浏览器插件事件通讯
Kivy教程之 如何自动载入kv文件
顺序表(C语言实现)
8皇后问题
显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti