The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Hello, finals week is coming up and I would appreciate help on this project. I am going to use this answer as a reference and not blindly copy it because I actually want to understand the material as well. This is for the program python.
Rock, Paper, Scissors GameFinal ProjectFor the final project you are to create a Rock, Paper, Scissors game in Python named rps.pyaccording to the requirements specified in this document.Description:Create a menu-driven rock, paper, scissors game that a user plays against thecomputer with the ability to save and load a game and its associated play statistics.This Wikipedia article describes the game play:http://en.wikipedia.org/wiki/Rock-paper-scissorsDuring a round of play the user chooses rock, paper, or scissors from a menu and the computermakes its choice randomly. For each round it is possible for the user to win, lose, or tie. Thestatistics that are maintained within auserobject for a game are wins, losses, and ties. When agame is exited, theuserplay statistics (wins, losses, and ties) are to be updated in theusersclassand then will be saved. Whenever a new User object is created, add it to your Users objects list.Requirements:User ClassWrite a class named user and save it as a file named User.py. The user class should have thefollowing data attributes:__usernameTo store the name of the player__winsTo store the number of wins__tiesTo store the number of ties__lossesTo store the number of losses__createdTo store when the user account was createdThe User class should also have the following methods:__init__This method takes 4 parameters, the username, wins, ties, and losses(when initializing the last 3 will be zeroes eg. (John,0,0,0)) It should create__username, __wins, __ties, and __losses based on those parameters and itshould create __created based on the current time.get_usernameReturns the value of __username fieldget_user_winsReturn the value of the __wins fieldset_user_winsTakes in 1 parameter and sets __wins to that parameterget_user_tiesReturns the value of the __ties fieldset_user_tiesTakes in 1 parameters and sets __ties to that parameterget_user_lossesReturns the value of the __losses field
Rock, Paper, Scissors GameFinal Projectset_user_lossesTakes in 1 parameter and sets __losses to that parameterget_roundReturns the current round number (not the next)HINT: return (wins + ties + losses)get_ageThis method calculates the difference between the current time andthe value of the __age field. It should return a string based on theage of the user. For example, this method should return thefollowing:30s if the user was created 30 seconds ago15m if the user was created 15 minutes ago1h if the created was posted 1 hour, 10 minutes, and 42 secondsagodisplay_userDisplays the username and stats (check sample output forformatting)* Note that the string returned from __get_age is only concerned with the largest unit of time. Ifthe user is 0 to 59 seconds old, the value returned from __get_age will end with an “s” for“seconds”. If the user is some number of minutes old, it will end with an “m” and ignore theseconds. Likewise, if the user is 1 or more hours old, it will ignore both the minutes and seconds.To work with time, you’ll need to use Python’s time module. The documentation for that moduleis available here:https://docs.python.org/3.4/library/time.htmlHINT:If we have a user that wins a round and want to increment their wins stat.user.get_user_wins() will get the current number of wins (it is an integer)we add one with + 1we pass that number as a parameter to user.set_user_wins(new incremented wins)in working code:user.set_user_wins(user.get_user_wins()+1)Users ClassWrite a class named users and save it as a file named Users.py. The users class should have thefollowing data attributes:__user_listIs a list that will store each user
Rock, Paper, Scissors GameFinal Project__rps_file_nameTo store the name of the file in which we read and write to.“rps.dat”so simply self.__rps_file_name = “rps.dat”The Users class should also have the following methods:def load_userswill attempt to use pickle to read the list of users into user_listfrom the file “rps.dat”def save_userswill attempt to use pickle to write the list of users, user_list, to thefile “rps.dat”##CRUD OPERATIONS###create, read, update, delete (we don’t need to worry about delete)#def create_userTakes in a parameter, username, and checks to see if it exists.If itexists we return False, if it doesn’t exist, we add it to the list settingthe wins, ties, losses to 0 and return True.If the name exists, we print the error:[!]Error: This User already exists.def read_userTakes in a parameter, username, and checks to see if it exists.If itexists, we return the True AND the user object which has the samename.If it doesn’t exist, we return False and the user object.Atthe beginning of the function set found_user = None.We willreturn True, found_user or return False, found_user.To check if auser exists, we will compare each user name in the list (for user inself.__user_list:) to username.So compare each user.get_name()to usernameIf the name doesn’t exist, we print the error:[!]Error: This User doesn't exist.def update_userTakes in a parameter, a user, We find the user in the list and updateusers wins, losses, and ties using the accessor methods.We willget the current loaded users stats and update the user that is savedin the list to these new statsEg. user.set_user_wins(current_user.get_user_wins)If the name doesn’t exist, we print the error:[!]Error: This User doesn't exist.#This isn’t neededdef delete_userTakes in a parameter, a username, and deletes that user from thelist.If the name doesn’t exist, we print the error:[!]Error: This User doesn't exist.
Rock, Paper, Scissors GameFinal Projectdef display_highscore Takes in no parameters.Uses the list of users and creates aranking of the Win percentage based on the wins divided by therounds. It ranks everyone on the list from 1-N, N being the lengthof the list. Don’t worry about ranking ties in the highscore. Eg. if 2people have a .50 Win percentage either can be firstHINT:This is one way to do thisStart with making separate duplicate listtemp_list = list(self.__user_list)With this temp_list we can use temp_list.remove(user) toremove a user.Think about the when we did max and first_pass…cur_max_user = user.cur_max_ratio = (user.get_user_wins/user.get_round())If the next users ratio is greater than the max..make it thenew user and the ratio..then at the end delete it..do this untilthe temp_list length is 0RPS.pyFor menus in the game, the user makes a selection from the menu by entering the number of theirchoice. If the user enters something other than a number or a number outside the range of thechoices provided in the menu they are to be given feedback that their choice is not valid andasked for the input again.HINT: To help clean up code and prevent duplicate code making these functions will help.1.It would be easy to have 3 functions to display each menu.2.It would also be easy to have a function that takes in the range of numbers for amenu, makes sure they are valid, and returns a choice.Examples:#main menuchoice = get_choice(1,4)#game menuchoice = get_choice(1,3)#round menuchoice = get_choice(1,3)Under no circumstance should input from the user crash the program. When the program is run,the following title, menu, and input prompt are to be displayed:Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High scores[4] Exit
Rock, Paper, Scissors GameFinal ProjectWhat would you like to do?If the user chooses1to start a new game they are to be prompted for their name and game play isto proceed after their name is entered.If the user chooses2to load a game then they should be taken to a prompt to enter a name that isto be used to load a saved game.If the user chooses3to display the high scores the program will display a list of the high scoresin wins per number of rounds ratio is descending order. For example•John has 2 wins, 1 tie, 3 loss, is 2 win / 6 rounds = .33•Stephanie1 win, 0 ties, 1 losses, is 1 win / 2 round = .5So when presenting High ScoresWhat would you like to do? 3Rank NameWin% Wins TiesLosses1Stephanie0.50 1012John0.33 213If the user chooses4to quit the game the program is to exit.1.Start New GameIf the user chooses to start a new game the program is to prompt the user for their name using thefollowing prompt:What is your name?After the name is entered the program is to respond with a line that is “Hello” followed by thename of the user, a period, and the phrase “Let’s play!” Example:Hello John. Let’s play!If the user already exists in the list of users, the user is to be presented with a message indicatingthat the username given already exists and then presented with the startup menu described at thetop of the requirements.The message is to be an error message Example:[!]Error: This User already exists.After the hello statement is presented to the user, game menu is to proceed. Game menu isdescribed below in the Game menu section.2.Load Game
Rock, Paper, Scissors GameFinal ProjectIf the user chooses to load an existing game, the program is to prompt the user for their nameusing the following prompt:What is your name?After the name is entered the program is to attempt to load a game user by finding it in the list ofusers located in Users class. If the user object is found, the information about the game andstatistics are to be loaded locally, a welcome back message is to be presented to the user, andgame play is to proceed. The round number displayed is to be based on the number of roundspreviously played plus one. (Note: number of rounds previously played is sum of wins, losses,and ties plus one) Game menu is described below in the Game menu section.The welcome back message is to be “Welcome back ” followed by the user’s name, a period, andthe phrase “Let’s Play!” Example:Welcome back John. Let’s play!If the user is not found, the user is to be presented with a message indicating the users data couldnot be found and then presented with the startup menu described at the top of the requirements.The message is to be an error message Example:[!]Error: This User doesn't exist.3.Display High ScoresIf the user chooses display High Scores the program will display a list of the high scores rank bythe number of wins divided by the total number of rounds in descending order. The text can beformatted using the “\t” tab or however else you would like.For the name I used a"{:<15}".format(cur_max_user.get_username()) and then you should also round the Win% to 2decimal places.Rank NameWin% Wins TiesLosses1Stephanie0.50 1012John0.33 2134.ExitIf the user chooses to exit, the program is to exit.Game MenuThis section describes the game menu. When at the game menu the following title, menu, andinput prompt are to be displayed:
Rock, Paper, Scissors GameFinal ProjectRPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?1.Play A RoundIf the user chooses to Play a Round the program will move to the Game Play portion of theprogram.This is described below2.View StatsIf the user chooses to View Stats the program will display the currents users stats and how longits been since their account has been createdExample:Username: JohnWins TiesLosses Age31357h3.ExitIf the user chooses to exit, the program is to exit.Game PlayThis section describes game play. For each round a line that includes the round number is to bedisplayed followed by a menu that let’s the user choose Rock, Paper, or Scissors as their choicefor the round as shown here:Hint:round number = wins + ties + losses + 1Round <round number>[1] Rock[2] Paper[3] ScissorsWhat would you like to do?The user makes their choice and the computer chooses randomly. The result of the round is to bedisplayed using the following format:
Rock, Paper, Scissors GameFinal ProjectFor Wins<User Choice> beats <Computer Choice>! You Win!Example:Scissors beat Paper! You Win!For TiesYou both picked <choice>! It's a tieExample:You both picked Paper! It's a tieFor losses<Computer Choice> beats <User choice>..You lose =(Example:Paper beats Rock..You lose =(After the each round the user is to be presented with the Game Menu:Saving / Loading:When the program ends, we don’t want to lose our users. Each time you run the program, itshould be possible to add new users and load previous users.To accomplish that, we’ll need tosave and load our list of users.You can develop your own strategy of doing that if you’d like. Here are a few of oursuggestions: I suggest using pickle to save and load user information.Whenever the game is runand then exited, update that User object in the list. Then serialize your list and save it to a file.Section 9.3 in the textbook provides information on serializing objects. “Serializing an object isthe process of converting the object to a stream of bytes that can be saved to a file for laterretrieval.” Then each time the program starts, check for that file of users. If it does not exist, startwith a new, empty list. If it does exist, you can read that file and de-serialize it back into a list ofUser objects. Study 9.3 Serializing Objects to learn how serialization works. Also, refer to 10.3Working with Instances for examples on how to serialize objects. Your users should be saved ina file namedrps.dat.When running the program if it cannot find rps.dat print out the followingerror message and then start the name.It will create a newrps.datfile with new users.The error message should be:
Rock, Paper, Scissors GameFinal Project[!]Error: Could not find previous users game data.Example OutputIf rps.dat doesn’t exist===== RESTART: /Users/jtwyp6/Desktop/IT1040 - RPS Manager Soltion/RPS.py =====[!]Error: Could not find previous users game data.Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?If rps.dat does existRock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?1What is your name?JohnnyHello Johnny. Let's play!RPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?2Username: JohnnyWins TiesLosses Age
Rock, Paper, Scissors GameFinal Project0004sRPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?1Round #1[1] Rock[2] Paper[3] ScissorsWhat would you like to do?3Rock beats Scissors..You lose =(RPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?3Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?3Rank NameWin% Wins TiesLosses1Stephanie0.50 1012John0.33 2133Johnny0.00 001Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores
Rock, Paper, Scissors GameFinal Project[4] ExitWhat would you like to do?2What is your name?Jack[!]Error: This User doesn't exist.Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?1What is your name?Johnny[!]Error: This User already exists.Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?2What is your name?JohnnyWelcome back Johnny. Let's play!RPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?2Username: JohnnyWins TiesLosses Age00138s
Rock, Paper, Scissors GameFinal ProjectRPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?1Round #2[1] Rock[2] Paper[3] ScissorsWhat would you like to do?1Rock beats Scissors! You Win!RPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?2Username: JohnnyWins TiesLosses Age10143sRPS Game Menu-------------[1] Play a Round[2] View Stats[3] ExitWhat would you like to do?3Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?3
Rock, Paper, Scissors GameFinal ProjectRank NameWin% Wins TiesLosses1Stephanie0.50 1012Johnny0.50 1013John0.33 213Rock Paper Scissors-------------------[1] Start a New Game[2] Load a Game[3] Display High Scores[4] ExitWhat would you like to do?4Thank you for playing Rock Paper Scissors!TestingMake sure you have thoroughly tested your program!SubmissionPut your User.py, Users.py and RPS.py files in a folder named<pawprint>RPSand zip thefolder. The zip file is to be submitted for this assignment.