Advertisement
AskTomorrow

Untitled

Feb 9th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. package xyz.antonkazakov;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. //N игроков
  7. //K костей
  8. //M побед
  9.  
  10. public class Game extends Thread {
  11.  
  12.     int playersCount;
  13.     int winsCount;
  14.  
  15.     public int getPlayersCount() {
  16.         return playersCount;
  17.     }
  18.  
  19.     public void setPlayersCount(int playersCount) {
  20.         this.playersCount = playersCount;
  21.     }
  22.  
  23.     public int getWinsCount() {
  24.         return winsCount;
  25.     }
  26.  
  27.     public void setWinsCount(int winsCount) {
  28.         this.winsCount = winsCount;
  29.     }
  30.  
  31.     Game() {
  32.         this.setWinsCount(1);
  33.         this.setPlayersCount(1);
  34.         for (int i = 0; i < getPlayersCount(); i++) {
  35.             players.add(new Player(1, i + 1));
  36.         }
  37.     }
  38.  
  39.     Game(int m, int n, int k) {
  40.         this.setPlayersCount(n);
  41.         this.setWinsCount(m);
  42.         for (int i = 0; i < getPlayersCount(); i++) {
  43.             players.add(new Player(k, i + 1));
  44.         }
  45.     }
  46.  
  47.     ArrayList<Player> players = new ArrayList<>();
  48.  
  49.     public boolean isCommentatorSpeaking = false;
  50.  
  51.     private Commentator commentator;
  52.  
  53.     public Commentator getCommentator() {
  54.         return commentator;
  55.     }
  56.  
  57.     public void setCommentator(Commentator commentator) {
  58.         this.commentator = commentator;
  59.     }
  60.  
  61.     @Override
  62.     public void start() {
  63.         for (int j = 0; j < this.getWinsCount(); j++) {
  64.             notifyAll();
  65.             for (int i = 0; i < players.size(); i++) {
  66.                 players.get(i).run();
  67.                 if (players.get(i).getCurrRes() == players.get(i).getCubesCount() * 6) {
  68.                     commentator.setMessage("Round finished, player: " + players.get(i).getPlayerName() + "won this round");
  69.                     commentator.run();
  70.                     break;
  71.                 }
  72.                 else {
  73.                     commentator.setMessage("Player's " + players.get(i).getPlayerName() + " result: " + players.get(i).getCurrRes());
  74.                     commentator.run();
  75.                 }
  76.             }
  77.         }
  78.     }
  79.  
  80.     @Override
  81.     public void run() {
  82.         this.run();
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement