Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:23+00:00 2026-06-12T19:09:23+00:00

I really don’t understand the principle of Object Oriented Design?? So I have classes

  • 0

I really don’t understand the principle of Object Oriented Design??
So I have classes

Map class holds rooms and connects all of rooms , places all of hazards randomly into rooms, return the particulate room, and return the random rooms.

and

Player class that play turns, move player from room to another, shoot into rooms and play games.

also

Room class as follow.

import java.util.ArrayList;

public class Room
{
    private int myRoomID;
    private ArrayList<Room> myNeighbours;

    private boolean myHasBats;
    private boolean myHasPit;
    private boolean myHasWumpus;

    public Room(int id) {
        myRoomID = id; 
        myNeighbours = new ArrayList<Room>();
    }

    public int getRoomID() {
        return myRoomID;
    }

    public ArrayList<Room> getNeighbours() {
        return myNeighbours;
    }

    public void connectTo(Room room) {
        myNeighbours.add(room);
    }    

    public boolean hasBats() {
        return myHasBats;
    }

    public void setHasBats(boolean flag) {
        myHasBats = flag;
    }

    public boolean hasPit() {
        return myHasPit;
    }

    public void setHasPit(boolean flag) {
        myHasPit = flag;
    }

    public boolean hasWumpus() {
        return myHasWumpus;
    }

    public void setHasWumpus(boolean flag) {
        myHasWumpus = flag;
    }

    public void checkBats() {
        boolean bats = false;
        for (Room r : myNeighbours) {
            if (r.hasBats()) {
                bats = true;
            }
        }
        if (bats) {
            System.out.println("I hear squeaking!");
        }
    }

    public void checkPit() {
        boolean pit = false;
        for (Room r : myNeighbours) {
            if (r.hasPit()) {
                pit = true;
            }
        }
        if (pit) {
            System.out.println("I feel a draft!");
        }
    }

    public void checkWumpus() {
        boolean wumpus = false;
        for (Room r : myNeighbours) {
            if (r.hasWumpus()) {
                wumpus = true;
            }
        }
        if (wumpus) {
            System.out.println("I smell a wumpus!");
        }
    }

    public boolean enter(Player player) {
        System.out.println("You are in Room " + myRoomID);
        System.out.print("Exits lead to rooms");

        for (Room r : myNeighbours) {
            System.out.print(" " + r.getRoomID());
        }
        System.out.println();
        checkBats();
        checkPit();
        checkWumpus();

        if (myHasBats) {
            System.out.println("A flock of bats picks you up and carries you off to another room!");
            return player.moveRandom();
        }
        else if (myHasPit) {
            System.out.println("You fall into a bottomless pit!");
            return true;
        }
        else if (myHasWumpus) {
            System.out.println("You have been eaten by a wumpus!");            
            return true;
        }

        return false;
    }

public boolean shoot()


        if (myHasWumpus) {

            System.out.println("You killed the Wumpus!");

            return true;


        }
        else {

            System.out.println("Your arrow falls with a clatter to the floor!");

            return false;


        }

    }

And I want to change this so that the wumpus needs to be shot more than once (you choose how many times) to be killed. Each time it is shot it runs to a random neighbouring room (not the one the player is in).

I am assuming that I need to change public boolean shoot() method into loop and call public Room getRandomRoom() as below.

But I really don’t understand how to do this, especially because the use of boolean method is very confusing to me.
Does anyone know where I can find a information to learn the basic’s of Object Oriented Design?

    public Room getRandomRoom() {

        Random rng = new Random();

        int i = rng.nextInt(Map.NUM_ROOMS);  

        return myRooms.get(i);

  }

Later on we are going to use implements in the class to separate all of hazards into classes. but for not they are all in Map and Room class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:09:24+00:00Added an answer on June 12, 2026 at 7:09 pm

    Well without a wumpus class that’s going to be messy and limited and even more inefficient. Your problem isn’t that you don’t get OO, it’s that you are being restricted from using it.

    Without out the class.
    You are goingto have to add a myWumpusShotCount to room
    Then in your shoot function, add 1 to it, test to see if it’s 3 and if so kill it else random choose a room and set hasWumpus and WumpusShotCount in it

    If you had a wumpus class it would have a property room , and another for how many bullets it had shipped and a behaviour when shot, ie the state of the wumpus and the behaviours of wumpus would be implemented by wumpus, not room. That’s OO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really don't understand this. I have a simple ASP with 3 div in
I really don't understand how a class like HttpContext.Current is visible (for the single
I really don't understand regular expressions and was wondering what the following regular expressions
As a developer I really don't like writing documentation but when I have to
Sorry for unclear subject but i really don't understand where problem. I use a
There is something that I really don't understand with the HttpListener. The code below
I'm stuck on a problem I really don't know how to solve: I have
I really don't like this style of formatting: Class AwesomeClass { private static void
I have been roaming the internet for a solution I really don't know what
I really don't understand why do we need to create channel.html file, as mentioned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.