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 근 게 . . 게 게 겁.