repl.it
@bikey/

JavaExam2019Dec-2019/12

Java

No description

fork
loading
Files
  • Main.java
  • jdt.ls-java-project
  • Bow.java
  • Character.java
  • Dragon.java
  • FlyingCreature.java
  • Hero.java
  • SuperHero.java
  • Sword.java
  • Weapon.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public class Main {
  public static void main(String[] args) {
    int command;  //入力したコマンド
    java.util.Scanner scan = new java.util.Scanner(System.in);  //キーボードからの入力
    
    SuperHero player = new SuperHero("ミナト");
    Dragon com = new Dragon();

    player.setTarget(com);
    com.setTarget(player);

    while(!(player.isDead() || com.isDead())) {
      player.showCommand();
      boolean isError;
      do {
        System.out.print("コマンド:");
        command = scan.nextInt();
        isError = player.doCommand(command);
      } while(isError);

      System.out.println();

      com.doRandomAction();

      System.out.println();
    }

    checkResult(player, com);
  }

  public static void checkResult(Hero player, Dragon com) {
    if(player.isDead()) {
      System.out.println("ざんねん!あなたの負けです...");
    } else if(com.isDead()) {
      System.out.println("おみごと!敵を倒しました!");
    } else {
      System.out.println("戦いはまだまだ続きます。");
    }
  }

  public static void gameEnd() {
    System.out.println("ゲームを終了します。");
    System.exit(0);
  }
}
?