Advertisement
Shavit

P. 126 Ex. 12.8

Mar 16th, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8.     public static void main(String[] args)
  9.     {
  10.         final int SIZE = 8;
  11.        
  12.         Scanner in = new Scanner(System.in);
  13.        
  14.         int row, col;
  15.         int points = 0;
  16.        
  17.         System.out.printf("The size of your board is %d.\n", SIZE);
  18.         Game game = new Game(SIZE);
  19.        
  20.         System.out.printf("Keep entering pairs of numbers to represent your coin's location: ");
  21.         row = in.nextInt();
  22.         col = in.nextInt();
  23.        
  24.         while(row != -1 && col != -1)
  25.         {
  26.             points += game.Move(row, col);
  27.             System.out.printf("Next: ");
  28.             row = in.nextInt();
  29.             col = in.nextInt();
  30.         }
  31.        
  32.         System.out.printf("Game over. You have %d points!", points);
  33.         in.close();
  34.     }
  35. }
  36.  
  37. // Next class
  38.  
  39. public class Game
  40. {
  41.     int[][] matrix;
  42.    
  43.     public Game(int size)
  44.     {
  45.         matrix = new int[size][size];
  46.     }
  47.    
  48.     public int Move(int row, int col)
  49.     {
  50.         int result = 0;
  51.         if(col > row)
  52.             result = 1;
  53.         else if(col < row)
  54.             result = -1;
  55.         else if(col == row)
  56.             result = 5;
  57.         return result;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement