2012-09-17 22 views
-2

我有错误是unexpected T_STRING, expecting '(' on line 22,但我没有看到任何(丢失。我正在使用PHP这个基于文本的游戏,但我遇到了第22行的错误

请问谁能向我解释一下这里发生了什么?我在第22行之前错过了什么吗?

这里是我的代码:

<?php 

class Room { 
    protected $description = ""; 
    protected $name = ""; 
    protected $rooms = array(
    "ne" => NULL, 
    "n" => NULL, 
    "nw" => NULL, 
    "e" => NULL, 
    "c" => NULL, 
    "w" => NULL, 
    "se" => NULL, 
    "s" => NULL, 
    "sw" => NULL 
    ); 

    public function __construct ($n = "", $desc = "") { 
    $this->description = $desc; 
    $this->name = $n; 
    } 

    public function get Description() { 
    return $this->description; 
    } 

    public function get Name() { 
    return $this->name; 
    } 

    public function set Room ($direction = "c", $room) { 
    $this->rooms[$direction] = $room; return True; 
    } 

    public function getNewRoom ($direction = "") { 
    return $this->rooms[$direction]; 
    } 
} 


$start Room = new Room ("First Room", "A small room. There is a door to the north."); 
$second Room = new Room ("Second Room", "A short hallway that ends in a dead end. There is a door to the south."); 
$start Room->set Room("n", $second Room); 
$second Room->set Room("s", $first Room); 
$current Room = $start Room; 

$play = True; 

while ($play) { 
    print $current Room->get Name(); 
    print $current Room->get Description(); 

    $input = readline("(Enter your command. Type QUIT to quit.) >"); 

    if ($input == "QUIT") { 
    $play = False; 
    } else { 
    if ($input == 'nw' || 
     $input == 'n' || 
     $input == 'né' || 
     $input == 'e' || 
     $input == 'e' || 
     $input == 'e' || 
     $input == 'e' || 
     $input == 'e' || 
     $input == 'e') 
    { 
     $current Room = $current Room->getNewRoom($input); 
    } 
    } 

} 

?> 
+3

此代码不会看起来像PHP可言,空间的方法/变量,对一些变量没有$等 –

+0

http://www.w3schools.com/php/default.asp – donutdan4114

回答

10

一束你的方法有他们的名字空间。

public function get Description() { 
public function get Name() { 
public function set Room ($direction = "c", $room) { 

这些是不允许的。您必须使用一个词的名字:

public function getDescription() { // For example 

然后,把它以同样的方式:

print $currentRoom->getDescription(); 

同样的事情,必须申请变量。

$current Room = $start Room; // Not allowed 
$currentRoom = $startRoom; // Good! 
相关问题