Submit Search
Upload
Java Final Report
β’
0 likes
β’
76 views
H
Hwangcy
Follow
Java Final Report
Read less
Read more
Devices & Hardware
Report
Share
Report
Share
1 of 32
Download now
Download to read offline
Recommended
Visual term project2
Visual term project2
ssuser8de143
Β
μ΄μ°μν05
μ΄μ°μν05
JeongJunYong
Β
Visual term ppt
Visual term ppt
ssuser8de143
Β
μμ λ°μ΄ν°μ μ²λ¦¬μ μ 보μ μΆμΆ
μμ λ°μ΄ν°μ μ²λ¦¬μ μ 보μ μΆμΆ
λμ€ μ΄
Β
리ν©ν λ§ μ¬λ‘ μ€ννλ‘리그μ±
리ν©ν λ§ μ¬λ‘ μ€ννλ‘리그μ±
beom kyun choi
Β
λΉμ£ΌμΌνλ‘κ·Έλλ° ν νλ‘κ·Έλλ° μ΅μ’ λ³΄κ³ μ
λΉμ£ΌμΌνλ‘κ·Έλλ° ν νλ‘κ·Έλλ° μ΅μ’ λ³΄κ³ μ
KimSungJoon
Β
κ°λ¨ Ip νν° κ΅¬ν μ΄μΌκΈ°
κ°λ¨ Ip νν° κ΅¬ν μ΄μΌκΈ°
beom kyun choi
Β
Project#5 μ΅λ¨κ±°λ¦¬ μ°ΎκΈ° D0 Hwp
Project#5 μ΅λ¨κ±°λ¦¬ μ°ΎκΈ° D0 Hwp
Kimjeongmoo
Β
Recommended
Visual term project2
Visual term project2
ssuser8de143
Β
μ΄μ°μν05
μ΄μ°μν05
JeongJunYong
Β
Visual term ppt
Visual term ppt
ssuser8de143
Β
μμ λ°μ΄ν°μ μ²λ¦¬μ μ 보μ μΆμΆ
μμ λ°μ΄ν°μ μ²λ¦¬μ μ 보μ μΆμΆ
λμ€ μ΄
Β
리ν©ν λ§ μ¬λ‘ μ€ννλ‘리그μ±
리ν©ν λ§ μ¬λ‘ μ€ννλ‘리그μ±
beom kyun choi
Β
λΉμ£ΌμΌνλ‘κ·Έλλ° ν νλ‘κ·Έλλ° μ΅μ’ λ³΄κ³ μ
λΉμ£ΌμΌνλ‘κ·Έλλ° ν νλ‘κ·Έλλ° μ΅μ’ λ³΄κ³ μ
KimSungJoon
Β
κ°λ¨ Ip νν° κ΅¬ν μ΄μΌκΈ°
κ°λ¨ Ip νν° κ΅¬ν μ΄μΌκΈ°
beom kyun choi
Β
Project#5 μ΅λ¨κ±°λ¦¬ μ°ΎκΈ° D0 Hwp
Project#5 μ΅λ¨κ±°λ¦¬ μ°ΎκΈ° D0 Hwp
Kimjeongmoo
Β
Image game
Image game
Hwangcy
Β
Java Omok Project
Java Omok Project
Hwangcy
Β
Ppt
Ppt
Hwangcy
Β
Image game
Image game
Hwangcy
Β
Java
Java
Hwangcy
Β
Image
Image
Hwangcy
Β
Rhr
Rhr
Hwangcy
Β
Omok game
Omok game
Hwangcy
Β
Tetris
Tetris
Hwangcy
Β
Rhr
Rhr
Hwangcy
Β
Java project
Java project
Hwangcy
Β
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
Hwangcy
Β
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
Hwangcy
Β
More Related Content
More from Hwangcy
Image game
Image game
Hwangcy
Β
Java Omok Project
Java Omok Project
Hwangcy
Β
Ppt
Ppt
Hwangcy
Β
Image game
Image game
Hwangcy
Β
Java
Java
Hwangcy
Β
Image
Image
Hwangcy
Β
Rhr
Rhr
Hwangcy
Β
Omok game
Omok game
Hwangcy
Β
Tetris
Tetris
Hwangcy
Β
Rhr
Rhr
Hwangcy
Β
Java project
Java project
Hwangcy
Β
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
Hwangcy
Β
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
Hwangcy
Β
More from Hwangcy
(13)
Image game
Image game
Β
Java Omok Project
Java Omok Project
Β
Ppt
Ppt
Β
Image game
Image game
Β
Java
Java
Β
Image
Image
Β
Rhr
Rhr
Β
Omok game
Omok game
Β
Tetris
Tetris
Β
Rhr
Rhr
Β
Java project
Java project
Β
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
μλ° λ€μ€ μ±ν νλ‘κ·Έλ¨
Β
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
μλ°λ₯Ό μ΄μ©ν λ€μ€ μ±ν νλ‘κ·Έλ¨ κΈ°λ§κ³Όμ
Β
Java Final Report
1.
λ΄λΉκ΅μ: λ°λκ· νκ³Ό: μ 보ν΅μ 곡νκ³Ό νλ²:
20143091,20142325 μ΄λ¦: μλ³κ±΄,ν©μ°½μ€ β λΉμ£ΌμΌ νλ‘κ·Έλλ° κΈ°λ§ μ΅μ’ λ³΄κ³ μ DATE :2019.12.17
2.
1. κΈ°νλκΈ° λ§μ νμλ€μ΄
βνμ°½μμ μ λ¬΄μ¨ κ²μμ λ§μ΄ ν΄λ΄€μκΉβ μκ°μ ν΄λ³΄λ€κ° μ€κ³ λ±ν κ΅ μ¬λ μκ°μ μΉκ΅¬λ€κ³Ό λ ΈνΈμ νμ κ·Έλ €μ λκ·ΈλΌλ―Έμ Xνλ‘ μ€λͺ©μ νλ λκ° μ κ°λμ μ²μ κΈ°νμ μμνκ² λμμ΅λλ€. μ€λͺ©μ΄λΌλ κ²μμ λꡬλ ν λ²μ―€μ ν΄λ΄€μ κ²μμ΄λΌκ³ μκ°ν΄ μλ°λ‘ ꡬνμ ν΄λ³΄ κ³ μΆμμ΅λλ€. 2. νλ‘κ·Έλ¨ μ€λͺ μ΄ 5κ°μ ν΄λμ€μ΄λ©° κ°κ°μ μ€λͺ μ λ€μκ³Ό κ°μ΅λλ€. - Player.java : ν λͺ μ νλ μ΄μ΄λ₯Ό μ€μ νκΈ° μν ν΄λμ€ - Board.java : νλμ κ²μμ μ¬μ©λλ νλμ 보λνμ λνλ΄λ ν΄λμ€ - Game.java : ν νμ κ²μμ μ§ννκΈ° μν΄ μ¬μ©λλ ν΄λμ€ - Main.java : μ 체μ μΈ νλ‘κ·Έλ¨μ νκ³Ό κ²μ μ§νμ μν λ©μΈ ν΄λμ€ - Restart.java : ν κ²μμ΄ λλ¬μ λ κ²μμ μ¬μμνκΈ° μν ν΄λμ€ μ΄λ―Έμ§ νμΌ - black.png : κ²μμ λ μ΄λ―Έμ§ - white.png : νμμ λ μ΄λ―Έμ§ - board.png : λ°λν κΈ°λ³Έμ μΌλ‘ λλΈ λ²νΌλ§ κΈ°λ²μ μ¬μ©νμ¬ μ€μκ°μΌλ‘ μ΄λ―Έμ§λ₯Ό μ²λ¦¬νλ€. μ΄λ―Έμ§ ν΄λμλ λ°λλ μ΄λ―Έμ§, λ°λν μ΄λ―Έμ§λ₯Ό λ£μλ€. 보λνμλ λμ ν λ² λ λλ§λ€ draw()ν¨μλ₯Ό μ΄μ©νμ¬ λ°λνμ κ·Έλ¦¬κ² λλ€. 3. μ€ννλ©΄ [μ€ν 첫 νλ©΄]
3.
[μ€ν μ νλ μ΄μ΄
μ°¨λ‘ μ€λͺ ] [λ μ μλ κ³³μ λμμ λ] [μΉλ¦¬μνλ³]
4.
[μΉλ¦¬μνλ³ ν 3μ΄
ν μ¬μμ] [μ¬λ¬ μ°¨λ‘ κ²μ μ§ν]
5.
4. μ½λ <board> import java.awt.Graphics; import
java.awt.Image; import javax.swing.ImageIcon; public class Board{ // 보λν κΈ°λ³Έ λ³μ μ μΈ private final int WIDTH = 480, HEIGHT = 510; private final int BLACK = 1, WHITE = 2; private int boardXSize = 15, boardYSize = 15; private int[][] boardMap = new int[boardXSize][boardYSize]; private Player playerOne, playerTwo; private Player Winner; private Image boardImage; private Image blackImage; private Image whiteImage; // 보λν μμ±μ μ μ public Board() { boardImage = new ImageIcon(getClass().getResource("/image/board.png")).getImage(); blackImage = new ImageIcon(getClass().getResource("/image/black.png")).getImage(); whiteImage = new ImageIcon(getClass().getResource("/image/white.png")).getImage(); for(int i = 0; i < boardXSize; i++)
6.
{ for(int j =
0; j < boardYSize; j++) { // 보λν νλ ¬ μ΄κΈ°ν boardMap[i][j] = 0; } } } // 보λνμ 그리λ ν¨μ public void draw(Graphics g) { g.drawImage(boardImage, 0, 30, null); for(int i = 1; i <= boardXSize; i++) g.drawLine(30 * i, 60, 30 * i, 480); for(int i = 1; i <= boardYSize; i++) g.drawLine(30, 30 + 30 * i, 450, 30 + 30 * i); for(int i = 1; i <= boardXSize; i++) { for(int j = 1; j <= boardYSize; j++) { if(boardMap[i - 1][j - 1] != 0) { if(boardMap[i - 1][j - 1] == BLACK) g.drawImage(blackImage, 30 * i - 15, 15 + 30 * j, null); if(boardMap[i - 1][j - 1] == WHITE) g.drawImage(whiteImage, 30 * i - 15, 15
7.
+ 30 *
j, null); } } } } // 보λνμ λμ λλ ν¨μ public boolean put(int x, int y, Player player) { if(boardMap[x][y] != 0) return false; boardMap[x][y] = player.getPlayerColor(); return true; } // νμ¬ λ³΄λνμ μΆλ ₯ public void show() { for(int i = 0; i < boardXSize; i++) { for(int j = 0; j < boardYSize; j++) { System.out.print(boardMap[i][j] + " "); } System.out.print("n"); }
8.
} // μΉλ¦¬μλ₯Ό λ°ν public
Player getWinner() { return Winner; } // νλ μ΄μ΄ μΉλ¦¬ νμ public boolean win(int x, int y, Player player) { if(win1(x, y)||win2(x, y)||win3(x, y)||win4(x, y)||win5(x, y)|| win6(x, y)||win7(x, y)||win8(x, y)||win9(x, y)||win10(x, y)|| win11(x, y)||win12(x, y)||win13(x, y)||win14(x, y)||win15(x, y)|| win16(x, y)||win17(x, y)||win18(x, y)||win19(x, y)||win20(x, y)) { Winner = player; return true; } return false; } /*------------- ν λ² λμ λμ λλ§λ€ μ΄ 20κ°μ§ μΉλ¦¬ κ°λ₯ κ²½μ°μ μκ° μ‘΄μ¬ -------------*/
9.
public boolean win1(int
x, int y) { try { for(int i = y; i < y + 5; i++) { if(boardMap[x][i] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win2(int x, int y) { try { for(int i = x, j = y; i < x + 5; i++, j--) { if(boardMap[i][j] != boardMap[x][y])
10.
{ return false; } } } catch(ArrayIndexOutOfBoundsException e) { return
false; } return true; } public boolean win3(int x, int y) { try { for(int i = x; i < x + 5; i++) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) {
11.
return false; } return true; } public
boolean win4(int x, int y) { try { for(int i = x, j = y; i < x + 5; i++, j++) { if(boardMap[i][j] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win5(int x, int y) {
12.
try { for(int i =
y; i > y - 5; i--) { if(boardMap[x][i] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win6(int x, int y) { try { for(int i = x, j = y; i > x - 5; i--, j++) { if(boardMap[i][j] != boardMap[x][y]) { return false;
13.
} } } catch(ArrayIndexOutOfBoundsException e) { return false; } return
true; } public boolean win7(int x, int y) { try { for(int i = x; i > x - 5; i--) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; }
14.
return true; } public boolean
win8(int x, int y) { try { for(int i = x, j = y; i > x - 5; i--, j--) { if(boardMap[i][j] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win9(int x, int y) { try {
15.
for(int i =
y - 1; i < y + 4; i++) { if(boardMap[x][i] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win10(int x, int y) { try { for(int i = x - 1, j = y + 1; i < x + 4; i++, j--) { if(boardMap[i][j] != boardMap[x][y]) { return false; } }
16.
} catch(ArrayIndexOutOfBoundsException e) { return false; } return
true; } public boolean win11(int x, int y) { try { for(int i = x - 1; i < x + 4; i++) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; }
17.
public boolean win12(int
x, int y) { try { for(int i = x - 1, j = y - 1; i < x + 4; i++, j++) { if(boardMap[i][j] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win13(int x, int y) { try { for(int i = y + 1; i > y - 4; i--) {
18.
if(boardMap[x][i] != boardMap[x][y]) { return
false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win14(int x, int y) { try { for(int i = x + 1, j = y - 1; i > x - 4; i--, j++) { if(boardMap[i][j] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e)
19.
{ return false; } return true; } public
boolean win15(int x, int y) { try { for(int i = x + 1; i > x - 4; i--) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win16(int x, int y)
20.
{ try { for(int i =
x + 1, j = y + 1; i > x - 4; i--, j--) { if(boardMap[i][j] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win17(int x, int y) { try { for(int i = y - 2; i < y + 3; i++) { if(boardMap[x][i] != boardMap[x][y]) {
21.
return false; } } } catch(ArrayIndexOutOfBoundsException e) { return
false; } return true; } public boolean win18(int x, int y) { try { for(int i = x - 2; i < x + 3; i++) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false;
22.
} return true; } public boolean
win19(int x, int y) { try { for(int i = y + 2; i > y - 3; i--) { if(boardMap[x][i] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } public boolean win20(int x, int y) { try
23.
{ for(int i =
x + 2; i > x - 3; i--) { if(boardMap[i][y] != boardMap[x][y]) { return false; } } } catch(ArrayIndexOutOfBoundsException e) { return false; } return true; } } <Game> import java.awt.Graphics; import java.util.Random; import java.util.Scanner; public class Game{ Board board = new Board(); private static int BLACK = 1;
24.
private static int
WHITE = 2; public static Player attacker; Player playerOne = new Player("μλ³κ±΄", "μλ³κ±΄μ λλ€."); Player playerTwo = new Player("ν©μ°½μ€", "ν©μ°½μ€μ λλ€."); public boolean ready = true; public Game() { playerSetting(playerOne, playerTwo); if(playerOne.getPlayerColor() == BLACK) attacker = playerOne; else attacker = playerTwo; } public boolean attack(int x, int y) { Main.textArea.requestFocus(); if(!board.put(x, y, attacker)) { Main.textArea.append("λμ μ μλ μ리μ λλ€.n"); Main.textArea.append("λ μμΉλ₯Ό λ€μ μ ννμΈμn"); return false; } if(board.win(x, y, attacker))
25.
{ Main.textArea.append("μΉλ¦¬μλ " + board.getWinner().getPlayerName()
+ "μ λλ€.n"); ready = false; return true; } else { if(playerOne == attacker) attacker = playerTwo; else attacker = playerOne; Main.textArea.append(attacker.getPlayerName() + " νλ μ΄μ΄κ° λ μ°¨λ‘μ λλ€.n"); } return false; } public void draw(Graphics g) { board.draw(g); } // νλ μ΄μ΄ μμ κ²°μ public static void playerSetting(Player playerOne, Player playerTwo) {
26.
Random random =
new Random(); if(random.nextBoolean() == true) { playerOne.setPlayerColor(BLACK); playerTwo.setPlayerColor(WHITE); } else { playerOne.setPlayerColor(WHITE); playerTwo.setPlayerColor(BLACK); } } } <Main> import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextArea;
27.
public class Main
extends JFrame{ private final int BLACK = 1, WHITE = 2; private int boardXSize = 15, boardYSize = 15; private final int WIDTH = 480, HEIGHT = 510; private static Game game = new Game(); public static Main main; Image dbImage; Graphics dbG; public static JTextArea textArea = new JTextArea(10, 20); public static JScrollPane scrollPane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); public Main() { setSize(WIDTH + 500, HEIGHT); setResizable(false); setVisible(true); setTitle("μ€λͺ© κ²μ"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addMouseListener(new MouseHandler()); setLocationRelativeTo(null); setLayout(null);
28.
scrollPane.setBounds(WIDTH + 20,
25, 455, 430); add(scrollPane); scrollPane.setVisible(true); } public void paint(Graphics g) { super.paint(g); dbImage = createImage(WIDTH, HEIGHT); dbG = dbImage.getGraphics(); draw(dbG); g.drawImage(dbImage, 0, 0, null); } public void draw(Graphics g) { game.draw(g); } public static void main(String[] args) { main = new Main(); textArea.append(game.attacker.getPlayerName() + " νλ μ΄μ΄κ° λ μ°¨λ‘μ λλ€.n"); } public static void restart() { game = new Game(); textArea.append("κ²μμ΄ μ¬μμλμμ΅λλ€.n"); main.repaint();
29.
} public class MouseHandler
extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { repaint(); int mx = e.getX(); int my = e.getY(); if(game.ready) { for(int i = 0; i < boardXSize; i++) { for(int j = 0; j < boardYSize; j++) { if(mx > 30 * i + 15 && mx < 30 * i + 45 && my > 30 * j + 45 && my < 30 * j + 75) { if(game.attack(i, j)) { textArea.append("3μ΄ νμ κ²μμ΄ μ¬μμλ©λλ€.n"); Restart restart = new Restart(); Thread restartThread = new Thread(restart);
30.
restartThread.start(); } } } } } } } } <Player> public class Player
{ // νλ μ΄μ΄ κΈ°λ³Έ λ³μ μ μΈ private String playerName; private String playerInfo; private int playerColor; // νλ μ΄μ΄ μμ±μ μ μ public Player(String playerName, String playerInfo) { this.playerName = playerName; this.playerInfo = playerInfo; } // νλ μ΄μ΄μ λ μκΉμ λ°ν int getPlayerColor()
31.
{ return playerColor; } // νλ μ΄μ΄μ
λ μκΉμ μ€μ void setPlayerColor(int playerColor) { this.playerColor = playerColor; } // νλ μ΄μ΄ μ΄λ¦μ λ°ν public String getPlayerName() { return playerName; } // νλ μ΄μ΄ μ΄λ¦μ μ€μ public void setPlayerName(String playerName) { this.playerName = playerName; } // νλ μ΄μ΄ μ 보λ₯Ό λ°ν public String getPlayerInfo() { return playerInfo; } // νλ μ΄μ΄ μ 보λ₯Ό μ€μ
32.
public void setPlayerInfo(String
playerInfo) { this.playerInfo = playerInfo; } } <Restart> public class Restart implements Runnable{ @Override public void run() { try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } Main.restart(); }
Download now