Page 2 of 2 FirstFirst 12
Results 21 to 32 of 32

Thread: Help!

  1. #21
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    78
    Rep Power
    0

    Default Re: Help!

    You will also need to have another addItem() method with only one item as a parameter.

  2. #22
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    This is what i have done:

    public void addItem(Items Shield, Items Pole, Items Chain, Items Axe, Items Hammer, Items Shoulderblade, Items Helmet, Items Sword)
    {
    items= new ArrayList<>();
    items.add(Pole);
    items.add(Chain);
    items.add(Axe);
    items.add(Hammer);
    items.add(Shoulderblade);
    items.add(Helmet);
    items.add(Sword);
    items.add(Shield);
    }

    Yet it styll comes up wid an error in the main game class for the add.Item

  3. #23
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    78
    Rep Power
    0

    Default Re: Help!

    I think you're misunderstand the concept of calling a method. In your main class you are calling addItem with 3 parameters, and with 1 parameter. The method and its signature has to match the call to it. Therefore you need to addItem methods: 1 with 3 parameters, and one with one parameter. ie
    Java Code:
    public void addItem(Items i1, Items i2, Items i3){
    //write code here to add the 3 items to items.
    }
    
    public void addItem(Items i1){
    //write code here to add the 1 item to items.
    }

  4. #24
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    and what should i put in the Items as because i cant choose one item otherwise the rest wont work in the main Game class and it will cum up wid the origianl error message, please add me on skype as i think it would be easier for us to communicate
    and im very desperate to finish this today or im "Doomed"
    Skype : don-ellz
    if you do not have skype my mobile number is 07931233558

  5. #25
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    78
    Rep Power
    0

    Default Re: Help!

    You put both add Item methods in. They have different signatures therefore you shouldn't have an issue. This is called overloading the method.
    Last edited by jbarke12; 05-08-2013 at 09:33 PM.

  6. #26
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    Your right ive fixed that but now, my exits are playin up:

    // room exits
    Dimension1.setExit("forward", Dimension2);
    Dimension2.setExit("forward", Dimension3);
    Dimension3.setExit("forward", Dimension4);
    Dimension4.setExit("forward", Dimension5);
    Dimension6.setExit("forward", Dimension7);
    Dimension7.setExit("forward", Dimension8);
    Dimension8.setExit("forward", Dimension9);
    Dimension9.setExit("forward", Dimension10);

  7. #27
    jbarke12 is offline Member
    Join Date
    May 2013
    Location
    Charleston, South Carolina USA
    Posts
    78
    Rep Power
    0

    Default Re: Help!

    well in dimensions you need a method called setExit
    Java Code:
    public void setExit(String s, Dimensions d){
    //do your code here to set the Exit.  I don't know what that is without more info
    }
    Notice the method signature is the same as the signature of the call in main.

  8. #28
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    im trying to create a method in my dimensions class but i keep getting this error code: missing method body or declare abstract

    Heres my code:

    public void setExit(String s, Dimension d);
    {
    Dimension1.setExit("forward", Dimension2);
    Dimension2.setExit("forward", Dimension3);
    Dimension3.setExit("forward", Dimension4);
    Dimension4.setExit("forward", Dimension5);
    Dimension6.setExit("forward", Dimension7);
    Dimension7.setExit("forward", Dimension8);
    Dimension8.setExit("forward", Dimension9);
    Dimension9.setExit("forward", Dimension10);
    }

  9. #29
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    Ive decided to let u have a look at the whole code as im sure new problems will arise, im going to continue to try and figure this thing out but if u come up with anyting please dont hesitate to let me kno ive got to hand it in by 11:30, so as i sed b4 im very desperate.

    import java.util.Set;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.*;

    /**
    * Elliott Nunoo
    */
    public class Dimension
    {
    private String dimensionStatus;
    private String description;
    private HashMap<String, Dimension> exits; // stores exits of this room.
    private String Zombie = "";
    private ArrayList<Items> items;
    private String Item;

    /**
    * Create a room described "description". Initially, it has
    * no exits. "description" is something like "a kitchen" or
    * "an open court yard".
    * @param description The room's description.
    */
    //public void setExit(String direction, Dimension neighbor)
    //{
    //exits.put(direction, neighbor);
    //}

    public Dimension(String s)
    {
    s = dimensionStatus;
    }

    public void Dimension(String description)
    {
    this.description = description;
    exits = new HashMap<String, Dimension>();
    }

    /**
    * Define an exit from this room.
    * @param direction The direction of the exit.
    * @param neighbor The room to which the exit leads.
    */

    /**
    * @return The short description of the room
    * (the one that was defined in the constructor).
    */
    public String getShortDescription()
    {
    return description;
    }

    /**
    * Return a description of the room in the form:
    * You are in the kitchen.
    * Exits: north west
    * @return A long description of this room
    */

    public String getLongDescription()
    {
    return "You are " + description + ".\n" + getExitString();
    }

    public void setExit();
    {
    Dimension1.setExit("forward", Dimension2);
    Dimension2.setExit("forward", Dimension3);
    Dimension3.setExit("forward", Dimension4);
    Dimension4.setExit("forward", Dimension5);
    Dimension6.setExit("forward", Dimension7);
    Dimension7.setExit("forward", Dimension8);
    Dimension8.setExit("forward", Dimension9);
    Dimension9.setExit("forward", Dimension10);
    }

    /**
    * Return a string describing the room's exits, for example
    * "Exits: north west".
    * @return Details of the room's exits.
    */
    private String getExitString()
    {
    String returnString = "Exits:";
    Set<String> keys = exits.keySet();
    for(String exit : keys) {
    returnString += " " + exit;
    }
    return returnString;
    }

    /**
    * Return the room that is reached if we go from this room in direction
    * "direction". If there is no room in that direction, return null.
    * @param direction The exit's direction.
    * @return The room in the given direction.
    */
    public Dimension getExit(String direction)
    {
    return exits.get(direction);
    }

    public void addToRoom(String r)
    {
    Zombie = r;
    }

    public void removeFromRoom()
    {
    Zombie = "";
    }

    public void addItem(Items Shield, Items Pole, Items Chain, Items Axe, Items Hammer, Items Shoulderblade, Items Helmet, Items Sword)
    {
    items= new ArrayList<>();
    items.add(Pole);
    items.add(Chain);
    items.add(Axe);
    items.add(Hammer);
    items.add(Shoulderblade);
    items.add(Helmet);
    items.add(Sword);
    items.add(Shield);
    }

    public void addItem(Items Pole)
    {
    items.add(Pole);
    }

    public boolean hasItem()
    {
    if (!items.isEmpty())
    {
    return true;
    }
    return false;
    }

    public boolean isItem(String i)
    {
    for (Items it:items)
    {
    if (it.getName().equals(i))
    {
    return true;
    }
    }
    return false;
    }

    public Items returnItems(String r)
    {
    for (Items it:items)
    {
    if(it.getName().equals(r))
    {
    return it;
    }
    }
    return null;
    }

    }

  10. #30
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Help!

    java is an OO language. Most of the time Links between Classes will be Object references not strings.

  11. #31
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help!

    Im not sure what u mean ?

  12. #32
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default Re: Help!

    Java Code:
    public void setExit(String s, Dimension d);
    {
    Dimension1.setExit("forward", Dimension2);
    Dimension2.setExit("forward", Dimension3);
    Dimension3.setExit("forward", Dimension4);
    Dimension4.setExit("forward", Dimension5);
    Dimension6.setExit("forward", Dimension7);
    Dimension7.setExit("forward", Dimension8);
    Dimension8.setExit("forward", Dimension9);
    Dimension9.setExit("forward", Dimension10);
    }
    This does nothing.
    Java Code:
    public void setExit(String s, Dimension d);
    Notice the parameters are a String, and a Dimension Object. You are calling the setExit method inside the setExit method itself!

    you need 2 variables in your dimension Class
    Java Code:
    private String direction;
    
    private Dimension exitDimension;
    then
    Java Code:
    public void setExit(String s, Dimension d);
    
    this.direction = s;
    
    this.exitDimension = d;
    
    }
    You might need to edit that to suit your code, but you cant call the method inside itself, the parameters are there for a reason use them!

    If you dont understand this very basic concept in Java, you should start looking up tutorials.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •