U E D R , A S I H C RSS

Java Study2003/두번째과제/곽세환

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.

.
태:
:
) -
,,핸,,, -
, , , - 행

->
태 ->
-> (함)


화(Encapsulation):
.
(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 . 한 . 험하 .

  • ~ ? ^^; . ? ?
  • . -> -> .
  • . .
  • 1페 .


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:31
Processing time 0.0515 sec