超初心者が0からRPG作る(オマケ)

長すぎるソースコード等をこちらに公開していく。

机上に躍れ、小人形【第陸歩-おまけ】

今回作成したソースコードがこちらになる。

コピー&ペーストの影響で空白が詰められてしまっているが、これを各自Battle.javaとしてコンパイル・実行してくれれば問題なく動くはずだ。

 

public class Battle
{

 public static void main(String[] args)
{
String player1Name;
String player2Name;
int player1JobCode = 0;
String player1Job = "無職";
int player2JobCode = 0;
String player2Job = "無職";
boolean startBool = false;
do{
//プレイヤー1の名前決め
System.out.println("プレイヤー1の名前を入力してください。");
String name = new java.util.Scanner(System.in).nextLine();
player1Name = name;
System.out.println(player1Name + "でよろしいですか?");
System.out.println("1:はい 2:いいえ");
int nameInt = new java.util.Scanner(System.in).nextInt();
System.out.println();
switch(nameInt){
case 1:
startBool = true;
break;
case 2:
startBool = false;
break;
default:
startBool = false;
break;
}
}
while(startBool != true);

do{
//プレイヤー2の名前決め
System.out.println("プレイヤー2の名前を入力してください。");
String name = new java.util.Scanner(System.in).nextLine();
player2Name = name;
System.out.println(player2Name + "でよろしいですか?");
System.out.println("1:はい 2:いいえ");
int nameInt = new java.util.Scanner(System.in).nextInt();
System.out.println();
switch(nameInt){
case 1:
startBool = true;
break;
case 2:
startBool = false;
break;
default:
startBool = false;
break;
}
}
while(startBool != true);


//プレイヤー1の職決め
System.out.println(player1Name + "の職業を選択してください。");
System.out.println();
do{
System.out.println("ソルジャー :耐久力 …★★★★☆");
System.out.println(" :最大攻撃力…★★★☆☆");
System.out.println(" :攻撃安定度…★★★★☆");
System.out.println(" :回復力 …★★☆☆☆");
System.out.println(" :特殊能力 …「不撓不屈」体力低下で攻撃力アップ");
System.out.println();
System.out.println("職業をソルジャーで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt == 1){
player1JobCode = 1;
}
else {
System.out.println("メイジ :中位魔導士 ");
System.out.println(" :耐久力 …★★☆☆☆");
System.out.println(" :最大攻撃力…★★★★☆");
System.out.println(" :攻撃安定度…★★★★★");
System.out.println(" :回復力 …★★☆☆☆");
System.out.println(" :特殊能力 …「魔法障壁」稀にダメージ無効");
System.out.println();
System.out.println("職業をメイジで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt2 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt2 == 1){
player1JobCode = 2;
}
else {
System.out.println("ボウガンナー:新型弩弓兵 ");
System.out.println(" :耐久力 …★★★☆☆");
System.out.println(" :最大攻撃力…★★★★★");
System.out.println(" :攻撃安定度…★☆☆☆☆");
System.out.println(" :回復力 …★★★★☆");
System.out.println(" :特殊能力 …「超速装弾」稀に二回攻撃");
System.out.println();
System.out.println("職業をボウガンナーで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt3 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt3 == 1){
player1JobCode = 3;
}
else {
System.out.println("ヴァンパイア:体力 …★★☆☆☆");
System.out.println(" :最大攻撃力…★★★☆☆");
System.out.println(" :攻撃安定度…★★★☆☆");
System.out.println(" :回復力 …★★★★★");
System.out.println(" :特殊能力 …「不老不死」毎ターン徐々に回復、最大HPを超えて回復できる");
System.out.println();
System.out.println("職業をヴァンパイアで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt4 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt4 == 1){
player1JobCode = 4;
}
else {
System.out.println("ゴーレム :護衛石人形 ");
System.out.println(" :耐久力 …★★★★★");
System.out.println(" :最大攻撃力…★★☆☆☆");
System.out.println(" :攻撃安定度…★★★★☆");
System.out.println(" :回復力 …★★☆☆☆");
System.out.println(" :特殊能力 …「岩石質肌」受けるダメージ軽減");
System.out.println();
System.out.println("職業をゴーレムで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt5 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt5 == 1){
player1JobCode = 5;
}
else {

}
}
}
}
}
}
while(player1JobCode == 0);

switch(player1JobCode){
case 1:
player1Job ="ソルジャー";
break;
case 2:
player1Job ="メイジ";
break;
case 3:
player1Job ="ボウガンナー";
break;
case 4:
player1Job ="ヴァンパイア";
break;
case 5:
player1Job ="ゴーレム";
break;
default:
break;
}
System.out.println(player1Name + "は" + player1Job + "になりました。");
System.out.println();
System.out.println();

 

//プレイヤー2の職決め
System.out.println(player2Name + "の職業を選択してください。");
System.out.println();
do{
System.out.println("ソルジャー :万能型傭兵 ");
System.out.println(" :耐久力 …★★★★☆");
System.out.println(" :最大攻撃力…★★★★☆");
System.out.println(" :攻撃安定度…★★★☆☆");
System.out.println(" :回復力 …★★☆☆☆");
System.out.println(" :特殊能力 …「不撓不屈」体力低下で攻撃力アップ");
System.out.println();
System.out.println("職業をソルジャーで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt == 1){
player2JobCode = 1;
}
else {
System.out.println("メイジ :中位魔導士 ");
System.out.println(" :耐久力 …★★☆☆☆");
System.out.println(" :最大攻撃力…★★★★☆");
System.out.println(" :攻撃安定度…★★★★★");
System.out.println(" :回復力 …★★☆☆☆");
System.out.println(" :特殊能力 …「魔法障壁」稀にダメージ無効");
System.out.println();
System.out.println("職業をメイジで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt2 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt2 == 1){
player2JobCode = 2;
}
else {
System.out.println("ボウガンナー:新型弩弓兵 ");
System.out.println(" :耐久力 …★★★☆☆");
System.out.println(" :最大攻撃力…★★★★★");
System.out.println(" :攻撃安定度…★☆☆☆☆");
System.out.println(" :回復力 …★★★★☆");
System.out.println(" :特殊能力 …「超速装弾」稀に二回攻撃");
System.out.println();
System.out.println("職業をボウガンナーで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt3 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt3 == 1){
player2JobCode = 3;
}
else {
System.out.println("ヴァンパイア:吸血鬼末裔 ");
System.out.println(" :耐久力 …★★☆☆☆");
System.out.println(" :最大攻撃力…★★★☆☆");
System.out.println(" :攻撃安定度…★★★☆☆");
System.out.println(" :回復力 …★★★★★");
System.out.println(" :特殊能力 …「不老不死」毎ターン徐々に回復、最大HPを超えて回復できる");
System.out.println();
System.out.println("職業をヴァンパイアで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt4 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt4 == 1){
player2JobCode = 4;
}
else {

System.out.println("ゴーレム :護衛石人形 ");
System.out.println(" :耐久力 …★★★★★");
System.out.println(" :最大攻撃力…★★★☆☆");
System.out.println(" :攻撃安定度…★★★★☆");
System.out.println(" :回復力 …★☆☆☆☆");
System.out.println(" :特殊能力 …「岩石質肌」受けるダメージ軽減");
System.out.println();
System.out.println("職業をゴーレムで決定しますか?");
System.out.println("1:はい 2:いいえ");
int jobInt5 = new java.util.Scanner(System.in).nextInt();
System.out.println();
if(jobInt5 == 1){
player2JobCode = 5;
}
else {

}
}
}
}
}
}
while(player2JobCode == 0);

switch(player2JobCode){
case 1:
player2Job ="ソルジャー";
break;
case 2:
player2Job ="メイジ";
break;
case 3:
player2Job ="ボウガンナー";
break;
case 4:
player2Job ="ヴァンパイア";
break;
case 5:
player2Job ="ゴーレム";
break;
default:
break;
}
System.out.println(player2Name + "は" + player2Job + "になりました。");
System.out.println();
System.out.println();

//順番決め
System.out.println("それでは、戦闘を開始します。");
System.out.println();
int r = new java.util.Random().nextInt(2);
int Turn = 0;
if (r == 0){
System.out.println("先攻は" + player1Name + "です。");
}
else {
System.out.println("先攻は" + player2Name + "です。");
Turn = 1;
}
System.out.println();

//戦闘準備

int player1MaxHP;
int FPAct0Damage;
int FPAct0Heal;
int FPAct1Damage;
int FPAct1Heal;
int FPAct2Damage;
int FPAct2Heal;
int FPAct3Damage;
int FPAct3Heal;
int FPAct4Damage;
int FPAct4Heal;
int FPAct5Damage;
int FPAct5Heal;

switch(player1JobCode){
case 1:
player1MaxHP = 400;
FPAct0Damage = 80;
FPAct0Heal = 0;
FPAct1Damage = 50;
FPAct1Heal = 0;
FPAct2Damage = 40;
FPAct2Heal = 0;
FPAct3Damage = 30;
FPAct3Heal = 0;
FPAct4Damage = 0;
FPAct4Heal =100;
FPAct5Damage = 0;
FPAct5Heal = 0;
break;
case 2:
player1MaxHP = 200;
FPAct0Damage =100;
FPAct0Heal = 0;
FPAct1Damage = 80;
FPAct1Heal = 0;
FPAct2Damage = 70;
FPAct2Heal = 0;
FPAct3Damage = 60;
FPAct3Heal = 0;
FPAct4Damage = 60;
FPAct4Heal = 0;
FPAct5Damage = 0;
FPAct5Heal = 50;
break;
case 3:
player1MaxHP = 300;
FPAct0Damage =250;
FPAct0Heal = 0;
FPAct1Damage = 0;
FPAct1Heal = 0;
FPAct2Damage = 0;
FPAct2Heal = 0;
FPAct3Damage = 0;
FPAct3Heal = 0;
FPAct4Damage = 0;
FPAct4Heal = 0;
FPAct5Damage = 0;
FPAct5Heal =100;
break;
case 4:
player1MaxHP = 200;
FPAct0Damage = 90;
FPAct0Heal = 90;
FPAct1Damage = 50;
FPAct1Heal = 50;
FPAct2Damage = 40;
FPAct2Heal = 40;
FPAct3Damage = 40;
FPAct3Heal = 40;
FPAct4Damage = 0;
FPAct4Heal = 0;
FPAct5Damage = 0;
FPAct5Heal = 0;
break;
case 5:
player1MaxHP = 500;
FPAct0Damage = 50;
FPAct0Heal = 0;
FPAct1Damage = 50;
FPAct1Heal = 0;
FPAct2Damage = 50;
FPAct2Heal = 0;
FPAct3Damage = 50;
FPAct3Heal = 0;
FPAct4Damage = 50;
FPAct4Heal = 0;
FPAct5Damage = 0;
FPAct5Heal = 0;
break;
default:
player1MaxHP = 0;
FPAct0Damage = 0;
FPAct0Heal = 0;
FPAct1Damage = 0;
FPAct1Heal = 0;
FPAct2Damage = 0;
FPAct2Heal = 0;
FPAct3Damage = 0;
FPAct3Heal = 0;
FPAct4Damage = 0;
FPAct4Heal = 0;
FPAct5Damage = 0;
FPAct5Heal = 0;
break;
}

int player2MaxHP;
int SPAct0Damage;
int SPAct0Heal;
int SPAct1Damage;
int SPAct1Heal;
int SPAct2Damage;
int SPAct2Heal;
int SPAct3Damage;
int SPAct3Heal;
int SPAct4Damage;
int SPAct4Heal;
int SPAct5Damage;
int SPAct5Heal;

switch(player2JobCode){
case 1:
player2MaxHP = 400;
SPAct0Damage = 80;
SPAct0Heal = 0;
SPAct1Damage = 60;
SPAct1Heal = 0;
SPAct2Damage = 30;
SPAct2Heal = 0;
SPAct3Damage = 30;
SPAct3Heal = 0;
SPAct4Damage = 0;
SPAct4Heal =100;
SPAct5Damage = 0;
SPAct5Heal = 0;
break;
case 2:
player2MaxHP = 200;
SPAct0Damage =100;
SPAct0Heal = 0;
SPAct1Damage = 70;
SPAct1Heal = 0;
SPAct2Damage = 60;
SPAct2Heal = 0;
SPAct3Damage = 50;
SPAct3Heal = 0;
SPAct4Damage = 40;
SPAct4Heal = 0;
SPAct5Damage = 0;
SPAct5Heal = 80;
break;
case 3:
player2MaxHP = 300;
SPAct0Damage =250;
SPAct0Heal = 0;
SPAct1Damage = 0;
SPAct1Heal = 0;
SPAct2Damage = 0;
SPAct2Heal = 0;
SPAct3Damage = 0;
SPAct3Heal = 0;
SPAct4Damage = 0;
SPAct4Heal = 0;
SPAct5Damage = 0;
SPAct5Heal =100;
break;
case 4:
player2MaxHP = 200;
SPAct0Damage = 90;
SPAct0Heal = 90;
SPAct1Damage = 50;
SPAct1Heal = 50;
SPAct2Damage = 40;
SPAct2Heal = 40;
SPAct3Damage = 20;
SPAct3Heal = 20;
SPAct4Damage = 0;
SPAct4Heal = 0;
SPAct5Damage = 0;
SPAct5Heal = 0;
break;
case 5:
player2MaxHP = 500;
SPAct0Damage = 50;
SPAct0Heal = 0;
SPAct1Damage = 50;
SPAct1Heal = 0;
SPAct2Damage = 50;
SPAct2Heal = 0;
SPAct3Damage = 50;
SPAct3Heal = 0;
SPAct4Damage = 0;
SPAct4Heal = 0;
SPAct5Damage = 0;
SPAct5Heal = 50;
break;
default:
player2MaxHP = 0;
SPAct0Damage = 0;
SPAct0Heal = 0;
SPAct1Damage = 0;
SPAct1Heal = 0;
SPAct2Damage = 0;
SPAct2Heal = 0;
SPAct3Damage = 0;
SPAct3Heal = 0;
SPAct4Damage = 0;
SPAct4Heal = 0;
SPAct5Damage = 0;
SPAct5Heal = 0;
break;
}

int player1HP = player1MaxHP;
int player2HP = player2MaxHP;
int actDamage;
int actHeal;


//戦闘開始
while(player1HP > 0 && player2HP > 0){
if(Turn == 0){
boolean react = true;
boolean guard = false;
System.out.println(player1Name + "のターン!");
int FPAct = new java.util.Random().nextInt(6);
switch(FPAct){
case 0:
actDamage = FPAct0Damage;
actHeal = FPAct0Heal;
break;
case 1:
actDamage = FPAct1Damage;
actHeal = FPAct1Heal;
break;
case 2:
actDamage = FPAct2Damage;
actHeal = FPAct2Heal;
break;
case 3:
actDamage = FPAct3Damage;
actHeal = FPAct3Heal;
break;
case 4:
actDamage = FPAct4Damage;
actHeal = FPAct4Heal;
break;
case 5:
actDamage = FPAct5Damage;
actHeal = FPAct5Heal;
break;
default:
actDamage = 0;
actHeal = 0;
break;
}
//「不撓不屈」の効果
if(player1JobCode == 1){
if(player1HP < player1MaxHP && actDamage != 0){System.out.println("「不撓不屈」発動!" + player1Name + "の攻撃力が上昇した!");}
int damageUp = player1MaxHP * 10 / player1HP;
if(damageUp >= 20){damageUp = 20;}
actDamage = actDamage * damageUp;
actDamage /= 10;
}
//「魔法障壁」の効果
if(player2JobCode == 2){
int guard2 = new java.util.Random().nextInt(4);
if(guard2 == 0 && actDamage != 0){
System.out.println("「魔法障壁」発動!" + player1Name + "の攻撃は無効化された!");
guard = true;
actDamage = 0;
}
}
//「岩石質肌」の効果
if(player2JobCode == 5 && actDamage != 0){
System.out.println("「岩石質肌」発動!ダメージが減少した!");
actDamage *= 8;
actDamage /= 10;
}
//ダメージ計算
if(actDamage >= actHeal){
System.out.println(player1Name + "の攻撃!");
}
else {
System.out.println(player1Name + "はポーションを使った!");
}
player2HP -= actDamage;
player1HP += actHeal;
if(player1JobCode == 4 && actDamage != 0){
System.out.println(player1Name + "は" + player2Name + "の体力を" + actDamage + "吸収した!");
}
else {
if(actDamage != 0) {
System.out.println(player2Name + "は" + actDamage + "のダメージを受けた!");
}
else if(actHeal != 0) {
System.out.println(player1Name + "の体力が" + actHeal + "回復した!");
}
else {
if(guard != true){System.out.println("ミス!" + player1Name + "の攻撃は外れた!");}
}
}
//「超速装弾」の効果
if(player1JobCode == 3){
if(react == true){
int react2 = new java.util.Random().nextInt(4);
if(react2 == 0){
System.out.println("「超速装弾」発動!");
react = false;
}
else {Turn++;}
}
else {Turn++;}
}
else {Turn++;}
//「不老不死」の効果
if(player1JobCode == 4 && player1HP >= 0){
int regenerate = new java.util.Random().nextInt(10);
regenerate += 10;
player1HP += regenerate;
System.out.println("「不老不死」発動!" + player1Name + "のHPが" + regenerate + "回復した!");
}
else {
if(player1HP >= player1MaxHP){player1HP = player1MaxHP;}
}
System.out.println(player1Name + "の体力…" + player1HP + "/" + player1MaxHP);
System.out.println(player2Name + "の体力…" + player2HP + "/" + player2MaxHP);
System.out.println("Enterキーを押してください。");
String go = new java.util.Scanner(System.in).nextLine();
System.out.println();
}
if(Turn ==1 && player2HP > 0)
{
boolean react = true;
boolean guard = false;
System.out.println(player2Name + "のターン!");
int SPAct = new java.util.Random().nextInt(6);
switch(SPAct){
case 0:
actDamage = SPAct0Damage;
actHeal = SPAct0Heal;
break;
case 1:
actDamage = SPAct1Damage;
actHeal = SPAct1Heal;
break;
case 2:
actDamage = SPAct2Damage;
actHeal = SPAct2Heal;
break;
case 3:
actDamage = SPAct3Damage;
actHeal = SPAct3Heal;
break;
case 4:
actDamage = SPAct4Damage;
actHeal = SPAct4Heal;
break;
case 5:
actDamage = SPAct5Damage;
actHeal = SPAct5Heal;
break;
default:
actDamage = 0;
actHeal = 0;
break;
}
//「不撓不屈」の効果
if(player2JobCode == 1){
if(player2HP < player2MaxHP && actDamage != 0){System.out.println("「不撓不屈」発動!" + player2Name + "の攻撃力が上昇した!");}
int damageUp = player2MaxHP * 10 / player2HP;
if(damageUp >= 20){damageUp = 20;}
actDamage *= damageUp;
actDamage /= 10;
}
//「魔法障壁」の効果
if(player1JobCode == 2){
int guard3 = new java.util.Random().nextInt(4);
if(guard3 == 0 && actDamage != 0){
System.out.println("「魔法障壁」発動!" + player2Name + "の攻撃は無効化された!");
guard = true;
actDamage = 0;
}
}
//「岩石質肌」の効果
if(player1JobCode == 5 && actDamage != 0){
System.out.println("「岩石質肌」発動!ダメージが減少した!");
actDamage *= 8;
actDamage /= 10;
}
//ダメージ計算
if(actDamage >= actHeal){
System.out.println(player2Name + "の攻撃!");
}
else {
System.out.println(player2Name + "はポーションを使った!");
}
player1HP -= actDamage;
player2HP += actHeal;
if(player2JobCode == 4 && actDamage != 0){
System.out.println(player2Name + "は" + player1Name + "の体力を" + actDamage + "吸収した!");
}
else {
if(actDamage != 0) {
System.out.println(player1Name + "は" + actDamage + "のダメージを受けた!");
}
else if(actHeal != 0) {
System.out.println(player2Name + "の体力が" + actHeal + "回復した!");
}
else {
if(guard != true){System.out.println("ミス!" + player2Name + "の攻撃は外れた!");}
}
}
//「超速装弾」の効果
if(player2JobCode == 3){
if(react == true){
int react3 = new java.util.Random().nextInt(4);
if(react3 == 0){
System.out.println("「超速装弾」発動!");
react = false;
}
else {Turn--;}
}
else {Turn--;}
}
else {Turn--;}
//「不老不死」の効果
if(player2JobCode == 4 && player1HP >= 0){
int regenerate = new java.util.Random().nextInt(10);
regenerate += 10;
player2HP += regenerate;
System.out.println("「不老不死」発動!" + player2Name + "のHPが" + regenerate + "回復した!");
}
else {
if(player2HP >= player2MaxHP){player2HP = player2MaxHP;}
}
System.out.println(player1Name + "の体力…" + player1HP + "/" + player1MaxHP);
System.out.println(player2Name + "の体力…" + player2HP + "/" + player2MaxHP);
System.out.println("Enterキーを押してください。");
String go = new java.util.Scanner(System.in).nextLine();
System.out.println();
}
}
if(player1HP <= 0){
System.out.println(player2Name + "の勝利です!");
System.out.println("CONGRATULATIONS!!!");
}
else {
System.out.println(player1Name + "の勝利です!");
System.out.println("CONGRATULATIONS!!!");
}
}
}