/** * This class instanciates a mock "Game" and tracks downloads, high scores, etc. * * @author George Wilkinson * @version 24/10/23 */ public class Game { // Initialise title String to hold the title of the game. private String title; // Initialise objective String to hold the objective of the game. private String objective; // Initialise costInPence integer to hold the cost of the game. private int costInPence; // Initialise numberOfDownloads integer to hold the number of downloads the game has. private int numberOfDownloads; // Initialise bestScoreName String to hold the name of the highest score. private String bestScoreName; // Initialise bestScore integer to hold the best score game has. private int bestScore; // Initialise a gameManager object to hold the manager details assigned to the game. private Manager gameManager; /** * Default Constructor for "My First Game" */ public Game() { // Initialise a default game title = "My First Game"; objective = "To Play a Game"; costInPence = 100; //Gives "My First Game" a default manager with the following fields. gameManager = new Manager(); numberOfDownloads = 10; bestScoreName = "George"; bestScore = 200; } /** * Old non-default constructor. * public Game( String title, String objective, int costInPence ) */ public Game( String title, String objective, int costInPence, Manager gameManager ) { // initialise instance variables this.title = title; this.objective = objective; this.costInPence = costInPence; this.gameManager = gameManager; numberOfDownloads = 0; bestScoreName = null; bestScore = 0; } /** * * FIELD ACCESSOR START * */ /** * Returns the @title value. */ public String getTitle() { return title; } /** * Returns the @objective value. */ public String getObjective() { return objective; } /** * Returns the @costInPence value. */ public int getCostInPence() { return costInPence; } /** * Returns the @bestScore value. */ public int getBestScore() { return bestScore; } /** * Returns the @bestScoreName value. **/ public String getBestScoreName() { return bestScoreName; } /** * Return the @gameManager value. */ public Manager getManager() { return gameManager; } /** * * FIELD MUTATOR START * */ /** * Sets @title to a user-input value. */ public void setTitle( String newTitle ) { title = newTitle; } /** * Sets @objective to a user-input value. */ public void setObjective( String newObjective ) { objective = newObjective; } /** * Sets @costInPence to a user-input value. */ public void setCostInPence( int newCostInPence ) { costInPence = newCostInPence; } /** * Sets @bestScore to a user-input value */ public void setBestScore( int newBestScore ) { bestScore = newBestScore; } /** * Sets @bestScoreName to a user-input value. */ public void setBestScoreName( String newBestScoreName ) { bestScoreName = newBestScoreName; } /** * Set @gameManager to a new gameManager object. */ public void setGameManager( Manager newGameManager ) { gameManager = newGameManager; } /** * * FUNCTIONAL MUTATOR START * */ /** * Simulates a user downloading the game. */ public void download() { System.out.println("Congratulations on your download! Please pay " + costInPence + " pence. Thank you"); //Increment number of downloads. numberOfDownloads += 1; } /** * Checks to see if player's score is the highest. If so, replace highest score and name. */ public void checkScore( int playerScore, String playerName ) { if( playerScore > bestScore ) { //Set new score, and player of said score to the "best" using the mutator methods made above. setBestScore( playerScore ); setBestScoreName( playerName ); } } /** * Prints, to terminal, the fields and their values in a strict format. */ public void printReport() { System.out.println( "Title: " + title ); System.out.println( "Objective: " + objective ); System.out.println( "Download cost: " + costInPence ); System.out.println( "Number of downloads to date: " + numberOfDownloads ); System.out.println( "Best score to date: " + bestScore ); System.out.println( "Player with best score: " + bestScoreName ); System.out.println( "Total earnings to date: " + calculateEarnings() ); System.out.println( "Game manager: " + gameManager.getSurname() ); } /** * * FUNCTIONAL ACCESSOR START * */ /** * Return earnings by calculating @numberOfDownloads * @costInPence. */ public int calculateEarnings() { return ( numberOfDownloads * costInPence ); } }