Skip to content

Commit

Permalink
refactoring setAndPrintWinner()
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmp33 committed Sep 5, 2021
1 parent a0a4cf8 commit 2d4ec53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 30 deletions.
25 changes: 10 additions & 15 deletions src/com/labrisca/catalan/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void setTrump() {

// print all cards and their attributes
private void printAllCards() {
System.out.println("Informació de totes les cartes:");
System.out.println("\nInformació de totes les cartes:");
for (Player player : players) {
System.out.println("Cartes guanyades " + player.getName() + ":");
for (Card card : player.getWonCards()) {
Expand Down Expand Up @@ -267,21 +267,16 @@ private void printPointsAndCards() {

// set and print game's winner
private void setAndPrintWinner() {
int temp = -1;
Player winner = players.get(0);
Player winner = null;
boolean draw = false;
for (Player p : players) {
int maxPoints = p.getPoints();

if (maxPoints > temp) {
temp = maxPoints;
winner = p;
} else if (maxPoints == temp) {
draw = true;
winner = null;
break;
}
}
Player player0 = players.get(0);
Player player1 = players.get(1);
int pointsPlayer0 = player0.getPoints();
int pointsPlayer1 = player1.getPoints();

if (pointsPlayer0 > pointsPlayer1) winner = player0;
else if (pointsPlayer1 > pointsPlayer0) winner = player1;
else draw = true;

String ln = "#########--------------------------------------------#########";
String s;
Expand Down
25 changes: 10 additions & 15 deletions src/com/labrisca/english/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void setTrump() {

// print all cards and their attributes
private void printAllCards() {
System.out.println("Information of all the cards:");
System.out.println("\nInformation of all the cards:");
for (Player player : players) {
System.out.println(player.getName() + " won cards:");
for (Card card : player.getWonCards()) {
Expand Down Expand Up @@ -266,21 +266,16 @@ private void printPointsAndCards() {

// set and print game's winner
private void setAndPrintWinner() {
int temp = -1;
Player winner = players.get(0);
Player winner = null;
boolean draw = false;
for (Player p : players) {
int maxPoints = p.getPoints();

if (maxPoints > temp) {
temp = maxPoints;
winner = p;
} else if (maxPoints == temp) {
draw = true;
winner = null;
break;
}
}
Player player0 = players.get(0);
Player player1 = players.get(1);
int pointsPlayer0 = player0.getPoints();
int pointsPlayer1 = player1.getPoints();

if (pointsPlayer0 > pointsPlayer1) winner = player0;
else if (pointsPlayer1 > pointsPlayer0) winner = player1;
else draw = true;

String ln = "######---------------------------------------######";
String s;
Expand Down

0 comments on commit 2d4ec53

Please sign in to comment.