Last active
June 30, 2024 14:36
-
-
Save trikitrok/c293de4f0e7cf55ac424 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.adaptionsoft.games.uglytrivia; | |
public class Game { | |
private Rules rules; | |
private Players players; | |
private Player currentPlayer; | |
private Turn turn; | |
public Game(Players players, Rules rules, Turn turn) { | |
this.players = players; | |
this.rules = rules; | |
this.turn = turn; | |
} | |
public void run() { | |
presentPlayers(); | |
play(); | |
} | |
private void play() { | |
do { | |
nextPlayer(); | |
playTurn(); | |
} while (noPlayerHasWon()); | |
} | |
private void presentPlayers() { | |
int num = 0; | |
for (Player player : players) { | |
System.out.println(player + " was added"); | |
System.out.println("They are player number " + String.valueOf(++num)); | |
} | |
} | |
private void playTurn() { | |
turn.play(currentPlayer); | |
} | |
private void nextPlayer() { | |
currentPlayer = players.next(); | |
System.out.println(currentPlayer + " is the current player"); | |
} | |
private boolean noPlayerHasWon() { | |
return !currentPlayer.hasWonAccordingTo(rules); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment