Software DevelopmentPython Programming Assignment 2UniSA STEMThe University of South AustraliaMay 2021
2 -ContentsIntroductionGraduate QualitiesSpecifications and RequirementsSubmission RequirementsExtensions and Late SubmissionsAcademic MisconductSample OutputMarking Criteria3 -IntroductionThis document describes the second programming assignment for COMP 2034 SoftwareDevelopment course.The assignment is intended to provide you with the opportunity to put into practice whatyou have learnt in the course by applying your knowledge and skills in Object-OrientedProgramming with Python programming language. The task is to develop a program withmultiple modules which allows users to play the game of Rock-Paper-Scissors or the game ofCode Break against the computer and maintains information on players. Player informationwill be stored in a text file that will be read in when the program commences. Once theapplication has read the initial player data, it should allow the user to interactively queryand manipulate the player information as well as play games against the computer.This assignment is an individual task that will require an individual submission. Eachstudent is required to submit your work via LearnOnline system by the deadline specifiedin the Submission Requirements section of this document.This document is a specification of the required end product that will be generated byimplementing the assignment. Like many specifications, it is written in English and hencewill contain some imperfectly specified parts. Please make sure you seek clarification if youare not clear on any aspect of this assignment.4 -Graduate QualitiesBy undertaking this assessment, you will progress in developing the qualities of a Universityof South Australia graduate. The Graduate qualities being assessed by this assignment are:• The ability to demonstrate and apply a body of knowledge (GQ1) gained from thelectures, practicals, and readings. This is demonstrated in your ability to applyprogramming theory to a practical situation.• The ability to effectively problem solve (GQ3) using Python and Object-OrientedProgramming concepts to complete the programming problem. Effective problemsolving is demonstrated by the ability to understand what is required, utilise therelevant information from lectures, the text book and practical work, write Pythoncode, and evaluate the effectiveness of the code by testing it.• The use of communication skills (GQ6) by producing source code that has beenproperly formatted; and by writing adequate, concise and clear comments.Communicating with others through demonstrating and explaining the programcode to the instructor.5 -Specifications and RequirementsYour solution MUST adhere to the specifications and requirements described in thisdocument.It is recommended that you develop this assignment in stages and make back-ups of yourcode regularly not only for development purpose, but also as an evidence of original work.Your program must be developed using multiple Python modules, with the number andnames of all the files strictly adhering to the specifications below.Your program must be developed with six Python files, three of them provided, and three ofthem newly written by yourself. These files must be:• assignment2.py - This file contains the main part of your program to import theother modules and run. It allows the user to interactively query and manipulate theplayer information and play games. (PROVIDED)• player.py - This file contains Player class definition to store a single playerinformation.• leaderboard.py - This file contains LeaderBoard class definition to manageplayers on a leader board.• game.py - This file contains Game class definition which is the base class of othergame classes. (PROVIDED)• rpsgame.py - This file contains RockPaperScissors class definition whichimplements the Rock-Paper-Scissors game. (PROVIDED)• codebreakgame.py - This file contains CodeBreak class definition whichimplements the Code Break game.Three files (assignment2.py, game.py, rpsgame.py) will be provided on the coursewebsite along with this document and they must be used without any modification. Tosolve this assignment, you must create and write three additional files player.py,leaderboard.py, and codebreakgame.py.Program BehaviourWhen your run the program assignment2.py, it will create an instance object of theLeaderBoard class you define and call the load() method which should load in playerinformation from a file called players.txt (provided on the course website). If theprogram has loaded the data successfully, the following message will be displayed:Players info successfully loaded.Or if the program fails to load the players info, the following message will be displayed:ERROR: Cannot load players info.Your program will enter the command mode after the player information has been loadedfrom the file. In the command mode, the program reads user input for a command with thefollowing prompt shown on the screen:6 -Please enter a command [list, add, remove, play, winner,quit]:The program will allow the user to enter commands and process these commands until the‘quit’ command is entered.The following commands must be supported:Command Descriptionlist Displays the leader board (a list of all players and theirdetails) by calling the display() method of theLeaderBoard object.add Prompts to input a name for a new player to add, and callsthe addPlayer() method of the LeaderBoard objectto add the player with the provided name. Depending onthe return value from the addPlayer() method, thefollowing messages are displayed on the screen with theplayer’s NAME :returned True: "Successfully added player NAME. "returned False: "Player NAME already exists. "remove Prompts to input the player’s name to remove then callsthe removePlayer() method of the LeaderBoardobject to remove the player with the given name.Depending on the return value, the following messagesare displayed on the screen with the player’s NAME :returned True: "Successfully removed player NAME. "returned False: "No such player found."play Asks to input the player’s name who will play the game,and checks the player’s points by calling thegetPlayerPoints() method of the LeaderBoardobject. If the player is not found (i.e. the return value isnegative), an error message “No such player found.” isdisplayed to the screen, otherwise asks for the amount ofpoints to bid, then asks to choose which game to play. Thechosen game will be played by creating an instance ofeither RockPaperScissors or CodeBreak class,then calling its play() method which will return theresult of the game (1: win, 0: tie, -1: lose). After playingthe game, the returned results and the points bid will bepassed on to calling the recordGamePlay() method ofthe LeaderBoard object to update the playerinformation.winner Prints the details of the winning player who has thehighest number of points by calling the getWinner()method of the LeaderBoard object.7 -quit Causes the program to quit, displaying a message “Thankyou for playing!”. Upon quitting, the program will call thesave() method of the LeaderBoard object which willsave the player information to a file named output.txtwhich is in the same format as the input players.txtfile. Upon successfully saving the information the programwill show a message, “Players info successfully saved.” If itfails saving the information, the program will show amessage, “ERROR: Cannot save players info.”debug This is a hidden command (not shown in the prompt) thatwill turn the debug mode on or off. If the debug mode ison, the debugMode property of the game object will beset to True which will let the answer be printed.After performing each command, the program returns to command mode, prompting theuser to input next command.Class SpecificationsBelow are detailed specifications of the three classes you must define in three files:player.py, leaderboard.py, and codebreakgame.py.• Player classThe Player class stores the information for each player. This class must be defined in theplayer.py file, and must have the following public data attributes:Data AttributesA string, name of the player which may include white spaces.An integer, number of games playedAn integer, number of games wonAn integer, number of games lostAn integer, number of games tiedAn integer, current pointsThe Player class must have an initialiser method that takes the name of the player as aparameter, and initialises the name data attribute, as well as sets the rest of the attributesto 0, except the current points which must be initialised to 100.The Player class must also have a string conversion method that returns a stringdescribing the player object including the name, the number of games played, winning rate,and the current points remaining. For example, for a player named "John Doe" who haswon 4 games out of 7 games and has 75 remaining points, it must return a string in thefollowing format:"John Doe has 75 points and a winning rate of 57.1%."Note the winning rate should show 1 digit under the decimal point.8 -If the player did not play any games, the string must be in the following format:"John Doe has 100 points, and never played a game."• LeaderBoard classThe LeaderBoard class manages a list of players (i.e., instance objects of the Playerclass). The LeaderBoard class must be defined in the leaderboard.py file, and musthave only one private (i.e. hidden) data attribute which is the list of players.The LeaderBoard class must define eight public methods, load(), save(),display(), addPlayer(), removePlayer(), getPlayerPoints(),getWinner(), and recordGamePlay(), as well as two private methods,__findPlayer() and __sortPlayers(). Below are detailed specifications of eachmethod:load()This method loads in the player information from a file named players.txt (provided onthe course website together with this document). It reads in the file and creates a list ofinstances of the Player class you defined, and updates the list of players data attributewith the loaded information. In the players.txt file, each player is described in twolines of text. The name of the player (which may include white spaces) is stored in the firstline. The very next line contains the number of games played, games won, games lost,games tied, and the current remaining points, all stored in one line and separated by thespace character. Below is a sample content of the players.txt file with three players:John Doe4 0 1 70Lisa Smith13 2 1 105Andrew Whittaker0 7 0 55You must use the input file players.txt provided on the course website. You are notsupposed to create it yourself or edit the provided input file. You may assume that all datain this file is in the correct format. Note there could be empty lines at the end of the filewhich should be ignored.After loading the data, the load() method must call the __sortPlayers() method tokeep the player list in the order of their points. It should not print any message onto thescreen, but must return True if the data has been successfully loaded, or False if there isany error.save()This method saves the player information to the output.txt file which should have thesame format as the input players.txt file. It should not print any message onto thescreen, but must return True if the data has been successfully saved, or False if there isany error.9 -display()This method shows the leader board onto the screen in the format as described below:• The player name field is displayed under the “Player Name” heading, and should be 30characters wide, left justified.• The number of games played is displayed under the “P” heading, and should be 2characters wide, right justified.• The number of games won is displayed under the “W” heading, and should be 2characters wide, right justified.• The number of games lost is displayed under the “L” heading, and should be 2characters wide, right justified.• The number of games tied is displayed under the “T” heading, and should be 2characters wide, right justified.• The winning rate is displayed under the “W-Rate” heading, and should be 6 characterswide, right justified, showing 1 digit under the decimal point with a percent sign (%) atthe end (Hint: 100.0% has 6 characters). Note that the winning rate is not part of theinformation stored in the Player structure, but should be calculated based on numberof games played and number of games won. If the number of games played is zero,the winning rate is treated as zero percent.• The points is displayed under the “Points” heading, and should be 6 characters wide,right justified.• Each of the field should be separated by a single empty space character.
...