Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 37 additions & 4 deletions src/Game.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
/**
*
* @author Trevor Hartman
* @author Angelina Perez
*
* @since Version 1.0
*
*/

import java.util.Scanner;

public class Game {
Player p1;
Player p2;
Dice die;

public void play() {
public Game(Player p1, Player p2, Dice die) {
this.p1 = p1;
this.p2 = p2;
this.die = die;
}

public Player nextPlayer(Player current) {
public void play() {
Player current = p1;
takeTurn(current);
current = nextPlayer(p1);
takeTurn(current);

System.out.println(announceWinner());
}

public void takeTurn(Player player) {
player.toss(this.die);
}

public String announceWinner() {
public Player nextPlayer(Player current) {
if(current == this.p1) {
return this.p2;
} else {
return this.p1;
}
}

public static void main(String[] args) {
public String announceWinner() {
System.out.printf("%s rolled %d%n%s rolled %d%n", p1.getName(), p1.getScore(), p2.getName(), p2.getScore());

if(this.p1.getScore() > this.p2.getScore()) {
return String.format("%s won", p1.getName());
} else if(this.p2.getScore() > this.p1.getScore()) {
return String.format("%s won", p2.getName());
} else {
return String.format("%s and %s tied", p1.getName(), p2.getName());
}
}
}