This site requires JavaScript, please enable it in your browser!
Greenfoot back
sun12
sun12 wrote ...

2015/3/29

Can someone help me with my game?

sun12 sun12

2015/3/29

#
How do you List<Ingredient> preferences
danpost danpost

2015/3/29

#
sun12 wrote...
How do you List<Ingredient> preferences
That is quite vague. I you really want an answer to that, then (1) import the java.util.List and java.util.ArrayList classes (2) define your field 'private List<Ingredient> preferences;' (3) create the preferences List object 'preferences = new ArrayList<Ingredients>();' and (4) add Ingredient objects to the list -- 'preferences.add(new Ingredient(...));'
sun12 sun12

2015/3/29

#
My game is a diner dasher game where a customer orders and you have to catch the right ingredients. How do you make the computer check if the burger is what the customer ordered
danpost danpost

2015/3/29

#
Have the Ingredient class get (by way of the constructor call), use for image filename (within the constructor), and saved in a field (by the constructor) for returning (using getter method) the string that represents which ingredient each object created from the class is. Then outside the Ingredient class, have two lists of strings, one for what was ordered and one for what was caught, and compare the size and contents of the sorted lists for success.
sun12 sun12

2015/4/2

#
What code would I have to write
danpost danpost

2015/4/2

#
sun12 wrote...
What code would I have to write
It would be similar to how the keys get their images in the Piano scenario (as far as getting the String and saving it) and similar to how a value is returned from a Counter class (as far as a getter method -- except it will return a String value instead of an int value).
sun12 sun12

2015/4/2

#
public void setRandomPref() { prefs = new ArrayList<Ingredient>(); int amt = (int)(Math.random()*3) + 4; for(int i =0; i < amt; i++) { prefs.add(new Mustard()); prefs.add(new Lettuce()); prefs.add(new Tomato()); prefs.add(new TopBun()); prefs.add(new Onions()); prefs.add(new Patty()); prefs.add(new Ketchup()); } } public void setOrder() { for(Ingredient i : prefs) { order += i + ", "; } } public void makeOrder() { GreenfootImage o = new GreenfootImage(WIDTH,HEIGHT); o.setColor(bckg); o.fill(); o.setColor(ink); Font f = o.getFont(); f = f.deriveFont(FONT_SIZE); o.setFont(f); String s = order + " "; o.drawString(s,10,30); setImage(o); } I created this code, but why is it not creating a random customer preference
danpost danpost

2015/4/2

#
First, your 'for' loop will add all seven items to the list repeatedly from between 4 to 6 times (meaning the list will be either 28, 35 or 42 in size with each ingredient in the list 4, 5 or 6 times). I really do not think that is what you wanted to do there. You should probably start with an ingredients list (with only one occurrence of each in the list), then get a random number (between 4 and 6 if desired) for the number of order prefs. Then you can use a 'for' loop to iterate that number of times to build a new prefs list by pulling a random selection from the ingredients list and adding it to the prefs list. Because you only show bits and pieces of the class, I cannot say much else about the way the class is coded. Except for that it looks like your 'setOrder' method will not do what may think it will. The way it is coded, it will create (presuming that 'order' is a declared String field since you are assigning a String value to it) memory address references (unless you wrote some 'toString' methods in your Ingredient subclasses).
sun12 sun12

2015/4/4

#
HOw would I make my ingredients stack on top of each other
danpost danpost

2015/4/4

#
sun12 wrote...
HOw would I make my ingredients stack on top of each other
You can use a 'for' loop to iterate through the prefs list and add them into the world with descending y-coordinate locations.
sun12 sun12

2015/4/4

#
What code would you write to do that
Super_Hippo Super_Hippo

2015/4/4

#
Change numbers to your needs.
int dy = 0;
for (Ingredient i : pref)
{
    addObject(i, 100, 200+dy);
    dy += 20;
}
sun12 sun12

2015/4/5

#
public void stack() { Actor a = getOneIntersectingObject(Ingredient.class); if ((a != null) ) { System.out.println(((Ingredient)a).name); //getWorld().addObject(a, this.getX()-50, this.getY()); //if (stackW != 1) Ingredient x = new Ingredient(((Ingredient)a).name); getWorld().removeObject(a); getWorld().addObject(new Ingredient("Tomato"),50,50); { getWorld().addObject(x, this.getX()-50, this.getY()+10); getWorld().removeObject(a); stackW=1; System.out.println(stackW); } } I wrote this code to do that, but all this code does is add the Ingredient to the Chef. Then if an ingredient fall on top another ingredient, then it switches with the ingredient that is already there. How would I fix this
You need to login to post a reply.