![]() |
Buddy Game
Starting a game for my Java class but having trouble getting it going. Any code or help would be awesome.
Buddy Caretaker Create a game that instantiates a buddy that may be a pet, creature, car, plant, etc. You need to select a type of buddy and at least five properties of at least three different types. The game must include at least three different activities that you can do with your buddy (example: Cat – feed, pet, clean litter box). There needs to a point system that determines the well-being of your buddy. (example: 5 – points for feeding, 1 – for petting and negative 5 – for cleaning the litter box) The needs to be a method to determine the wellbeing of your buddy (example: Good if points are between -3 and 3, poor if the points are between -6 and 6 and not Good, and dead if less than -6 or more then 6.) The game should continuously ask the user which activity the user wants to perform. The activities must be listed including a sentinel value. After each activity, the program needs to display the wellbeing of the buddy. This should continue until the buddy dies or the sentinel value is entered. Example: Buddy Caretaker What is your buddies name: Ily Do you want to (F)eed Ily, (P)et Ily, (C)lean Ily’s litter box, or (G)o to bed? F Buddy is Feeling Poor Do you want to (F)eed Ily, (P)et Ily, (C)lean Ily’s litter box, or (G)o to bed? C Buddy is Feeling Good Do you want to (F)eed Ily, (P)et Ily, (C)lean Ily’s litter box, or (G)o to bed? C Buddy is Feeling Poor Do you want to (F)eed Ily, (P)et Ily, (C)lean Ily’s litter box, or (G)o to bed? C Buddy is Feeling Dead |
This one will be somewhat tricky to give advice since its a school assignment and I don't know what it is that you know.
Now does the instructions indicate that you are allowed/have to to make multiple different types of buddies? Can you choose between a cat, a car, a shovel, etc? Or is it just one type? If you are to make multiple that the user can select, I'd suggest that Buddy be an interface for simplicity. If its only the one, then you can simply create a single class for Buddy. Next, you have a class Activity. This class will contain a field for the condition change amount as well as a description of it. Set these during the constructor and allow it the accessor methods it needs. Mutators are optional. Buddy properties will include: name, condition, and activities. Activities can be an Activity[], a Collection<Activity>, or individual properties (activity1, activity2, etc). If you can't think up any other properties to give it, separate activities will fulfill the requirements of 5 properties and 3 different datatypes (string, int, activity, activity, activity), but does complicate the code when needing to check on stuff. I'd suggest a collection or array for that, and make up some other stuff. Easy if you can only create one type of buddy, you can give your cat a fur colour, a breed, eye colour, whatever. But if you can take many different types, its a bit trickier since there is no real way to enforce it (my shovel will have a brand, a type/design, a material, etc). Come back if you run into problems with making these. btw, right now I suggest you make a shovel buddy. Seriously. Points for creativity. |
hahaha. Loving the shovel idea! Also thank you for spending the time to reply. The assignment only calls for one type buddy and its only a first semester course so we haven't gotten into arrays yet. I'll start tinkering with some code and post what I come up with tomorrow.
|
Ok. I got some of the basic code done but I am having trouble with some of the harder concepts. 1. How am I going to make it so when the user enters the first letter of the corresponding activity it will run that activity. 2. How to associate a points system that returns the correct condition of the buddy. I apologize, my java skills are quite noob.
package shovelbuddy; import java.util.Scanner; /** * * @author SKelnhofer */ public class ShovelBuddy { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Please enter a name for you shovel"); String name = keyboard.nextLine(); System.out.println("Do you want to" + Pet + name); Activity theActivity = new Activity(Pet, Sleep, Dig, Feed, Clean); } } package shovelbuddy; /** * * @author SKelnhofer */ public class Activity { private String Pet; private String Sleep; private String Dig; private String Feed; private String Clean; private int Health; public Activity(String Pet, String Sleep, String Dig, String Feed, String Clean, int Health) { this.Pet = Pet; this.Sleep = Sleep; this.Dig = Dig; this.Feed = Feed; this.Clean = Clean; this.Health = Health; } public String getPet() { return Pet; } public void setPet(String Pet) { this.Pet = Pet; } public String getSleep() { return Sleep; } public void setSleep(String Sleep) { this.Sleep = Sleep; } public String getDig() { return Dig; } public void setDig(String Dig) { this.Dig = Dig; } public String getFeed() { return Feed; } public void setFeed(String Feed) { this.Feed = Feed; } public String getClean() { return Clean; } public void setClean(String Clean) { this.Clean = Clean; } } |
Activity base definition like so:
PHP Code:
Also, in the future please wrap code with [php][/php] or [code][/code] tags as it preserves the formatting. Activity wise, I wouldn't pet or sleep my shovel. I'd store and. . . stroke it. lol. Edit: Actually, noting the phrases used here for the activities, make activity like so: PHP Code:
|
Still messing with this. What I am trying to do is start health off at 3 then based on the users input subtract or add the corresponding number. Then check to see what range health is in and display its condition. health< 0 = dead, health 1-3 sick, health 3-5 ok, health 5-7 too good, health>7 dead.
Code:
public class ShovelBuddy { |
No, this isn't correct. Look back at the requirements; the buddy requires at least 5 properties and at least three datatypes. Buddy would contain a name, condition and Activity items.
Activity itself should just be a shell. I can think of a dozen ways to accomplish this task, but the absolute minimum for Activity would be a name of the activity and the amount it modifies condition by. The name would include any specific buddy information during construction such as the name and passed to the constructor for Activity. Take all the weight off of Activity and put it into buddy. |
| All times are GMT +1. The time now is 08:18 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.