当前位置:网站首页>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;
}
}
边栏推荐
- The shortage of graphics cards finally came to an end: 3070ti for more than 4000 yuan, 2000 yuan cheaper than the original price, and 3090ti
- [how to earn a million passive income]
- Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
- MySQL functions and related cases and exercises
- 已解决TypeError: Argument ‘parser‘ has incorrect type (expected lxml.etree._BaseParser, got type)
- Heap structure and heap sort heapify
- Introduction to the implementation principle of rxjs observable filter operator
- Stack application (balancer)
- Libuv Library - Design Overview (Chinese version)
- Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
猜你喜欢
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
106. How to improve the readability of SAP ui5 application routing URL
双链笔记 RemNote 综合评测:快速输入、PDF 阅读、间隔重复/记忆
Flink SQL knows why (16): dlink, a powerful tool for developing enterprises with Flink SQL
Internet of things completion -- (stm32f407 connects to cloud platform detection data)
Typeerror resolved: argument 'parser' has incorrect type (expected lxml.etree.\u baseparser, got type)
File uploading and email sending
CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
Brief analysis of tensorboard visual processing cases
Flink SQL knows why (XIV): the way to optimize the performance of dimension table join (Part 1) with source code
随机推荐
SQL Injection (GET/Select)
8 Queen question
Comprehensive evaluation of double chain notes remnote: fast input, PDF reading, interval repetition / memory
Resource Cost Optimization Practice of R & D team
Setting up remote links to MySQL on Linux
Flink SQL knows why (17): Zeppelin, a sharp tool for developing Flink SQL
DQL basic query
【被动收入如何挣个一百万】
Flink SQL knows why (12): is it difficult to join streams? (top)
Students who do not understand the code can also send their own token, which is easy to learn BSC
【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
父亲和篮球
Open PHP error prompt under Ubuntu 14.04
道路建设问题
Heap structure and heap sort heapify
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
MapReduce implements matrix multiplication - implementation code
Swiftui development experience: the five most powerful principles that a programmer needs to master
Static linked list (subscript of array instead of pointer)
SVN添加文件时的错误处理:…\conf\svnserve.conf:12: Option expected