我正在使用 PHP 创建一个 Dungeon 场景。本质上,我试图完成的是创建一个 10 x 10 的表,该表将显示一组由随机数定义的变量。我已经为此苦苦挣扎了很长时间,但无济于事。希望有人可以帮我一把,并指出我正确的方向。
<html>
<head>
<title>The Dungeon</title>
<?php
function populateRoom(){
$randomNumber = rand(1,5);
$emptyRoom = "O";
$treasure = "$";
$monster = "M";
$trap = "^";
if($randomNumber == 1 || $randomNumber ==2){
echo "<h1><td>$emptyRoom</td></h1>";}
elseif ($randomNumber == 3){
echo"<h1><td>$treasure</td></h1>";}
elseif ($randomNumber == 4){
echo"<h1><td>$monster</td></h1>";}
else{
echo"<h1><td>$trap</td></h1>";}
return array($emptyRoom,$treasure,$monster,$trap)
?>
</head>
<body>
<h2>The Dungeon</h2>
<?php
echo "<table border=\"1\">";
for ($row=1; $row<=10; $row++){
echo "<tr>\n";
for ($col=1; $col<=10; $col++){
echo "<td>.populateRoom().</td>\n";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>