import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Random;
import java.util.Scanner;
//1. 영울 클래스
class hero{
    String name;
    int hp;
    int pow;
}

//3. 시작대기 클래스
class start{
    Scanner sc = new Scanner(System.in);

    void waitStart(){
        String ifstart="";
    do{
        System.out.println("싸우려면 'START'을 입력하세요. > ");
        ifstart = sc.nextLine();
    } while(! ifstart.equals("START"));
}
}

//2. 싸움, 결과 클래스
class fight{
    int[] whoFirst = {0,1};
    Random randFirst = new Random();
    Random randpow = new Random();

    void startFight(hero iron, hero sniper){
    int randomIndex=randFirst.nextInt(whoFirst.length);
    int result = whoFirst[randomIndex];

    
    if(result==0){
    int ironpow = randpow.nextInt(11)+10;
        sniper.hp = sniper.hp-ironpow;
        iron.pow=ironpow;
    System.out.println("아이언맨의 선공입니다.\n");
    System.out.println("아이언맨의 체력: "+iron.hp+"\n"+
                      "아이언맨의 공격력: "+iron.pow+"\n"+
                        "저격수의 체력: "+sniper.hp+"\n");
    }
    else{
    int sniperpow = randpow.nextInt(21)+10;
        iron.hp=iron.hp-sniperpow;
        sniper.pow=sniperpow;
    System.out.println("저격수의 선공입니다.\n");
    System.out.println("저격수의 체력: "+sniper.hp+"\n"+
                      "저격수의 공격력: "+sniper.pow+"\n"+
                        "아이언맨의 체력: "+iron.hp+"\n");
    }
    if(sniper.hp<=0){
        System.out.println("아이언맨의 승리");
        return;}
        
        else if(iron.hp<=0){
        System.out.println("저격수의 승리");
        return;}
        else{
            System.out.println("다음 라운드 시작");
        }
    }
} 
    
class Main {
    public static void main(String[] args) {
        
        hero iron = new hero();
        iron.name="아이언맨";
        iron.hp=100;
        iron.pow = 0;
        hero sniper = new hero();
        sniper.name="저격수";
        sniper.hp=65;
        sniper.pow = 0;

        start input = new start();
        input.waitStart();
        fight result = new fight();
        result.startFight(iron, sniper);         
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: