我目前正在製作一個遊戲,發生在大四的10多天。我爲這款遊戲創建了一個介紹,但我不確定如何把它放在一起。我應該將介紹作爲父類,並且每天都有不同的子類?這是我的代碼到目前爲止。基於文本的遊戲與選擇,發生在多天
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'提煉行爲並用於「is-a」關係(香蕉是一種水果)。與你的介紹有關係嗎? – zapl
從技術上講,介紹不是一個獨立的東西。如果這是有道理的。從介紹開始,你將被提升爲遊戲菜單,以播放或退出。如果你退出system.quit(1)行觸發器,但如果不行,你顯然會玩遊戲。我的問題是如何從這裏開始第一天。我是否以單獨的課程或單獨的方法進行第一天課程? –
我會讓每一天繼承Day類。讓外部的課程處理日常移動的邏輯,記錄日期可能會分享的變量等。 –