Page 1 of 2 12 LastLast
Results 1 to 20 of 32

Thread: Help!

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

    Default Help!

    Soo basically my task was to make a game and i need help using the constructor to set all the rooms i need for my game, the game requires 10 rooms.

    the error message is as follows

    "Constructor Dimension cannot be applied to given type;
    required: no arguments
    found: java.lang.string
    reason: actual and formal argument lists differ in length

    the operator that you use here cannot be used for the type of value that you are using it for.
    You are either using the wrong type here, or using the wrong operator."

    I have put the code that does not compile in red
    Here is the code that does not compile:


    public class Game
    {
    private Parser parser;
    private Dimension Dimension1, Dimension2, Dimension3, Dimension4, Dimension5, Dimension6, Dimension7, Dimension8, Dimension9, Dimension10;
    private Player player = new Player(" ");
    private Items Axe, Chain, Hammer, Shoulderblade, Helmet, Shinpads, Pole, Shield;
    /**
    * Create the game and initialise its internal map.
    */
    public Game()
    {
    createDimension();
    parser = new Parser();
    }

    /**
    * Create all the rooms and link their exits together.
    */
    private void createDimension()
    {
    Dimension1 = new Dimension("1st Dimension");
    Dimension2 = new Dimension("2nd Dimension");
    Dimension3 = new Dimension("3rd Dimension");
    Dimension4 = new Dimension("4th Dimension");
    Dimension5 = new Dimension("5th Dimension");
    Dimension6 = new Dimension("6th Dimension");
    Dimension7 = new Dimension("7th Dimension");
    Dimension8 = new Dimension("8th Dimension");
    Dimension9 = new Dimension("9th Dimension");
    Dimension10 = new Dimension("Last Dimension");

    Axe = new Items("Axe",5);
    Chain = new Items("Chain",5);
    Hammer = new Items("Hammer",5);
    Shoulderblade = new Items("Shoulderblade",5);
    Helmet = new Items("Helmet",5);
    Shinpads = new Items("Shinpads",5);
    Pole = new Items("Pole",5);
    Shield = new Items("Shield",5);

    // 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);


    player.setDimension(Dimension1);

    Dimension1.addToRoom("3 Zombies");
    Dimension2.addToRoom("5 Zombies");
    Dimension3.addToRoom("6 Zombies");
    Dimension4.addToRoom("8 Zombies");
    Dimension5.addToRoom("10 Zombies");
    Dimension6.addToRoom("11 Zombies");
    Dimension7.addToRoom("13 Zombies");
    Dimension8.addToRoom("15 Zombies");
    Dimension9.addToRoom("16 Zombies");
    Dimension10.addToRoom("Boss");

    Dimension1.addItem(Shield, Axe, Hammer);
    Dimension2.addItem(Pole, Chain, Shoulderblade);
    Dimension3.addItem(Shinpads, Hammer, Chain);
    Dimension4.addItem(Helmet, Pole, Axe);
    Dimension5.addItem(Chain, Shoulderblade, Hammer);
    Dimension6.addItem(Axe, pole, Helmet);
    Dimension7.addItem(pole, Axe, shield);
    Dimension8.addItem(shield, Chain, Hammer);
    Dimension9.addItem(chain, Shoulderblade, Pole);
    Dimension10.addItem(Sword);
    }

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

    Default Re: Help!

    you don't have a Dimension Constructor that takes a String as an argument. Create one of those and you will be fine.

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

    Default Re: Help!

    im very new to java do you think you could help me a little with the coding

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

    Default Re: Help!

    you need a dimension Class or something similar so you can say

    Java Code:
    public Class Dimension {
    
    private String dimensionStatus;
    
    public Dimension(String s){
    
    dimensionStatus = s;
    
    }
    
    }
    Last edited by monkeyjr97; 05-08-2013 at 07:03 PM.

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

    Default Re: Help!

    Where exactly do i need to place the code sorry?

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

    Default Re: Help!

    i already have another class called Dimension, which is used for the rooms

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

    Default Re: Help!

    i cant change this name of this class i must keep it the same, i think this is where the confusion occured

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

    Default Re: Help!

    you keep the class you have, just add:

    private String dimensionStatus;

    public Dimension(String s){

    dimensionStatus = s;

    }

    to your Dimension Class.
    Last edited by monkeyjr97; 05-08-2013 at 07:03 PM.

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

    Default Re: Help!

    hmmm do you have skype or something? i think i need a better explanation

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

    Default Re: Help!

    ive added the code and its working but now im havin the same problem with .addItem

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default Re: Help!

    Quote Originally Posted by Snizz View Post
    ive added the code and its working but now im havin the same problem with .addItem
    If you copied the code from reply #8 I find it strange that it works because that code is utterly incorrect (it assigns a member variable to a parameter instead of vice versa).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: Help!

    ye my bad on that, simply wrote them the wrong way round, i have a habbit of that :/ updated above posts.

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

    Default Re: Help!

    Lol as long as its working it doesnt bother me, my .addItems is giving me the same problem do u think u could help JosAH? id Really appreciate it as its very urgent (N)

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

    Default Re: Help!

    look at my edited code and replace yours with that.

    It sounds like you dont have an addItem method, you need to create one of those as well:

    looks to me that addItem takes 3 Item Objects as parameters:

    Java Code:
    public void addItem(Item a, Item b, Item c) {
    
    //you fill this in
    
    }

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

    Default Re: Help!

    its still not working and its coming up with the same error message, heres how i edited the code:
    public void addItem()
    {
    Dimension1.addItem(Shield, Axe, Hammer);
    Dimension2.addItem(Pole, Chain, Shoulderblade);
    Dimension3.addItem(Shinpads, Hammer, Chain);
    Dimension4.addItem(Helmet, Pole, Axe);
    Dimension5.addItem(Chain, Shoulderblade, Hammer);
    Dimension6.addItem(Axe, pole, Helmet);
    Dimension7.addItem(pole, Axe, shield);
    Dimension8.addItem(shield, Chain, Hammer);
    Dimension9.addItem(chain, Shoulderblade, Pole);
    Dimension10.addItem(Sword);
    }


    do you wish to have a look at the rest of the code ? maybe that may help, ive tired created new classes aswell

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

    Default Re: Help!

    even if i try and declare it in the dimension class it tells me that it cannot find the symbol for item

    public void addItem(Item a, Item b, Item c)
    {
    item.add(a, b, c);
    }

    any ideas ????

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

    Default Re: Help!

    You have to import your class 'item' at the top of the Dimension class.

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

    Default Re: Help!

    this way an error message comes up with:
    no suitable method found for add

    public void addItem(String a, String b, String c)
    {
    item.add();
    }

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

    Default Re: Help!

    Quote Originally Posted by jbarke12 View Post
    You have to import your class 'item' at the top of the Dimension class.
    i have its still not working and ive also put it into an Array because my player should be able to hold more than one item at once

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

    Default Re: Help!

    in your Dimension class you need to have an
    Java Code:
    private ArrayList<Items> items;
    in your constructor you need:
    Java Code:
    items= new ArrayList<>();
    and in your add Item
    Java Code:
    public void addItem(Items i1, Items i2, Items i3){
    items.add(i1);
    items.add(i2);
    //dont forget to add item number 3
    }
    You are passing Items in not Strings if you look at your main class.

Page 1 of 2 12 LastLast

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
  •