[Falling Grade]

Updated:

Falling Grade

GitHub

๋ณธ ํ”„๋กœ์ ํŠธ๋Š” 2019๋…„ 2ํ•™๋…„ 2ํ•™๊ธฐ Java Programming ํŒ€ ํ”„๋กœ์ ํŠธ ์ด๋‹ค.


image

๊ฐœ์š”

์ž๋ฐ” ์ˆ˜์—…์„ ์ˆ˜๊ฐ•ํ•˜๋ฉด์„œ ๊ฒŒ์ž„ ๋งŒ๋“ค๊ธฐ๊ฐ€ ๋งˆ์ง€๋ง‰ ํŒ€ ํ”„๋กœ์ ํŠธ๋กœ ์ฃผ์–ด์กŒ๋‹ค.

์ด์•Œํ”ผํ•˜๊ธฐ, ๋ฆฌ๋“ฌ๊ฒŒ์ž„ ๊ฐ™์€ ๊ณ ์ „ ๊ฒŒ์ž„์˜ ๊ฐœ๋…์„ ์‘์šฉํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค.

์—ฌ๊ธฐ์„œ ์ด์•Œ ํ”ผํ•˜๊ธฐ์˜ ํ”ผํ•˜๋Š” ๊ฐœ๋…, ๋ฆฌ๋“ฌ๊ฒŒ์ž„์—์„œ ๋‚ด๋ ค์˜ค๋Š” ๋…ธํŠธ๋ฅผ ๋งž์ถ”๋Š” ๊ฐœ๋…์„ ํ•ฉ์ณค๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ์—๊ฒŒ ์นœ๊ทผํ•˜๊ฒŒ ๋‹ค๊ฐ€ ์˜ฌ ์ˆ˜ ์žˆ๋Š” ์ฃผ์ œ์ธ ํ•™์ ์„ ๋”ํ•ด

์œ„์—์„œ ๋–จ์–ด์ง€๋Š” ํ•™์ ์„ ์–ป๋Š” ๊ฒŒ์ž„์„ ๋งŒ๋“ค๊ธฐ๋กœ ํ–ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด ์ƒ๋Œ€์ ์œผ๋กœ ๋‚ฎ์€ ํ•™์ ์€ ์ด์•Œ ํ”ผํ•˜๊ธฐ ์ฒ˜๋Ÿผ ํ”ผํ•˜๋ ค๊ณ  ํ•  ๊ฒƒ ์ด๊ณ 

๋†’์€ ํ•™์ ์€ ๋ฆฌ๋“ฌ๊ฒŒ์ž„ ์ฒ˜๋Ÿผ ๋งž์ถ”๋ ค๊ณ  ํ•  ๊ฒƒ ์ด๋‹ค.

๋ฐ”๋กœ ์–ด๋ฆด๋•Œ ์ž์ฃผ ํ•˜๋˜ ๋˜ฅ ํ”ผํ•˜๊ธฐ ๊ฒŒ์ž„๊ณผ ํ•™์ ์„ ํ•ฉ์ณ ์œ„์—์„œ ๋–จ์–ด์ง€๋Š” ํ•™์ ์„ ๋จน๋Š” ๊ฒŒ์ž„์„ ๋งŒ๋“ค๊ธฐ๋กœ ํ–ˆ๋‹ค.

ํ™”๋ฉด ๊ตฌ์„ฑ

  • ๊ฒŒ์ž„ ๊ตฌ์„ฑ์— ํ•„์š”ํ•œ ๋ชจ๋“  ์ด๋ฏธ์ง€, ๋ฒ„ํŠผ ์ƒ์„ฑ
  • ๊ฐ๊ฐ์˜ ํ™”๋ฉด์„ ํ‘œ์‹œํ•  ๋ณ€์ˆ˜ ์„ค์ •
  • If๋ฌธ, ๋ณ€์ˆ˜, setVisible ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์ƒํ™ฉ์— ๋งž๋Š” ๋ฒ„ํŠผ, ์ด๋ฏธ์ง€ ์ถœ๋ ฅ

๊ฒŒ์ž„ ๊ตฌ๋™

  • ๋‚œ์ด๋„ ๋ณ„ ํ•™์  ์ƒ์„ฑ ๋นˆ๋„ ์ˆ˜ ์กฐ์ ˆ
  • ๋žœ๋ค ์ƒ์„ฑ ๊ฐ’์— ๋”ฐ๋ฅธ ํ•™์  ์ข…๋ฅ˜ ์กฐ์ ˆ
  • ๋žœ๋ค ํ•˜๊ฐ• ๊ฐ’์— ๋”ฐ๋ฅธ ํ•™์  ํ•˜๊ฐ• ์†๋„ ๋ถ€์—ฌ
  • ์บ๋ฆญํ„ฐ ์ด๋ฏธ์ง€์™€ ํ•™์  ์ด๋ฏธ์ง€ ์ขŒํ‘œ ๊ณ„์‚ฐ์„ ํ†ตํ•œ ์ ์ˆ˜ ๊ณ„์‚ฐ
  • KeyAdapter ํด๋ž˜์Šค๋ฅผ ์ด์šฉํ•œ ์บ๋ฆญํ„ฐ ์ด๋™
  • Thread ๋ฅผ ํ†ตํ•œ ํ•™์ , ์บ๋ฆญํ„ฐ repaint

