Advertisement
makispaiktis

Game.java

Nov 29th, 2018 (edited)
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Map;
  3. import java.util.TreeMap;
  4.  
  5. public class Game {
  6.    
  7.     int round;
  8.    
  9.     // Constructors
  10.     public Game() {
  11.         round = 0;
  12.     }
  13.    
  14.     public Game(int round) {
  15.         this.round = round;
  16.     }
  17.    
  18.     // Getters, setters
  19.     public void setRound(int round) {
  20.         this.round = round;
  21.     }
  22.    
  23.     public int getRound() {
  24.         return round;
  25.     }
  26.    
  27.    
  28.    
  29.    
  30.     /*public Map <Integer, Integer> setTurns(ArrayList <Object> players) {
  31.    
  32.         Map <Integer, Integer> playerTurns = new TreeMap <Integer, Integer> ();
  33.         for(int i=0; i<players.size(); i++) {
  34.            
  35.             int roll = (int)Math.random() * 6 + 1;
  36.             //Integer temp = (Integer)roll;
  37.             playerTurns.put(roll, );
  38.         }
  39.     }
  40.     */
  41.    
  42.    
  43.    
  44.     public static void main(String[] args) {
  45.         ArrayList<Integer[]> heuristicPath = new ArrayList<Integer[]>();
  46.         Map<Integer, Integer> playerTurn= new TreeMap<Integer, Integer>();
  47.         Board gameBoard = new Board(10, 20, 3, 3, 6);
  48.         gameBoard.createBoard();
  49.         gameBoard.createElementBoard();
  50.         Player mavioux = new Player(1, "Mavioux", 0, gameBoard);
  51.         HeuristicPlayer thomas = new HeuristicPlayer(2, "Thomas", 0, gameBoard, heuristicPath);
  52.         Game game = new Game(0);
  53.        
  54.         System.out.println();
  55.         for(int i = 0; i < gameBoard.tiles.length; i++) {
  56.             for(int j = 0; j < gameBoard.tiles[i].length; j++) {
  57.                 System.out.print(gameBoard.tiles[i][j] + " ");
  58.             }
  59.             System.out.println();
  60.         }
  61.         System.out.println();
  62.         System.out.println();
  63.         System.out.println();
  64.        
  65.         int[] maviouxArray = new int[5];
  66.         int thomasArray = 0;
  67.         maviouxArray[0] = 0;
  68.         int turn = 1;
  69.         int roll= 0;
  70.        
  71.         while(maviouxArray[0] < gameBoard.getM() * gameBoard.getN() && thomasArray < gameBoard.getM() * gameBoard.getN()) {
  72.             switch(turn) {
  73.             case 1:
  74.                 System.out.println(mavioux.getName() + "'s turn:");
  75.                 System.out.println("Starting tile: " + maviouxArray[0]);
  76.                 roll = 1 + (int)(Math.random() * 6);
  77.                 System.out.println("You rolled: " + roll);
  78.                 maviouxArray = mavioux.move(maviouxArray[0], roll);
  79.                 System.out.println("Ending tile: " + maviouxArray[0]);
  80.                 turn++;
  81.                 break;
  82.             case 2:
  83.                 System.out.println(thomas.getName() + "'s turn:");
  84.                 System.out.println("Starting tile: " + thomasArray);
  85.                 thomasArray = thomas.getNextMove(thomasArray);
  86.                 thomas.statistics();
  87.                 System.out.println("Ending tile: " + thomasArray);
  88.                 turn = 1;
  89.                 break;
  90.             }
  91.            
  92.             game.setRound(game.getRound() + 1);
  93.             System.out.println();
  94.            
  95.             if(game.round >= 100) {
  96.                 break;
  97.             }
  98.            
  99.            
  100.         }
  101.        
  102.         /*// Give 15 points to the player who finished first
  103.         switch(turn) {
  104.         case 1:
  105.             thomas.setScore(thomas.getScore() + 15);
  106.             break;
  107.            
  108.         case 2:
  109.             mavioux.setScore(mavioux.getScore() + 15);
  110.             break;
  111.            
  112.         default:
  113.             System.out.println("Error!");
  114.         }*/
  115.        
  116.         System.out.println();
  117.         System.out.println("Rounds: " + game.getRound());
  118.         System.out.println("Score of Mavioux: " + mavioux.getScore());
  119.         System.out.println("Score of Thomas: " + thomas.getScore());
  120.         System.out.print("The winner of the game is: ");
  121.        
  122.         // Choose the winner
  123.         if(mavioux.getScore() > thomas.getScore()) {
  124.             System.out.println("Mavioux");
  125.         }
  126.        
  127.         else if(mavioux.getScore() < thomas.getScore()) {
  128.             System.out.println("Thomas");
  129.            
  130.         }
  131.        
  132.         else {
  133.             switch(turn) {
  134.             case 1:
  135.                 System.out.println("Thomas");
  136.                 break;
  137.                
  138.             case 2:
  139.                 System.out.println("Mavioux");
  140.                 break;
  141.                
  142.             default:
  143.                 System.out.println("Error!");
  144.             }
  145.            
  146.         }
  147.        
  148.        
  149.        
  150.        
  151.     }
  152.    
  153.    
  154.    
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement