当前位置:网站首页>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;
}
}
边栏推荐
- Red hat satellite 6: better management of servers and clouds
- Logseq 评测:优点、缺点、评价、学习教程
- [today in history] July 3: ergonomic standards act; The birth of pioneers in the field of consumer electronics; Ubisoft releases uplay
- Setting up remote links to MySQL on Linux
- Ubuntu 14.04 下开启PHP错误提示
- Flink SQL knows why (7): haven't you even seen the ETL and group AGG scenarios that are most suitable for Flink SQL?
- 开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
- stm32和电机开发(从mcu到架构设计)
- Useful blog links
- 显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
猜你喜欢
MySQL installation, uninstallation, initial password setting and general commands of Linux
Multi table query of MySQL - multi table relationship and related exercises
Unity EmbeddedBrowser浏览器插件事件通讯
DQL basic query
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
MyCms 自媒体商城 v3.4.1 发布,使用手册更新
显卡缺货终于到头了:4000多块可得3070Ti,比原价便宜2000块拿下3090Ti
Flink SQL knows why (19): the transformation between table and datastream (with source code)
2022-02-14 analysis of the startup and request processing process of the incluxdb cluster Coordinator
Libuv Library - Design Overview (Chinese version)
随机推荐
TensorBoard可视化处理案例简析
DQL basic query
Kivy教程之 如何通过字符串方式载入kv文件设计界面(教程含源码)
道路建设问题
json序列化时案例总结
The shadow of the object at the edge of the untiy world flickers, and the shadow of the object near the far point is normal
Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
开始报名丨CCF C³[email protected]奇安信:透视俄乌网络战 —— 网络空间基础设施面临的安全对抗与制裁博弈...
Flutter动态化 | Fair 2.5.0 新版本特性
Universal dividend source code, supports the dividend of any B on the BSC
人身变声器的原理
Convolution emotion analysis task4
35道MySQL面试必问题图解,这样也太好理解了吧
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
Flutter动态化 | Fair 2.5.0 新版本特性
Unity EmbeddedBrowser浏览器插件事件通讯
[Database Principle and Application Tutorial (4th Edition | wechat Edition) Chen Zhibo] [Chapter 6 exercises]
Setting up remote links to MySQL on Linux
Oracle memory management
Cadre de logback