๊ฒŒ์ž„ ๊ฒฐ๊ณผ ์‚ฐ์ถœ

  • Static ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•œ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ ๊ณ„์‚ฐ
  • ์บ๋ฆญํ„ฐ์™€ ํ•™์ ์ด ์ ‘์ด‰ ์‹œ ํ•™์ ์˜ ์ƒ์„ฑ ๊ฐ’์œผ๋กœ ์ ์ˆ˜ ๋ถ€์—ฌ
  • double ๊ฐ’์œผ๋กœ ๊ณ„์‚ฐ ํ›„ String.format ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ์†Œ์ˆ˜์  2์ž๋ฆฌ ๊นŒ์ง€ ์ถœ๋ ฅ

์ค‘์š” ๋ฉ”์†Œ๋“œ

๋‚œ์ด๋„์— ๋”ฐ๋ผ ํ•™์  ์ƒ์„ฑ ๋นˆ๋„์ˆ˜๋ฅผ ์กฐ์ ˆ

  • Easy : 0.8์ดˆ ๋งˆ๋‹ค ํ•™์  ์ƒ์„ฑ

  • Normal : 0.5์ดˆ ๋งˆ๋‹ค ํ•™์  ์ƒ์„ฑ

  • Hard : 0.3์ดˆ ๋งˆ๋‹ค ํ•™์  ์ƒ์„ฑ

๊ตฌํ˜„์›๋ฆฌ

  • Thread์˜ Sleep ๊ธฐ๋Šฅ ์ด์šฉ

  • Sleep ์‹œ๊ฐ„์„ ๋„ฃ์–ด์ฃผ์–ด ๋‚œ์ด๋„์— ๋งž๋Š” ๋นˆ๋„ ๊ตฌํ˜„

  • ํ•™์  ๊ฐ์ฒด ์ƒ์„ฑ โ†’ย ์›€์ง์ž„ Thread ์‹คํ–‰ โ†’ย ๋ฐฐ์—ด๋ฆฌ์ŠคํŠธ ์‚ฝ์ž…

// ๋‚œ์ด๋„ ๋ณ„ ํ•™์  ์ƒ์„ฑ ๋นˆ๋„์ˆ˜ ์กฐ์ ˆ ๋ฉ”์†Œ๋“œ

public void run() {
		while (true) {
			if (Main.GAME_START) {
				if (this.difficulty.equals("EASY")) {
					try {
						Thread.sleep(800); // 0.8์ดˆ๋งˆ๋‹ค
						Grade grade = new Grade(generator.nextInt(22));
						grade.start();
						gradeList.add(grade);
					} catch (InterruptedException e) {
						System.err.println(e.getMessage());
					}
				} else if (this.difficulty.equals("NORMAL")) {
					try {
						Thread.sleep(500); // 0.5์ดˆ๋งˆ๋‹ค
						Grade grade = new Grade(generator.nextInt(22));
						grade.start();
						gradeList.add(grade);
					} catch (InterruptedException e) {
						System.err.println(e.getMessage());
					}
				} else {
					try {
						Thread.sleep(300); // 0.3์ดˆ๋งˆ๋‹ค
						Grade grade = new Grade(generator.nextInt(22));
						grade.start();
						gradeList.add(grade);
					} catch (InterruptedException e) {
						System.err.println(e.getMessage());
					}
				}
			} else {
				interrupt();
				break;
			}
		}
	}

ํ•™์  ๊ฐ์ฒด ์ƒ์„ฑ ์‹œ ๋žœ๋ค ์ƒ์„ฑ ๊ฐ’ ๋ถ€์—ฌ

  • ์ƒ์„ฑ ๊ฐ’ 0 ~ 4 : A+, A โ†’ย ํ™•๋ฅ  23%
  • ์ƒ์„ฑ ๊ฐ’ 5 ~ 9 : B+, B โ†’ย ํ™•๋ฅ  23%
  • ์ƒ์„ฑ ๊ฐ’ 10: ~ 12 : C+, C โ†’ ํ™•๋ฅ  13.5%
  • ์ƒ์„ฑ ๊ฐ’ 13 ~ 15 : D+, D โ†’ ํ™•๋ฅ  13.5%
  • ์ƒ์„ฑ ๊ฐ’ 16 ~ 19 : F โ†’ย ํ™•๋ฅ  18%
  • ์ƒ์„ฑ ๊ฐ’ 20 ~ 21 : Item โ†’ย ํ™•๋ฅ  9%

