当前位置:网站首页>PHP maze game
PHP maze game
2022-07-03 13:43:00 【Gu Yue's blog】
<?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("======= Game over , IQ is really low =======");
default:
echo 22;
return;
}
// Is it over
if ($next_row == $GLOBALS['rows'] && $next_col == $GLOBALS['cols'] - 1) {
die("======= Game over , High IQ =======");
}
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(){
// Clear the screen
echo chr(27)."[H".chr(27)."[2J";
echo "====== Maze game ======\n";
foreach($GLOBALS['data'] as $val){
echo join(',',$val).PHP_EOL;
}
}
边栏推荐
- Logseq 评测:优点、缺点、评价、学习教程
- 研发团队资源成本优化实践
- 使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
- The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
- 106. How to improve the readability of SAP ui5 application routing URL
- 编程内功之编程语言众多的原因
- The reasons why there are so many programming languages in programming internal skills
- MapReduce实现矩阵乘法–实现代码
- (first) the most complete way to become God of Flink SQL in history (full text 180000 words, 138 cases, 42 pictures)
- Asp. Net core1.1 without project JSON, so as to generate cross platform packages
猜你喜欢
研发团队资源成本优化实践
The difference between stratifiedkfold (classification) and kfold (regression)
Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
rxjs Observable filter Operator 的实现原理介绍
DQL basic query
Resolved (error in viewing data information in machine learning) attributeerror: target_ names
Unity EmbeddedBrowser浏览器插件事件通讯
使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
Brief analysis of tensorboard visual processing cases
RichView TRVStyle ListStyle 列表样式(项目符号编号)
随机推荐
软件测试工作那么难找,只有外包offer,我该去么?
Road construction issues
KEIL5出现中文字体乱码的解决方法
Asp.Net Core1.1版本没了project.json,这样来生成跨平台包
PowerPoint 教程,如何在 PowerPoint 中將演示文稿另存為視頻?
Flutter动态化 | Fair 2.5.0 新版本特性
静态链表(数组的下标代替指针)
Open PHP error prompt under Ubuntu 14.04
Introduction to the implementation principle of rxjs observable filter operator
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
IBEM 数学公式检测数据集
Task5: multi type emotion analysis
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
8 Queen question
MySQL constraints
JS 将伪数组转换成数组
Flutter dynamic | fair 2.5.0 new version features
Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
[sort] bucket sort
Tutoriel PowerPoint, comment enregistrer une présentation sous forme de vidéo dans Powerpoint?