포켓몬 스티커 뽑기 v1.0
기능: 엔터를 누르면 빵을 먹고 스티커를 뽑음.
스티커 등급은  SS, S, A ~ F 까지 있음.
각 등급 안에는 포켓몬 종류가 여러가지 있음. 
알고리즘:
스티커 등급 별 확률(int)들을 변수들에 저장.
스티커 등급 별 포켓몬(String)들을 배열들에 저장.
if 문으로 SS에서 F 까지 순차적으로 가챠를 돌림.
돌리는 중 등급 확률에 컷 당하지 않으면 다음 함수로 빠져나감.
컷 당하면 다음 등급 확률로 넘어감. SS 에서 F까지 쭉 감.
다음 함수로 빠져나가면 해당하는 등급의 배열 중에서 랜덤으로 한 포켓몬을 뽑고 출력함.
프로그램 자동 재실행.
끝.
Loader class:
Main class:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.SplittableRandom;
public class Main {
	int SS = 1;
	int S = 30;
	int A = 59;
	int B = 160;
	int C = 170;
	int D = 180;
	int E = 190;
	int F = 210;
	String[] SSstickers = { "뮤", "뮤츠" };
	String[] Sstickers = { "망나뇽", "파이어", "프리져", "썬더", "리자몽" };
	String[] Astickers = { "잠만보", "메가프테라", "투구푸스", "암스타", "폴리곤" };
	String[] Bstickers = { "부스터", "쥬피썬더", "샤미드", "라프라스", "갸라도스", "피카츄" };
	String[] Cstickers = { "켄타로스", "쁘사이저", "마그마", "에레브", "루주라", "스라크" };
	String[] Dstickers = { "마임맨", "아쿠스타", "왕콘치", "시드라", "캥카", "덩쿠리" };
	String[] Estickers = { "럭키", "코뿌리", "또도가스", "내루미", "홍수몬", "시라소몬", "가디" };
	String[] Fstickers = { "텅구리", "나시", "잉어킹", "질퍽이" };
	public Main() {
		this.main();
	}
	private void main() {
		/* 확률 조절용 코드
		 * ArrayList<Integer> ranks = new ArrayList<Integer>(); ranks.add(SS);
		 * ranks.add(S); ranks.add(A); ranks.add(B); ranks.add(C); ranks.add(D);
		 * ranks.add(E); ranks.add(F);
		 * 
		 * int sum = 0; for (int i = 0; i < ranks.size(); i++) { sum += ranks.get(i); }
		 * System.out.println(ranks); System.out.println(sum);
		 */
		this.printTitle();
		this.print("포켓몬빵을 먹기: Enter");
		try {
			System.in.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.print("결과: ");
		try {
			System.in.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		this.getSticker();
	}
	private void getSticker() {
		SplittableRandom random = new SplittableRandom();
		if (random.nextInt(0, 1000) <= SS) {
			this.printResult("SS");
		} else if (random.nextInt(0, 1000) <= S) {
			this.printResult("S");
		} else if (random.nextInt(0, 1000) <= A) {
			this.printResult("A");
		} else if (random.nextInt(0, 1000) <= B) {
			this.printResult("B");
		} else if (random.nextInt(0, 1000) <= C) {
			this.printResult("C");
		} else if (random.nextInt(0, 1000) <= D) {
			this.printResult("D");
		} else if (random.nextInt(0, 1000) <= E) {
			this.printResult("E");
		} else {
			this.printResult("F");
		}
		this.main();
	}
	private void printResult(String c) {
		ArrayList<String> stickers;
		switch (c) {
		case "SS":
			stickers = new ArrayList<String>();
			for (int i = 0; i < SSstickers.length; i++) {
				stickers.add(SSstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "S":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Sstickers.length; i++) {
				stickers.add(Sstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "A":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Astickers.length; i++) {
				stickers.add(Astickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "B":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Bstickers.length; i++) {
				stickers.add(Bstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "C":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Cstickers.length; i++) {
				stickers.add(Cstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "D":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Dstickers.length; i++) {
				stickers.add(Dstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "E":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Estickers.length; i++) {
				stickers.add(Estickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		case "F":
			stickers = new ArrayList<String>();
			for (int i = 0; i < Fstickers.length; i++) {
				stickers.add(Fstickers[i]);
			}
			Collections.shuffle(stickers);
			print(c);
			print(stickers.get(0));
			break;
		}
	}
	private void printTitle() {
		System.out.println("****************************\r\n" + "\r\n" + "    Pokemon Sticker v1.0\r\n" + "\r\n"
				+ "       developed by Byul\r\n" + "****************************");
	}
	private void print(String s) {
		System.out.println(s);
	}
}
댓글
댓글 쓰기