๋ฐ์ํ
package G3_๋ฐฐ์ด์ฌํ3_ํ๊ฐ๋ฌธ์ ;
import java.util.Arrays;
import java.util.Random;
/*
[์ค์ง์ด๊ฒ์]
[๋ฌด๊ถํ ๊ฝ์ด ํผ์์ต๋๋ค]
doll ์ ์ธํ์ด๊ณ , arr ์ ์ค์ง์ด ๊ฒ์ ์ฐธ๊ฐ์๋ค ์ด๋ค.
[1] ๊ฒ์์ 10ํ ๋ฐ๋ณต๋๋ค.
[2] doll ๋งคํด ๋ง๋ค 3~5๋ฅผ ๋๋ค์ผ๋ก ์ ์ฅํ๋ค.
[3] arr ์ ๋๋ค์ผ๋ก 1~4๋ฅผ ์ ์ฅํ๋ค.
[4] ๋งคํด๋ง๋ค doll ๋ณด๋ค ํฐ์ซ์๊ฐ ๋์จ ์ฐธ๊ฐ์๋ ์์ง์ธ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋์ด ํ๋ฝ๋๋ค.
[5] 10ํ ๊น์ง ์ด์๋จ์ ์ฐธ๊ฐ์์ ๋ฒํธ๋ฅผ ์ถ๋ ฅํ์์ค.
[6] 1๋ฑ์ ๋ฒํธ๋ฅผ ์ถ๋ ฅํ์์ค.
*/
class Flower_Game{
Random ran = new Random();
int arr[]=new int[10]; boolean check[]=new boolean[10];
int survivor[]=new int[10];
int doll; int cnt=0; int win=0;
void flower_Winner() {
int max=0;
for(int i=0; i<check.length; i++) {
if(check[i]==false) {
if(max < survivor[i]) {
max = survivor[i]; win=i;
}
}
}
System.out.println(win+"๋ฒ ์ฐธ๊ฐ์ ์ฐ์น!");
}
void flower_Check() {
for(int i=0; i<check.length; i++) {
if(check[i]==false) {
System.out.println(i+"๋ฒ ์์กด!"+survivor[i]);
}
}
}
void flower_Start() {
doll=ran.nextInt(3)+3;
for(int i=0; i<arr.length; i++) {
arr[i] = ran.nextInt(4)+1;
if(check[i]==false) {
if(doll<arr[i]) {
check[i] = true;
System.out.println(i+"๋ฒ ํ๋ฝ!");
}else {
survivor[i]+=arr[i];
}
}
}
}
void run() {
while(cnt<10) {
System.out.println("--------------------");
System.out.println(cnt+1+")ํ ");
System.out.println("๋ฌด๊ถํ๊ฝ์ด ํผ์์ต๋๋ค.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
flower_Start();
System.out.println("๋ฒํธ:"+doll);
cnt++;
}
flower_Check(); //์์กด์
System.out.println("---------------------");
flower_Winner();
}
}
public class ๋ฐฐ์ด์ฌํ3_๋ฌด๊ถํ๊ฝ_์ฐ์ต {
public static void main(String[] args) {
Flower_Game go = new Flower_Game();
go.run();
}
}
300x250
'Algorithm > Etc' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ํฐ์ ์ธ ์ฌ์ด์ฆ๋ณ๋ก ๊ฐ์์ธ๊ธฐ - COS2๊ธ (0) | 2022.04.01 |
---|---|
[Java] 10 ์ง์๋ฅผ x ์ง์๋ก ๋ณํํ๊ธฐ (0) | 2022.03.10 |
2์ฐจ์ ๋ฐฐ์ด ์ธํ๋ฝ๊ธฐ (0) | 2022.02.03 |
๋ฐฐ์ด ๊ฐ์ด๋ฐ ์๋ฆฌ ์์ ํฉ (0) | 2022.01.27 |
(JAVA) ๋ฐฐ์ด ํฑํํ ๊ฒ์ (0) | 2022.01.24 |