๊ตฌํ˜„์›๋ฆฌ

  • Random ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉ, ์ƒ์„ฑ ๊ฐ’ ๋žœ๋ค ์ƒ์„ฑ
  • ์ƒ์„ฑ ๊ฐ’์— ๋งž๋Š” ํ•™์  ์ด๋ฏธ์ง€ ์‚ฝ์ž…
  • ๊ฐ ํ•™์ ์— ๋žœ๋ค ํ•˜๊ฐ• ๊ฐ’, ๋žœ๋ค ์ƒ์„ฑ์œ„์น˜ ๋ถ€์—ฌ
// ํ•™์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ ๋ฐ ๋žœ๋ค ๊ฐ’ ๋ถ€์—ฌ ๋ฉ”์†Œ๋“œ

public Grade(int gradeType) {
		//ํ•™์  ์ด๋ฏธ์ง€ ์ƒ์„ฑ
		if (gradeType >= 0 && gradeType <= 4) {
			if (gradeType % 2 != 0) {
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeAPlus.png").getImage();
			} else
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeA.png").getImage();

		} else if (gradeType >= 5 && gradeType <= 9) {
			if (gradeType % 2 != 0) {
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeBPlus.png").getImage();
			} else
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeB.png").getImage();
		} else if (gradeType >= 10 && gradeType <= 12) {
			if (gradeType % 2 != 0) {
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeCPlus.png").getImage();
			} else
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeC.png").getImage();
		} else if (gradeType >= 13 && gradeType <= 15) {
			if (gradeType % 2 != 0) {
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeDPlus.png").getImage();
			} else
				gradeImage = new ImageIcon(".\\bin\\Data\\gradeD.png").getImage();
		} else if (gradeType >= 16 && gradeType <= 19) {
			gradeImage = new ImageIcon(".\\bin\\Data\\gradeF.png").getImage();
		} else if (gradeType == 20) {
			gradeImage = new ImageIcon(".\\bin\\Data\\timePlus.png").getImage();
		} else {
			gradeImage = new ImageIcon(".\\bin\\Data\\FMinus.png").getImage();
		}
		this.speed = 2 + generator.nextInt(5);
		this.x = generator.nextInt(1200);
		this.gradeType = gradeType;
	}

๊ฒŒ์ž„ ์ข…๋ฃŒ, ๋•…์— ๋–จ์–ด์กŒ์„ ๊ฒฝ์šฐ ํ•™์  ํ•˜๊ฐ• ๋ฉˆ์ถค

  • ๊ฒŒ์ž„ ์ข…๋ฃŒ

    ํ•™์ ์ด ๊ณ„์† ๋–จ์–ด์ง€๋Š” ๊ฒฝ์šฐ ๊ฒฐ๊ณผ ์‚ฐ์ถœ์— ์˜ค๋ฅ˜ ๋ฐœ์ƒ

  • ๋•…์— ๋–จ์–ด์กŒ์„ ๊ฒฝ์šฐ

    ์›€์ง์ž„ ์ข…๋ฃŒ ํ›„ ๋ฐฐ์—ด๋ฆฌ์ŠคํŠธ์—์„œ ์‚ญ์ œ

๊ตฌํ˜„์›๋ฆฌ

  • ํ•™์  ํ•˜๊ฐ• ์—ฌ๋ถ€ ๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌ
  • ํ•™์ ์ด ํ•˜๊ฐ• ์ค‘์ด ์•„๋‹ ๋•Œ Thread ์ •์ง€ ํ›„ ๋ฐฐ์—ด๋ฆฌ์ŠคํŠธ์—์„œ ์‚ญ์ œ
// ๊ฒŒ์ž„ ์ข…๋ฃŒ, ๋•…์— ๋–จ์–ด์กŒ์„ ๊ฒฝ์šฐ ํ•™์  ํ•˜๊ฐ• ๋ฉˆ์ถค ๋ฉ”์†Œ๋“œ

public void run() {
		try {
			while (true) {
				drop();
				if (proceeded) {
					if (!Main.GAME_START) { // ๋–จ์–ด์ง€๋Š” ํ•™์ ์ด ์žˆ๋Š” ๋„์ค‘์— ๊ฒŒ์ž„์ด ์ข…๋ฃŒ ๋œ๋‹ค๋ฉด ๋–จ์–ด์ง€๊ณ  ์žˆ๋Š” ํ•™์ ๋„ ๋ฉˆ์ถฐ์•ผ ํ•œ๋‹ค
						interrupt();
						break;
					}
					Thread.sleep(Main.SLEEP_TIME);
				} else {
					interrupt();
					break;
				}
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
	}

ํ”Œ๋ ˆ์ด ์˜์ƒ


Leave a comment