我正在开发一个基于文本的在线游戏(这是非常不完整的),我主要使用php。在我的html中,我有一个表单(文本输入)用于命令我的游戏,但它只是不会出现。这是我的HTML:
<div class="container">
<div class="main">
<?php
include_once 'game.php';
?>
</div>
<FORM NAME="form1" METHOD="POST" ACTION="">
<INPUT TYPE="TEXT" VALUE="" name="input"
style="width: 600; position: absolute; bottom: 0; z-index: 2;">
</INPUT>
</FORM>
<?php
$input = $_POST["input"];
?>
</div>
因为它没有出现,所以它真的是形式和输入把我搞砸了。我也有这个作为我的css,如果它有帮助的话:
.main {
width: 600px;
height: 400px;
background-color: white;
border: 1px solid black;
position: absolute;
top:0;
left: 0;
right: 0;
z-index: 1;
}
.container {
width: 602px;
height: 500px;
background-color: white;
border: 1px solid blue;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 0;
margin: 0 auto;
}
当然我有我的
game.php
但我觉得这不是问题所在。任何帮助都将不胜感激。
编辑:根据人们的回答,可能是php。这是game.php文件的全部代码,我不知道出了什么问题。
<?php
include_once 'index.php';
$World = simplexml_load_file("gameworld.xml");
$CurrentPos = 0;
$Done = 0;
print "<br>";
printplace();
function printplace() {
GLOBAL $World, $CurrentPos;
$Room = $World->ROOM[$CurrentPos];
$Name = $Room->NAME;
$Desc = wordwrap((string)$Room->DESC);
print "$Name<br>";
print str_repeat('-', strlen($Name));
print "<br>$Desc<br>";
if ((string)$Room->NORTH != '-') {
$index = (int)$Room->NORTH;
print "North: {$World->ROOM[$index]->NAME}<br>";
}
if ((string)$Room->SOUTH != '-') {
$index = (int)$Room->SOUTH;
print "South: {$World->ROOM[$index]->NAME}<br>";
}
if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
$index = (int)$Room->WEST;
print "West: {$World->ROOM[$index]->NAME}<br>";
}
if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
$index = (int)$Room->EAST;
print "East: {$World->ROOM[$index]->NAME}<br>";
}
print "<br>";
}
while (!$Done) {
print "<br>"; // add another line break after the user input
$input = split(' ', $input);
switch(trim($input[0])) {
case 'north':
if ((string)$World->ROOM[$CurrentPos]->NORTH != '-') {
$CurrentPos = (int)$World->ROOM[$CurrentPos]->NORTH;
printplace() ;
} else {
print "You cannot go north!<br>";
}
break;
case 'south':
if ((string)$World->ROOM[$CurrentPos]->SOUTH != '-') {
$CurrentPos = (int)$World->ROOM[$CurrentPos]->SOUTH;
printplace() ;
} else {
print "You cannot go south!<br>";
}
break;
case 'west':
if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
$CurrentPos = (int)$World->ROOM[$CurrentPos]->WEST;
printplace() ;
} else {
print "You cannot go west!<br>";
}
break;
case 'east':
if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
$CurrentPos = (int)$World->ROOM[$CurrentPos]->EAST;
printplace() ;
} else {
print "You cannot go east!<br>";
}
break;
case 'look':
printplace() ;
break;
case 'quit':
$Done = 1;
break;
}
}
print "<br>Thanks for playing!<br>";
?>
真的,它只是http://www.hackingwithphp.com/21/4/2/text-game-v1的一个分支
我试图移植到浏览器,但失败得很可怕…
最佳答案
它在chrome和firefox中显示得很好。见下文。
.main {
width: 600px;
height: 400px;
background-color: white;
border: 1px solid black;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 1;
}
.container {
width: 602px;
height: 500px;
background-color: white;
border: 1px solid blue;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 0;
margin: 0 auto;
}
<div class="container">
<div class="main">
</div>
<FORM NAME="form1" METHOD="POST" ACTION="">
<INPUT TYPE="TEXT" VALUE="" name="input" style="width: 600; position: absolute; bottom: 0; z-index: 2;">
</INPUT>
</FORM>
</div>