Board.java ¶
~cpp import javax.swing.JOptionPane; public class Board { private int array[][]; //판 private int max_x; //판 크 private int max_y; //판 크 //판 public Board(int x, int y) { max_x = x; max_y = y; array = new int[max_y][max_x]; for (int i = 0; i < max_y; i++) for (int j = 0; j < max_x; j++) array[i][j] = 0; } // ? public boolean IsStepFull() { for (int i = 0; i < max_y; i++) for (int j = 0; j < max_x; j++) if (array[i][j] == 0) return false; return true; } // ? public boolean IsPostionWall(int x, int y) { if (x == -1 || x == max_x || y == -1 || y == max_y) return true; else return false; } // public void PutStep(int x, int y) { array[y][x]++; //표 //ShowStep(); } // public void ShowStep() { String output = ""; for (int i = 0; i < max_y; i++) { for (int j = 0; j < max_x; j++) output += array[i][j] + " "; output += '\n'; } JOptionPane.showMessageDialog(null, output); } }
Roach.java ¶
~cpp public class Roach { private int p_x; // x private int p_y; // y // public void Move(Board bo, int x, int y) { p_x = x; p_y = y; bo.PutStep(p_x, p_y); while (!bo.IsStepFull()) { int c_x; // 할 x int c_y; // 할 y do { c_x = p_x; c_y = p_y; int dir = (int)(Math.random() * 8); switch (dir) { case 0: c_y--; break; case 1: c_x++; c_y--; break; case 2: c_x++; break; case 3: c_x++; c_y++; break; case 4: c_y++; break; case 5: c_x--; c_y++; break; case 6: c_x--; break; case 7: c_x--; c_y--; break; } } while (!SeeNextPos(bo, c_x, c_y)); p_x = c_x; p_y = c_y; bo.PutStep(p_x, p_y); } } //할 // false true public boolean SeeNextPos(Board bo, int x, int y) { if (bo.IsPostionWall(x, y)) return false; else return true; } }
Human.java ¶
~cpp import javax.swing.JOptionPane; public class Human { // public void PutRoach (Roach ro, Board bo, int x, int y) { ro.Move(bo, x, y); } // KillRoach 할??? public void KillRoach (Roach ro) { // 호합 ^^ } // 판 public void SeeBoard (Board bo) { bo.ShowStep(); } public static void main(String[] args) { int start_x, start_y; // int board_x, board_y; // 판 크 Human sehwan = new Human(); Roach roach = new Roach(); board_x = Integer.parseInt(JOptionPane.showInputDialog(null, " 크")); board_y = Integer.parseInt(JOptionPane.showInputDialog(null, " 크")); start_x = Integer.parseInt(JOptionPane.showInputDialog(null, " ")); start_y = Integer.parseInt(JOptionPane.showInputDialog(null, " ")); // (0,0) Board board = new Board(board_x, board_y); sehwan.PutRoach(roach, board, start_x, start_y); // sehwan.SeeBoard(board); // 판 } }
1.향 ¶
.향
태:
행: 할 행
) -
태 ->
행 -> (함)
태:
행: 할 행
) -
,,핸,,, - 태
, , , - 행
-> 트 , , , - 행
태 ->
행 -> (함)
향
클
public: 클, 하클, 패키 클
private: 클
protected: 클, 하클, 패키 클
friendly(): 클, 패키 클
화(Encapsulation):
하 트 .
화 (modularity) (information hiding) 한.
한 하 .
한 한할 .
(Message):
통 하 .
, 행 한 , 해 한 .
클(Class):()
해 할 하 .
(Instance):( )
클 할 하
(Object)
(Inheritance)
클 하클 할 .
형(Polymorphism)
클 해 할 .
(overloading),함 ,함 (overriding) .
.클 () 하 트 .
화 (modularity) (information hiding) 한.
한 하 .
한 한할 .
(Message):
통 하 .
, 행 한 , 해 한 .
클(Class):()
해 할 하 .
(Instance):( )
클 할 하
(Object)
(Inheritance)
클 하클 할 .
형(Polymorphism)
클 해 할 .
(overloading),함 ,함 (overriding) .
클
~cpp class 클 { // // }
~cpp 클 클 = new 클(); 클 클; 클 = new 클();.
public: 클, 하클, 패키 클
private: 클
protected: 클, 하클, 패키 클
friendly(): 클, 패키 클
.
함: 함 하
: 클 행할 하
-> 하
함: 함 하
: 클 행할 하
-> 하
2. ¶
.
.클
클 클 )
~cpp 클(형 트) { } 클(형 트) { 호; // 함. } 클 = new 클( 트);.this
.클
클 클 )
~cpp [한] static ; [한] static ; 클 클 ) 클.클() 클() .클()
. 클 화
클 화 화
클 화 화
~cpp static =; static 형=new 형; static { 화 화; }
3. ¶
... ...
OOP ¶
화, , 클, , , , 형
하
하
¶
- 한 ?
. ^^;
- public protected ?
^^. private protected . 하 . . 히 . 하 트 합. 한 태 트 . protected 해 태 . 하 하 함 . 하 public 하 . 한 . 험하 해 .