java不等号が機能してない?
<= が動かない?
ここに解決したい内容を記載してください。
関数adventure(ランダムで敵キャラを表示する)の中のif(monster[i].conditionsPoint <= player[0].level)が機能していない
理想 2回ループで止まってほしい
現状 20(全部)ループしてしまう
発生している問題・エラー
なし
該当するソースコード
class character{
String name;
int maxHitPoint;
int hitPoint;
int atkPoint;
int speed;
character(String name, int maxHitPoint, int hitPoint, int atkPoint, int speed){
this.name = name;
this.maxHitPoint = maxHitPoint;
this.hitPoint = hitPoint;
this.atkPoint = atkPoint;
this.speed = speed;
}
}
class player extends character{
int level;
int p_exPoint;
player(String name, int level, int maxHitPoint, int hitPoint, int atkPoint, int speed, int p_exPoint){
super(name, maxHitPoint, hitPoint, atkPoint, speed);
}
Integer adventure(player[] player, monster[] monster) {
int random_adventure = (int)(Math.random()*100) + 1;
if(1 <= random_adventure && random_adventure <= 10) {
/*何もなかった*/
System.out.println("今日は何も見つからなかった。");
player[0].hitPoint = player[0].hitPoint + (player[0].maxHitPoint*10)/100;
return player[0].hitPoint;
}
else if(11 <= random_adventure && random_adventure <= 100) {
/*モンスターに出くわす*/
int monsterCount = 0;
for(int i = 0; i <= 20; i++) {
if(monster[i].conditionsPoint <= player[0].level) {
//当てはまったモンスターの番号を格納する配列作る
monsterCount++;
}
}
int random_monster = (int)(Math.random()* monsterCount);
System.out.println(monster[random_monster].name + "に出くわした!");
return random_monster;
}
return null;
}
void fight(player[] player, monster[] monster) {
Integer random_monster = adventure(player, monster);
int battlestart = 0;
int MyTurn = 0;
int EnemyTurn = 0;
if(battlestart == 0) {
if(player[0].speed >= monster[random_monster].speed) {
MyTurn = 1 ;
EnemyTurn = 0;
}
else {
MyTurn = 0 ;
EnemyTurn = 1;
}
battlestart = 1;
}
for(int i = 1; i <= 15; i++) {
if(MyTurn == 1) {
/////////////////////自分のターンが先行////////////////////////////
//////////////////////戦闘エフェクト//////////////////////////////
System.out.println(player[0].name + "の攻撃");
//////////////////////ダメージ計算////////////////////////////////
monster[random_monster].hitPoint = monster[random_monster].hitPoint - player[0].atkPoint;
System.out.println(monster[random_monster].name + "に" + player[0].atkPoint + "のダメージ");
if(monster[random_monster].hitPoint <= 0) {
System.out.println(monster[random_monster].name + "を倒した!");
}
System.out.println(monster[random_monster].name + "の攻撃");
player[0].hitPoint = player[0].hitPoint - monster[random_monster].atkPoint;
System.out.println(player[0].name + "は" + monster[random_monster].atkPoint + "のダメージ");
if(player[0].hitPoint <= 0) {
System.out.println(player[0].name + "は倒れてしまった!");
}
}
if(EnemyTurn == 1) {
/////////////////////相手ターンが先行////////////////////////////
//////////////////////戦闘エフェクト//////////////////////////////
System.out.println(monster[random_monster].name + "の攻撃");
//////////////////////ダメージ計算////////////////////////////////
player[0].hitPoint = player[0].hitPoint - monster[random_monster].atkPoint;
System.out.println(player[0].name + "は" + monster[random_monster].atkPoint + "のダメージ");
if(player[0].hitPoint <= 0) {
System.out.println(player[0].name + "は倒れてしまった!");
}
System.out.println(player[0].name + "の攻撃");
monster[random_monster].hitPoint = monster[random_monster].hitPoint - player[0].atkPoint;
System.out.println(monster[random_monster].name + "に" + player[0].atkPoint + "のダメージ");
if(monster[random_monster].hitPoint <= 0) {
System.out.println(monster[random_monster].name + "を倒した!");
}
}
}
}
}
class monster extends character{
int conditionsPoint;
int m_exPoint;
monster(String name, int conditionsPoint, int maxHitPoint, int hitPoint, int atkPoint, int speed, int m_exPoint){
super(name, maxHitPoint, hitPoint, atkPoint, speed);
}
}
class TextQuest_ver1 {
public static void main(String[] args) {
player[] player = new player[2];{
player[0] = new player("冒険者",1,5,5,2,3,0);
player[1] = new player("相棒",1,4,4,3,4,0);
}
monster[] monster = new monster[21];{
monster[0] = new monster("オオカミ",1,2,2,3,5,5);
monster[1] = new monster("スライム",1,3,3,1,3,5);
monster[2] = new monster("グール",3,5,5,3,3,10);
monster[3] = new monster("ゴブリン",5,5,5,5,4,15);
monster[4] = new monster("コボルト",5,4,4,5,5,15);
monster[5] = new monster("クマ",10,10,10,8,7,20);
monster[6] = new monster("スケルトン",10,10,10,5,4,20);
monster[7] = new monster("オーク",15,15,15,10,6,25);
monster[8] = new monster("ゴーレム",15,40,40,10,5,25);
monster[9] = new monster("ミミック",15,20,20,15,10,25);
monster[10] = new monster("ドレイク",20,30,30,15,8,30);
monster[11] = new monster("トロール",20,40,40,15,5,30);
monster[12] = new monster("オーガ",25,50,50,20,8,40);
monster[13] = new monster("ドラゴン",25,40,40,20,10,40);
monster[14] = new monster("勇者",25,60,60,22,9,40);
monster[15] = new monster("グリフォン",26,55,55,23,12,50);
monster[16] = new monster("ケルベロス",26,60,60,25,10,50);
monster[17] = new monster("リッチ",27,70,70,25,8,60);
monster[18] = new monster("デュラハン",28,80,80,28,15,70);
monster[19] = new monster("雪の女王",28,65,65,30,12,70);
monster[20] = new monster("魔王",30,100,100,35,100,80);
}
player[0].adventure(player, monster);
}
}
0