Jump to content

Help with a line of code please


Zayl

Recommended Posts

I am having a problem with line 41 in this code and i cant figure out why. It should work according to other people.

 

<?php

    $World = simplexml_load_file("gameworld.xml");

    $CurrentPos = 0;

    $Done = 0;

    print "\n";

    printplace() ;

 

    function printplace() {

        GLOBAL $World, $CurrentPos;

        $Room = $World->ROOM[$CurrentPos];

        $Name = $Room->NAME;

        $Desc = wordwrap((string)$Room->DESC);

        print "$Name\n";

        print str_repeat('-', strlen($Name));

        print "\n$Desc\n\n";

 

        if ((string)$Room->NORTH != '-') {

            $index = (int)$Room->NORTH;

            print "North: {$World->ROOM[$index]->NAME}\n";

        }

 

        if ((string)$Room->SOUTH != '-') {

            $index = (int)$Room->SOUTH;

            print "South: {$World->ROOM[$index]->NAME}\n";

        }

 

        if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {

            $index = (int)$Room->WEST;

            print "West: {$World->ROOM[$index]->NAME}\n";

        }

 

        if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {

            $index = (int)$Room->EAST;

            print "East: {$World->ROOM[$index]->NAME}\n";

        }

 

        print "\n";

    }

 

    while (!$Done) {

        $input = fgets(STDIN);

        print "\n"; // 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!\n";

                }

                break;

            case 'south':

                if ((string)$World->ROOM[$CurrentPos]->SOUTH != '-') {

                    $CurrentPos = (int)$World->ROOM[$CurrentPos]->SOUTH;

                    printplace() ;

                } else {

                    print "You cannot go south!\n";

                }

                break;

            case 'west':

                if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {

                    $CurrentPos = (int)$World->ROOM[$CurrentPos]->WEST;

                    printplace() ;

                } else {

                    print "You cannot go west!\n";

                }

                break;

            case 'east':

                if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {

                    $CurrentPos = (int)$World->ROOM[$CurrentPos]->EAST;

                    printplace() ;

                } else {

                    print "You cannot go east!\n";

                }

                break;

            case 'look':

                printplace() ;

                break;

            case 'quit':

                $Done = 1;

                break;

        }

    }

 

    print "\nThanks for playing!\n\n";

?>

 

if you can please im open for ideas for a fix or for a reason why its not working.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.