0

I am currently making a game that takes place over 10 days in senior year. I created an intro to this game but I am unsure of how to put it all together. Should I have the intro be the parent class and have different subclasses for each day? Here is my code so far.

package SeniorGame;

import java.util.Scanner;

public class Intro{ 
    public static void main (String[]args){
    Scanner sc = new Scanner(System.in);

    System.out.println("Before the game begins I need to know a few things about yourself.");
    System.out.println();

    String name;
    System.out.println("What is your name? ");
    name=sc.next();

    String crush;
    System.out.println("Who was your High School crush? ");
    crush=sc.next();

    String bfriend;
    System.out.println("Who was your best friend in High School? ");
    bfriend=sc.next();

    System.out.println();
    System.out.println();

    System.out.println("This is a story that consits of 12 days in your senior year of High School.\n"
            + "The days are spread out from the beginning to the end of the year.\nThe choices you make"
            + " will impact the way your story plays out.");
}

}

  • `extends` refines behavior and is used in "is-a" relations (banana is-a fruit). Are your days in that relation to the intro? – zapl Jun 07 '16 at 20:38
  • technically not the intro is a stand alone thing. if that makes sense. from the intro you will be promoted with a game menu to either play or quit. if you quit the system.quit(1) line triggers but if not you obviously play the game. My question is how do I start day one from here. Do I make day one in a seperate class or seperate method. – Jack Mccarty Jun 07 '16 at 20:47
  • I would make each day inherit from a Day class. Have an outside class handle the logic of moving from day to day, keeping track of variables the days might share, etc – Scott Twombly Jun 07 '16 at 20:50
  • I'm not even sure if you should do classes at all. Depends on how much you know about them and what they are about. You can always start with moving things into methods. Besides some general "structure" (like a methods per day), your goal should be to not repeat writing the same code. Whenever you see yourself writing the same or very similar code you can probably turn the repeated section into a method that you call from multiple places. Little differences in similar code can be extracted to become method parameters. – zapl Jun 07 '16 at 20:59

1 Answers1

0

If your days progress in similar fashion and have similar behavior, you might consider defining a SchoolDay interface and then creating the twelve days as classes that implement this interface. Variables in your main Intro class could keep track of what the player has done throughout.

Here's an example. Here, I have decided that keeping track of doing homework is essential to the outcome of the game (I'm boring):

public interface SchoolDay {
    public void doMorningClass();
    public void doLunchTime();
    public void doAfternoonClass();
    public boolean doHomework(); //Sets a boolean to true, see below
}

Then, in your main class (which I would rename, to be honest):

public class SchoolGame {
    private static boolean[] homeworkDone;
    //Your other global variables such as crush and name go here
    //Make getters and setters for all of these so the day objects can
    //access and change them.

    public static void main(String[] args) {
        homeworkDone = new boolean[12]; //One boolean for each day

        //Move your intro stuff into a method and call it here
        //The main method continues once they fill out the info

        //Instantiate day objects and run their school time methods
        //If the player decides to do homework during those times, for example
        //Then that day's doHomework() method is called
        //Which would affect the boolean of that day under some condition
        ...

This setup may not perfectly suit your needs because your description was somewhat vague and there isn't a specific question here. If you think your day objects will need variables common to all days, then use a parent (possibly abstract) class instead of an interface.

Zircon
  • 4,677
  • 15
  • 32