Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CaturJawa
- {
- static String[][] board = new String[19][19];
- static String player = "Player 1";
- public static void main(String[] args)
- {
- CreateBoard(19, 19);
- Scanner scan = new Scanner(System.in);
- int choose = 0;
- do
- {
- Clear();
- System.out.println("1. Play Game");
- System.out.println("2. Exit");
- System.out.print("Your choose: ");
- choose = scan.nextInt();
- switch(choose)
- {
- case 1:
- InGame();
- break;
- }
- }while(choose != 2);
- }
- static void InGame()
- {
- int choose = 0;
- Scanner scan = new Scanner(System.in);
- do
- {
- Clear();
- PrintBoard();
- System.out.println("1. Add Tile");
- System.out.println("2. Exit");
- System.out.println(player);
- System.out.print("Your choose: ");
- choose = scan.nextInt();
- switch(choose)
- {
- case 1:
- String coor = "";
- int x = 0;
- int y = 0;
- Scanner input = new Scanner(System.in);
- System.out.print("Input the coordinate: ");
- coor = input.nextLine();
- String[] temp = coor.split(",");
- x = Integer.parseInt(temp[0]);
- y = Integer.parseInt(temp[1]);
- AddTile(x, y, player);
- break;
- }
- if(player.equals("Player1"))
- {
- player = "Player2";
- }
- else
- {
- player = "Player1";
- }
- }while(choose != 2);
- }
- static void Clear()
- {
- for(int i = 0; i < 25; i++)
- {
- System.out.println();
- }
- }
- static void CreateBoard(int w, int h)
- {
- for(int i = 0; i < w; i++)
- {
- for(int j = 0; j < h; j++)
- {
- board[i][j] = ".";
- }
- }
- }
- static void AddTile(int x, int y, String player)
- {
- String tile = "W";
- if(player.equals("Player1"))
- {
- tile = "W";
- }
- else
- {
- tile = "B";
- }
- board[x][y] = tile;
- }
- static void PrintBoard()
- {
- for(int i = 0; i < 19; i++)
- {
- for(int j = 0; j < 20; j++)
- {
- int num = i+1;
- if(i < 9 && j == 0)
- {
- System.out.print(" " + num + ": ");
- }
- else if(j == 0)
- {
- System.out.print(num + ": ");
- }
- else
- {
- System.out.print(board[i][j-1]);
- }
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment