package beans;

import java.util.List;
import java.util.ListIterator;

/**
 * Class that represents a round of a point of the game.
 * @author Lucas Pinheiro @lucaspin
 * @author Bruno Vedovetto @bleandro
 * @author Dalton Lima @daltonbr
 */
public class Round {
    private boolean ended = false;
    private boolean tied = false;
    private Player winner;
    private List<Player> playersInOrder;

    /**
     * Set the order of the players in this round
     * @param _playersInOrder {List<Player>}
     */
    public void setPlayersInOrder(List<Player> _playersInOrder) {
        this.playersInOrder = _playersInOrder;
    }

    /**
     * Return and remove the next player to play on the ruond
     * @return {Player}
     */
    private Player getNextPlayer() {
        ListIterator<Player> it = this.playersInOrder.listIterator();
        Player nextPlayer = null;

        if (it.hasNext()) {
            nextPlayer = it.next();
            it.remove();
        }

        return nextPlayer;
    }

    /**
     * Init the round flow
     */
    public void initRound() {
        while (!this.isEnded()) {
            Player nextPlayer = this.getNextPlayer();

            if (nextPlayer != null) {
                nextPlayer.chooseCard();
            } else {
                // Compare the chosen cards
                Card winnerCard = this.playersInOrder.get(0).getCurrentChosenCard();
                Player winnerPlayer = this.playersInOrder.get(0);

                // TODO: consider tie cases

                for (Player player : this.playersInOrder) {
                    Card playerCard = player.getCurrentChosenCard();
                    if (playerCard.isStrongerThan(winnerCard)) {
                        winnerCard = playerCard;
                        winnerPlayer = player;
                    }
                }

                winnerPlayer.increaseRoundScore();
                this.setWinner(winnerPlayer);
                this.setEnded(true);
            }
        }
    }

    /**
     * Set the winner of the round
     * @param _winner {Player}
     */
    public void setWinner(Player _winner) {
        this.winner = _winner;
    }

    /**
     * Get the winner of the round
     * @return {PLayer}
     */
    public Player getWinner() {
        return this.winner;
    }

    /**
     * Check if a round has ended
     * @return {Boolean}
     */
    public boolean isEnded() {
        return this.ended;
    }

    /**
     * Set the new ended status of the round
     * @param _ended {boolean}
     */
    public void setEnded(boolean _ended) {
        this.ended = _ended;
    }

    /**
     * Check is a round has tied.
     * @return {Boolean}
     */
    public boolean isTied() {
        return this.tied;
    }

    /**
     * Set the new tied status of the round
     * @param _tied {Boolean}
     */
    public void setTied(boolean _tied) {
        this.tied = _tied;
    }
}

@@ -629,386 +629,8 @@
  %7D%0A%0A
-    /**%0A     * Return and remove the next player to play on the ruond%0A     * @return %7BPlayer%7D%0A     */%0A    private Player getNextPlayer() %7B%0A        ListIterator%3CPlayer%3E it = this.playersInOrder.listIterator();%0A        Player nextPlayer = null;%0A%0A        if (it.hasNext()) %7B%0A            nextPlayer = it.next();%0A            it.remove();%0A        %7D%0A%0A        return nextPlayer;%0A    %7D%0A%0A
     
@@ -748,85 +748,57 @@
     
+for (
 Player 
-next
+a
 Player
- = this.getNextPlayer();%0A%0A            if (nextPlayer != null
+sInOrder : this.playersInOrder
 ) %7B%0A
@@ -817,18 +817,23 @@
     
-next
+a
 Player
+sInOrder
 .cho
@@ -860,20 +860,10 @@
    %7D
- else %7B%0A    
+%0A%0A
     
@@ -898,20 +898,16 @@
 n cards%0A
-    
         
@@ -971,36 +971,32 @@
 ntChosenCard();%0A
-    
             Play
@@ -1054,20 +1054,16 @@
         
-    
 // TODO:
@@ -1083,20 +1083,16 @@
  cases%0A%0A
-    
         
@@ -1151,28 +1151,24 @@
             
-    
 Card playerC
@@ -1220,20 +1220,16 @@
         
-    
 if (play
@@ -1281,28 +1281,24 @@
             
- 
-   
 winnerCard =
@@ -1322,36 +1322,32 @@
                 
-    
 winnerPlayer = p
@@ -1365,34 +1365,26 @@
             
- 
-   %7D%0A    
+%7D%0A
             
@@ -1390,36 +1390,32 @@
  %7D%0A%0A            
-  
-  
 winnerPlayer.inc
@@ -1437,36 +1437,32 @@
 ();%0A            
-    
 this.setWinner(w
@@ -1479,36 +1479,32 @@
 r);%0A            
-  
-  
 this.setEnded(tr
@@ -1508,30 +1508,16 @@
 (true);%0A
-            %7D%0A
         

Change round flow