私はファイナルファンタジーのキャラクターの小さなゲームを作成しています。このゲームでは、「戦い」たい人の名前を入力します。各キャラクター(5人だけ)をサブクラスとして、Statsというスーパークラスの変数( static)およびgetter/setterが定義されています。
コードはすべて私が望むように機能しますが、すべてが1つの巨大なクラスに含まれるのは好きではありません。
主な方法はここにあります。
package com.George.revision;
import java.util.Random;
import com.George.characters.Cloud;
import com.George.characters.Squall;
import com.George.characters.Stats;
import com.George.characters.TheEnemy;
import com.George.characters.ThePlayer;
import com.George.characters.Tidus;
import com.George.characters.Yuna;
import com.George.characters.Zidane;
import com.George.input.GetInput;
import com.George.input.ListNames;
public class Main {
public static void main(String[] args) {
ListNames.listNames();
Stats clo = new Cloud();
Stats squ = new Squall();
Stats zid = new Zidane();
Stats tid = new Tidus();
Stats yun = new Yuna();
String versus = GetInput.getInput("\nWhich of these Characters would you like to go up against?");
Stats ene1 = new TheEnemy();
switch (versus) {
case "Cloud":
ene1.setName(Names.CLOUD);
ene1.setHairColor(Stats.BLONDE);
ene1.setWep(Weapons.BUSTER_SWORD);
ene1.setSkill(clo.skill);
ene1.setAp(clo.ap);
ene1.setStr(clo.str);
ene1.setMag(clo.mag);
break;
case "Squall":
ene1.setName(Names.SQUALL);
ene1.setHairColor(Stats.BLACK);
ene1.setWep(Weapons.LIONHEART);
ene1.setSkill(squ.skill);
ene1.setAp(squ.ap);
ene1.setStr(squ.str);
ene1.setMag(squ.mag);
break;
case "Zidane":
ene1.setName(Names.ZIDANE);
ene1.setHairColor(Stats.LIGHTBROWN);
ene1.setWep(Weapons.THIEF_DAGGER);
ene1.setSkill(zid.skill);
ene1.setAp(zid.ap);
ene1.setStr(zid.str);
ene1.setMag(zid.mag);
break;
case "Tidus":
ene1.setName(Names.TIDUS);
ene1.setHairColor(Stats.BLONDE);
ene1.setWep(Weapons.CALADBOLG);
ene1.setSkill(tid.skill);
ene1.setAp(tid.ap);
ene1.setStr(tid.str);
ene1.setMag(tid.mag);
break;
case "Yuna":
ene1.setName(Names.YUNA);
ene1.setHairColor(Stats.DARKBROWN);
ene1.setWep(Weapons.NIRVANA);
ene1.setSkill(yun.skill);
ene1.setAp(yun.ap);
ene1.setStr(yun.str);
ene1.setMag(yun.mag);
break;
default:
System.out.println("You did not enter a valid character name");
break;
}
System.out.println("You have chosen to face " + ene1.name);
System.out.println("Enemy Skill = " + ene1.skill + " Enemy Weapon = " + ene1.wep);
System.out.println("Enemy Skill = " + ene1.skill + " Enemy Weapon = " + ene1.wep);
int eneTotal = ene1.skill + ene1.ap + ene1.str + ene1.mag;
Stats player = new ThePlayer();
String plN = GetInput.getInput("What is your name?");
player.playerName = plN;
System.out.println("So Your name is " + player.playerName);
String plWep = GetInput.getInput("What is your Weapon's name?");
player.playerWep = plWep;
System.out.println("So your Weapon is " + player.playerWep);
Random generator = new Random();
int plSkill = generator.nextInt(10);
player.skill = plSkill;
System.out.println("Your skill level is " + player.skill);
Random gn = new Random();
int plAp = gn.nextInt(10 - 5) + 5;
System.out.println("So your Attack Power is " + plAp);
player.ap = plAp;
Random gns = new Random();
int plStr = gns.nextInt(10);
System.out.println("So your Strength is " + plStr);
plStr = player.str;
Random gnm = new Random();
int plMag = gnm.nextInt(10 - 5) + 5;
player.mag = plMag;
System.out.println("So your Magic is " + player.mag);
int plHax = 15;
double doubleResult = plHax;
double ene1Hax = 3.99;
int intResult = (int)ene1Hax;
double doubleValue = 6.99;
Double doubleObj = new Double(doubleValue);
int intR = doubleObj.intValue();
System.out.println(intR);
int plyrTotal = player.skill + player.ap + player.str + player.mag;
if (plyrTotal > eneTotal) {
System.out.println("Congratulations you beat " + ene1.name + " Please Play Again!" );
} else if (plyrTotal == eneTotal) {
System.out.println("You drew with " + ene1.name + " Play again and Win!");
}
else
{
System.out.println("You were not succesful this time " + ene1.name + " Defeated you by " + (eneTotal - plyrTotal) + " Please Try Again");
}
}
}
この後、プレイヤーの「統計」とキャラクターの乱数を生成し、統計の合計値を照合して、別のクラスに入れたい「勝者」を決定するコードがさらに増えました。私の問題は、
Mainクラスのswitchステートメントに入力された値を使用して別のクラスでene1を取得するにはどうすればよいですか。
わかりやすくするために、完全なメインメソッドに更新されました