package com.newlecture.game;


public class OmokBoard {

private char [][]buf;  

private char [][]om;

private int width;

private int height;

private int count;

public OmokBoard(int width, int height) //생성자 - 초기값설정

{

count = 0;

buf = new char[30][40];

this.width = width;

this.height = height;

for(int i=0; i<height; i++)

for(int j=0; j<width; j++)

{

if(i==0 && j==0)

{

buf[i][j] = '┌';

}

else if (i ==height-1 && j==width-1)

{

buf[i][j] = '┘';

}

else if (i ==height-1 && j==0)

{

buf[i][j] = '└';

}

else if (i ==0&& j==width-1)

{

buf[i][j] = '┐';

}

else if (i ==0)

{

buf[i][j] = '┬';

}

else if (j==0)

{

buf[i][j] = '├';

}

else if (i==height-1)

{

buf[i][j] = '┴';

}

else if (j==width-1)

{

buf[i][j] = '┤';

}

else  

buf[i][j] = '┼';

}

}

public void print()

{

for(int i=0; i<height; i++)

{

for(int j=0; j<width; j++)

System.out.printf("%c",  buf[i][j]);

System.out.println();

}

}


public void put(Omok omok) 

{

int x=omok.getX();

int y=omok.getY();

if(buf[x-1][y-1] =='○' || buf[x-1][y-1] == '●')

System.out.println("다시놔주세요");

else if(count%2 == 0)

{

this.buf[x-1][y-1] = '●';

count++;

}

else

{

this.buf[x-1][y-1] = '○';

count++;

}

this.print();

}

}


package com.newlecture.game;


import java.util.Scanner;


public class Omok 

{

private int x;

private int y;

private int type;

public void input()

{

System.out.print("(x,y)를 입력해주세요");

Scanner scan = new Scanner(System.in);

this.x = scan.nextInt();

this.y = scan.nextInt();

}

public int getX()

{

return x;

}

public int getY()

{

return y;

}

}



package com.newlecture.game;


import java.util.Scanner;


public class MenuView {


public void print()

{

System.out.print("1. 1인용\n2. 순위보기\n3. 종료하기\n>");

}


int input()

{

Scanner scan = new Scanner(System.in);

int q = scan.nextInt();

return q;

}

}



'개발 > java' 카테고리의 다른 글

자바 오목게임 만들기(omok board)  (0) 2013.10.08
자바 오목게임 만들기(omok)  (0) 2013.10.08
자바 오목게임 만들기(ui)  (0) 2013.10.08
자바 오목게임만들기(gamemenu)  (0) 2013.10.08
자바 오목게임 만들기(main)  (0) 2013.10.08

package com.newlecture.game;


import java.util.Scanner;



public class GameView 

{


private OmokBoard board;

private StatusBar statusBar;

private GameMenu menu;

private Omok omok;


public GameView() // has a  

{

System.out.println("오목판 크기를 정해주세요");

Scanner scan = new Scanner(System.in);

int x = scan.nextInt();

int y = scan.nextInt();

board = new OmokBoard(x,y);

statusBar = new StatusBar();

menu = new GameMenu();

}

public void print()

{

board.print();

statusBar.print();

menu.print();

while(true){

switch(menu.input())

{

case 1:

omok = new Omok();

omok.input();

board.put(omok);

statusBar.print();

menu.print();

break;

case 2:

break;

case 3:

break;

default :

}

}

}

}



'개발 > java' 카테고리의 다른 글

자바 오목게임 만들기(omok)  (0) 2013.10.08
자바 오목게임 만들기(menu view)  (0) 2013.10.08
자바 오목게임만들기(gamemenu)  (0) 2013.10.08
자바 오목게임 만들기(main)  (0) 2013.10.08
자바 생성자와 설정자  (0) 2013.10.02

+ Recent posts