Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package xyz.antonkazakov;
- import java.util.ArrayList;
- import java.util.List;
- //N игроков
- //K костей
- //M побед
- public class Game extends Thread {
- int playersCount;
- int winsCount;
- public int getPlayersCount() {
- return playersCount;
- }
- public void setPlayersCount(int playersCount) {
- this.playersCount = playersCount;
- }
- public int getWinsCount() {
- return winsCount;
- }
- public void setWinsCount(int winsCount) {
- this.winsCount = winsCount;
- }
- Game() {
- this.setWinsCount(1);
- this.setPlayersCount(1);
- for (int i = 0; i < getPlayersCount(); i++) {
- players.add(new Player(1, i + 1));
- }
- }
- Game(int m, int n, int k) {
- this.setPlayersCount(n);
- this.setWinsCount(m);
- for (int i = 0; i < getPlayersCount(); i++) {
- players.add(new Player(k, i + 1));
- }
- }
- ArrayList<Player> players = new ArrayList<>();
- public boolean isCommentatorSpeaking = false;
- private Commentator commentator;
- public Commentator getCommentator() {
- return commentator;
- }
- public void setCommentator(Commentator commentator) {
- this.commentator = commentator;
- }
- @Override
- public void start() {
- for (int j = 0; j < this.getWinsCount(); j++) {
- int mx = 0;
- int mxId = 1;
- notifyAll();
- for (int i = 0; i < players.size(); i++) {
- players.get(i).run();
- if (players.get(i).getCurrRes() == players.get(i).getCubesCount() * 6) {
- commentator.setMessage("Round finished, player: " + players.get(i).getPlayerName() + "won this round");
- commentator.run();
- break;
- }
- else {
- if (players.get(i).getCurrRes() > mx) {
- mx = players.get(i).getCurrRes();
- mxId = players.get(i).getID();
- }
- commentator.setMessage("Player's " + players.get(i).getPlayerName() + " result: " + players.get(i).getCurrRes());
- commentator.run();
- }
- }
- commentator.setMessage("Round finished. The winner is: " + players.get(mxId).getPlayerName() + " with score: " + mx);
- }
- }
- @Override
- public void run() {
- this.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement