jeudi 31 octobre 2019

if statement not valid?

This sounds so stupid, and i know for sure im being stupid, but i cant figure out why its not working.

the if in question, is

if (currentRoom = outside || pub);
    {
        System.out.println("A friendly traveller is here!"); 

    }
}

below is the rest of the relevant code

private Room currentRoom;

private void createRooms() 
{
    Room outside, theatre, pub, lab, office, up, down;

    // create the rooms
    outside = new Room("outside the main entrance of the university");
    theatre = new Room("in a lecture theatre");
    pub = new Room("in the campus pub");
    lab = new Room("in a computing lab");
    office = new Room("in the computing admin office");
    up = new Room("creepy upstairs");
    down = new Room("spooky downstairs");

    // initialise room exits
    outside.setExit("north", lab);
  //  outside.item.addItem("Gun", 10);
    outside.setExit("down", down);
    outside.setExit("up", up);
    outside.setExit("west", pub);
    outside.setExit("east", office);

    down.setExit("north", outside);
   // down.item.addItem("book", 1);
    up.setExit("south", outside);
    // up.item.addItem("knife", 5);

    lab.setExit("east", office);
    lab.setExit("south", outside);
    lab.setExit("north", theatre);
    // lab.item.addItem("bomb", 10);

    office.setExit("south", lab);
    // office.item.addItem("key", 0);

    pub.setExit("east", theatre);
    pub.setExit("south", outside);
    // pub.item.addItem("beer", 2);

    theatre.setExit("south", outside);
    currentRoom = outside;  // start game outside
}

    private void printWelcome() 
{
    System.out.println();
    System.out.println("Welcome to the World of Zuul!");
    System.out.println("World of Zuul is a new, incredibly boring adventure game.");
    System.out.println("Type 'help' if you need help.");
    System.out.println();
    System.out.println(currentRoom.getLongDescription());

    if (currentRoom = outside || pub);
    {
        System.out.println("A friendly traveller is here!"); 

    }
}

im literally just trying to make it so that if the players room is either outside, or the pub, then to print a message. However it's not working, any guidance is really appreciated. Im sure this is a really dumb question to ask but im new and i dont understand why its not working

Aucun commentaire:

Enregistrer un commentaire