diff --git a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java index 594d1b2..34d1df5 100644 --- a/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java +++ b/app/src/main/java/ch/zhaw/projekt2/turnierverwaltung/Game.java @@ -1,77 +1,171 @@ package ch.zhaw.projekt2.turnierverwaltung; import java.io.Serializable; +import java.util.logging.Logger; +/** + * Class Representing a game, implements Serializable to be saved inside a tournament + * Holding the data and points for a single match + */ public class Game implements Serializable { private Participant participant1, participant2; private int points1, points2; private Place place; private Game previousGame1, previousGame2; + private static final Logger logger = Logger.getLogger(FileIO.class.getCanonicalName()); + /** + * Constructor to initialize a new game. + * Two participants are needed. + * + * @param participant1 that is added to the game + * @param participant2 that is added to the game + */ public Game(Participant participant1, Participant participant2) { + logger.fine("initializing a new game with the participants: " + participant1 + ", " + participant2); this.participant1 = participant1; this.participant2 = participant2; } - public Game(Game previousGame1, Game previousGame2){ + /** + * Constructor to initialize a game with two previous games. + * + * @param previousGame1 previous game (connecting to this game in the hierarchy) + * @param previousGame2 other previous game (connecting to this game in the hierarchy) + */ + public Game(Game previousGame1, Game previousGame2) { + logger.fine("initializing a new game with the previous games: " + previousGame1 + ", " + previousGame2); this.previousGame1 = previousGame1; this.previousGame2 = previousGame2; } + /** + * Method to get the points of the first participant + * + * @return points of participant 1 + */ public int getPoints1() { + logger.fine("Returning points of: " + participant1 + ", holding: " + points1 + " points"); return points1; } + /** + * Method to set the points of the first participant + * + * @param points1 to be set for the first participant + */ public void setPoints1(int points1) { + logger.fine("Setting points of: " + participant1 + ", to " + points1 + " points"); this.points1 = points1; } + /** + * Method to get the points of the second participant + * + * @return points of participant 2 + */ public int getPoints2() { + logger.fine("Returning points of: " + participant2 + ", holding: " + points2 + " points"); return points2; } + /** + * Method to set the points of the second participant + * + * @param points2 to be set for the second participant + */ public void setPoints2(int points2) { + logger.fine("Setting points of: " + participant2 + ", to " + points2 + " points"); this.points2 = points2; } + /** + * Method to get the first Participant + * + * @return the first Participant + */ public Participant getParticipant1() { + logger.fine("Returning the first participant: " + participant1); return participant1; } + /** + * Method to set the first participant + * + * @param participant1 to be set as the first participant + */ public void setParticipant1(Participant participant1) { + logger.fine("Setting the first Participant as: " + participant1); this.participant1 = participant1; } + /** + * Method to set the second participant + * + * @param participant2 to be set as the second participant + */ public void setParticipant2(Participant participant2) { + logger.fine("Setting the second Participant as: " + participant2); this.participant2 = participant2; } + /** + * Method to get the second Participant + * + * @return the second participant + */ public Participant getParticipant2() { + logger.fine("Returning the second participant: " + participant2); return participant2; } + /** + * Method to set the place of a game + * + * @param place to be set for the game + */ public void setPlace(Place place) { + logger.fine("Setting the location of the game " + this + " to: " + place); this.place = place; } + /** + * Method to get the place of a game + * + * @return the place of the game + */ public Place getPlace() { + logger.fine("Returning the place of the game, current Location: " + place); return place; } - public Participant getWinner(){ - if(points1 > points2){ + /** + * Method to determine the winner of a game, if there is a draw null will be returned. + * + * @return the winner of the game or null if draw + */ + public Participant getWinner() { + logger.finer("Determining winner of game"); + if (points1 > points2) { + logger.fine(participant1 + "has won the game"); return participant1; - } else if(points2 > points1){ + } else if (points2 > points1) { + logger.fine(participant2 + "has won the game"); return participant2; } else { + logger.fine("There is no winner"); return null; } } - public void refreshParticipants(){ + /** + * Method that gets the winner of previous games and sets them as the participants of this game. + */ + public void refreshParticipants() { participant1 = previousGame1.getWinner(); participant2 = previousGame2.getWinner(); + logger.fine("Refreshed Participants, new Participants: " + participant1 + ", " + participant2); } }