A Game (HW Help)

Discussion in 'Programming General' started by Glyder, Nov 29, 2010.

A Game (HW Help)
  1. Unread #1 - Nov 29, 2010 at 4:49 PM
  2. Glyder
    Joined:
    Sep 6, 2009
    Posts:
    527
    Referrals:
    5
    Sythe Gold:
    0

    Glyder Forum Addict

    A Game (HW Help)

    Basically what I have to do, is make a program that simulates a kingdom. The assignment and pre-code is in the quotes below. What I want to know is how can
    I make the game do what I want, while changing, or adding the "TODO" sections (they are in the comments.) My knowledge in Java is a bit bare
    at the moment due to, well some of this we haven't gone over.

    Any help is much appreciated.

     
  3. Unread #2 - Nov 29, 2010 at 8:45 PM
  4. pkwithpink
    Joined:
    Nov 14, 2008
    Posts:
    770
    Referrals:
    0
    Sythe Gold:
    0

    pkwithpink Apprentice
    Banned

    A Game (HW Help)

    Wow that is an awesome assignment I might go ahead and do this one just for fun :).

    To answer your question all you do is have System.out.print asking how many bushels to use as food, how many to plant and how many to store. Then from there all you do is use simple formulas to decide what happens.

    If the user allocates say 2000 bushels for food, 500 to store, and 1500 to plant you run that through each method, 2000 bushes / 100 people = 20 bushels per person, population does not change. 1500 bushels / 2 = 750 acres of grain

    you would then simply call for the random int function to generate a number between 2-6 and multiply that by acres. So say 6 * 750 = 4,500 bushels of grain. then add the other grain you stored and now you have 5k bushels of corn and repeat.

    Very simple but very cool game. You didn't mentions specifically what you needed help with, but again this is just such an awesome project to take on.
     
  5. Unread #3 - Nov 30, 2010 at 12:13 AM
  6. Glyder
    Joined:
    Sep 6, 2009
    Posts:
    527
    Referrals:
    5
    Sythe Gold:
    0

    Glyder Forum Addict

    A Game (HW Help)

    I understand what you mean, but I forgot to mention, we are using GUI's, to ask like,
    "How many" and what-not.
     
  7. Unread #4 - Nov 30, 2010 at 9:19 PM
  8. pkwithpink
    Joined:
    Nov 14, 2008
    Posts:
    770
    Referrals:
    0
    Sythe Gold:
    0

    pkwithpink Apprentice
    Banned

    A Game (HW Help)

    Well how extensive does the GUI have to be? If you just need to gather info you could use the Joptionpane, if you have been specified to use the swing class to create a GUI then you should try reading up on some java docs if you can write out specifically what needs to be on the GUI I could possibly write up some quick code for a GUI for what you need.
     
  9. Unread #5 - Dec 1, 2010 at 9:41 AM
  10. Glyder
    Joined:
    Sep 6, 2009
    Posts:
    527
    Referrals:
    5
    Sythe Gold:
    0

    Glyder Forum Addict

    A Game (HW Help)

    Not very extensive, if you look at the code I provided before, the "TODO" comments are what I have to add to finish the assignment.

    I just need to have the GUI to enter and "calculate" what I need.
     
  11. Unread #6 - Dec 1, 2010 at 10:10 AM
  12. Glyder
    Joined:
    Sep 6, 2009
    Posts:
    527
    Referrals:
    5
    Sythe Gold:
    0

    Glyder Forum Addict

    A Game (HW Help)

    While working on adding ints and stuff, I came across this.

    Code:
        public void simulateOneYear(int food, int seed) {
    
            //TODO: Need to calculate new population based on food.
            myPopulation = food / FOOD_REQUIRED_PER_PERSON;
    
            //Reduce grain stockpile by amount used for food and seed
            myGrain = myGrain - food - seed;
    If "myPopulation" doesn't show up in the year simulation, I get the return "0" as my status.

    But in the -
    Code:
    public void simulateOneYear(int food, int seed)
    I see food and grain, but in both Java files, I don't see the conversion from "grain" to "seed" and "food",
    how can I add the population to the ints so that I do not get the return "0" in the status?




    This might help too.
    Code:
        private int myGrain = 4000; // Bushels of grain in storage.
        
        private int myArea  = 1500; // Area of kingdom in acres.  Note that
                                    // myArea isn't used yet, but will be if
                                    // you add a check for the total amount
                                    // of land that can be planted.
        
        private int myYear  = 0;    // Years since founding of kingdom.
        
        private int myHarvest = 0;  // Last harvest in bushels.
        
        private int myPopulation = 100; //First test for population.
    Code:
        //============================================================ getPopulation
        public int getPopulation() {
            return myPopulation;
        }
    
    (GUI for Status is this code as it seems.)
    Code:
        //=========================================================== toString
        public String toString() {
            // TODO: Don't forget to add population here too. (Done)
            return "Kingdom status at year " + myYear
                   + ", last harvest = " + myHarvest
                   + ", total grain = " + myGrain
                   + ", current population = " + myPopulation;
        }
    (The last one, FOOD_REQUIRED_PER_PERSON, is what each person gets from grain.)
    Code:
        private final static int MIN_GRAIN_TO_SURVIVE = 20;
        private final static int MAX_LAND_FARMABLE_PER_PERSON = 15;
        private final static int SEED_REQUIRED_PER_ACRE = 2;
        private final static int FOOD_REQUIRED_PER_PERSON = 20;
    Anybody got ideas?
     
  13. Unread #7 - Dec 1, 2010 at 8:39 PM
  14. Fate1
    Joined:
    Apr 21, 2005
    Posts:
    773
    Referrals:
    2
    Sythe Gold:
    5

    Fate1 Apprentice
    Banned

    A Game (HW Help)

    If I understand you correctly when you run the program your population returns a 0. Well from what I can see from your code you need to
    Code:
    //TODO: Ask the ruler how much to feed the people.
                int food = 0;  // Temporary substitute for asking for input.
    Since the food is 0 and you use the equation
    Code:
    myPopulaton = food / FOOD__REQUIRED_PER_PERSON;
    It is dividing 0 by 20 which equals 0.
     
  15. Unread #8 - Dec 2, 2010 at 1:00 AM
  16. pkwithpink
    Joined:
    Nov 14, 2008
    Posts:
    770
    Referrals:
    0
    Sythe Gold:
    0

    pkwithpink Apprentice
    Banned

    A Game (HW Help)

    Once you get input and ask for a value (since the 0 is a placeholder) you should not be getting a 0 for the population.

    I will write up a GUI later on today.
     
< What Version Do You Use? | Win32 Pong Game >

Users viewing this thread
1 guest


 
 
Adblock breaks this site