TheSTRIG

tugas02 rehan

Nov 14th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.19 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CaturJawa
  4. {
  5.     static String[][] board = new String[19][19];
  6.     static String player = "Player 1";
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         CreateBoard(19, 19);
  11.  
  12.         Scanner scan = new Scanner(System.in);
  13.         int choose = 0;
  14.  
  15.         do
  16.         {
  17.             Clear();
  18.             System.out.println("1. Play Game");
  19.             System.out.println("2. Exit");
  20.             System.out.print("Your choose: ");
  21.             choose = scan.nextInt();
  22.  
  23.             switch(choose)
  24.             {
  25.                 case 1:
  26.                 InGame();
  27.                     break;
  28.             }
  29.  
  30.         }while(choose != 2);
  31.     }
  32.  
  33.     static void InGame()
  34.     {
  35.         int choose = 0;
  36.         Scanner scan = new Scanner(System.in);
  37.  
  38.         do
  39.         {
  40.             Clear();
  41.             PrintBoard();
  42.             System.out.println("1. Add Tile");
  43.             System.out.println("2. Exit");
  44.             System.out.println(player);
  45.             System.out.print("Your choose: ");
  46.             choose = scan.nextInt();
  47.  
  48.             switch(choose)
  49.             {
  50.                 case 1:
  51.                     String coor = "";
  52.                     int x = 0;
  53.                     int y = 0;
  54.  
  55.                     Scanner input = new Scanner(System.in);
  56.  
  57.                     System.out.print("Input the coordinate: ");
  58.                     coor = input.nextLine();
  59.  
  60.                     String[] temp = coor.split(",");
  61.  
  62.                     x = Integer.parseInt(temp[0]);
  63.                     y = Integer.parseInt(temp[1]);
  64.  
  65.                     AddTile(x, y, player);
  66.  
  67.                     break;
  68.             }
  69.  
  70.             if(player.equals("Player1"))
  71.             {
  72.                 player = "Player2";
  73.             }
  74.             else
  75.             {
  76.                 player = "Player1";
  77.             }
  78.         }while(choose != 2);
  79.     }
  80.  
  81.     static void Clear()
  82.     {
  83.         for(int i = 0; i < 25; i++)
  84.         {
  85.             System.out.println();
  86.         }
  87.     }
  88.  
  89.     static void CreateBoard(int w, int h)
  90.     {
  91.         for(int i = 0; i < w; i++)
  92.         {
  93.             for(int j = 0; j < h; j++)
  94.             {
  95.                 board[i][j] = ".";
  96.             }
  97.         }
  98.     }
  99.  
  100.     static void AddTile(int x, int y, String player)
  101.     {
  102.         String tile = "W";
  103.  
  104.         if(player.equals("Player1"))
  105.         {
  106.             tile = "W";
  107.         }
  108.         else
  109.         {
  110.             tile = "B";
  111.         }
  112.  
  113.         board[x][y] = tile;
  114.     }
  115.  
  116.     static void PrintBoard()
  117.     {
  118.         for(int i = 0; i < 19; i++)
  119.         {
  120.             for(int j = 0; j < 20; j++)
  121.             {
  122.                 int num = i+1;
  123.  
  124.                 if(i < 9 && j == 0)
  125.                 {
  126.                     System.out.print(" " + num + ": ");
  127.                 }
  128.                 else if(j == 0)
  129.                 {
  130.                     System.out.print(num + ": ");
  131.                 }
  132.                 else
  133.                 {
  134.                     System.out.print(board[i][j-1]);
  135.                 }
  136.             }
  137.  
  138.             System.out.println();
  139.         }
  140.     }
  141. }
Add Comment
Please, Sign In to add comment