๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“œ ์ž๋ฐ” Java

์ž๋ฐ”(JAVA) - ๋‘ ์ฃผ์‚ฌ์œ„ ํ•ฉ ๋งž์ถ”๊ธฐ, ๋ฒ ํŒ…๊ฒŒ์ž„

by Meteora_ 2021. 1. 26.
728x90
1
2
3
4
5
6
7
8
9
10
11
12
 
public class MainClass {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
        GamePlay gp = new GamePlay ();
        gp.gamePlay();
        
    }
 
}
cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class Dice {
 
    private int number;
    
    public void diceRandom() {
        number = (int)(Math.random()*6)+1;
    }
    
    public int getNumber() {
        return number;
    }
    
    
}
 
cs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.util.Scanner;
 
public class GamePlay {
 
    private int coin;
    private int batting;
    private int inputNumber;
    
    Dice dice1 = new Dice();
    Dice dice2 = new Dice();
    
    public void init() {
        coin = 20;
        dice1.diceRandom();
        dice2.diceRandom();
        
        //System.out.println("์ฃผ์‚ฌ์œ„1 = " + dice1.getNumber());       (๋žœ๋ค์ฃผ์‚ฌ์œ„ ํ‘œํ˜„ ์˜์—ญ)
        //System.out.println("์ฃผ์‚ฌ์œ„1 = " + dice2.getNumber());
    }
    
    
    public void userInput() {
        Scanner sc = new Scanner(System.in);
        
        System.out.println("๋ฐฐํŒ… ๋จธ๋‹ˆ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์‹ญ์‹œ์˜ค=");
        batting = sc.nextInt();
        
        coin = coin - batting;
        
        System.out.println("๋‘๊ฐœ์˜ ์ฃผ์‚ฌ์œ„์˜ ํ•ฉ = ");
        inputNumber = sc.nextInt();
        
    }
        
        public void finding() {
            int d_num1 = dice1.getNumber();
            int d_num2 = dice2.getNumber();
            
            int diceSum = d_num1 + d_num2;
            
            if(inputNumber == diceSum) {
                if(diceSum == 3 || diceSum ==11) {
                    batting = batting * 18;
                }
                else if(diceSum == 4 || diceSum == 10) {
                    batting = batting * 12;
                }
                else if(diceSum == 5 || diceSum == 9) {
                    batting = batting * 9;
                }
                else if (diceSum ==6 || diceSum == 8) {
                    batting = batting * 7;
                }
                else if(diceSum ==7) {
                    batting = batting * 6;
                }
                System.out.println("์žญํŒŸ!!!!!!!!!!!!!!!");
                coin = coin + batting;            
            }
            else {
                System.out.println("๊ฝ~~~~~~~~~~~~");
            }
        }
        
            
        public void result() {
            System.out.println("์ฃผ์‚ฌ์œ„1 : " + dice1.getNumber());
            System.out.println("์ฃผ์‚ฌ์œ„2 : " + dice2.getNumber());
            
            System.out.println("ํ•ฉ๊ณ„ : " + (dice1.getNumber()+dice2.getNumber()));
            System.out.println("ํ˜„์žฌ ๋‚จ์€ ์ฝ”์ธ -> " + coin);
        }
        
        public void gamePlay() {
            init();
            userInput();
            finding();
            result();
        }
    
 
}
cs

๋Œ“๊ธ€