Implement a golf game program

Assignment Help Basic Computer Science
Reference no: EM132373724

Implementing the Tropical Golf Game v2.0

Task

You are to implement a golf game program as outlined in the following description. Use what you have learned during the entire trimester, as well as the feedback that you received from Assessment 1 and the class sessions on this assignment.

Please keep in mind that as this is a complex program, you will require substantial time to plan the program, break the game play into functions, and then code and test the result.

Program Features

Short description:

• You are required to create a Python 3 program for a game of Tropical Golf. The player will be attempting to get the ball in the hole using the least amount of swings.

• The rules and gameplay for the program are as follows:
o The game asks for the player's name then welcomes the player, asks the numerical value of par, the distance to the hole, and then displays the menu.
o The main menu displays 3 options "Instructions", "Play Game", and "Quit"
o If the player chooses "I" the instructions are displayed
o If the player chooses "P" the game is played:
– The ball starts at the distance to the hole specified by the player
– The player chooses one of three clubs, each of which hits a different average distance
– Every hit travels directly towards the hole in a straight line (this is a simple golf game, we're only playing in 2D)
– Distance of ball travel after a hit are only whole numbers (125, 250, etc)
– Once the ball is in the hole the player is told how many swings it took and whether they are over or under par
• ‘Par' is the estimate of how many swings a game should take
– The player may use as many swings as is necessary to get the ball in the hole
o After every menu choice OTHER than ‘Q' the menu is displayed again.
o Once the player enters "Q" the game thanks the player by name and says goodbye

Detailed instructions:

Ensure that your program has the following features:

1. Ask the player's name and welcome them to the game using their name.

2. Ask the player what is par for this game (number between 3-5 inclusive)

3. Ask the player what the distance to the hole for this game is (whole number between 195 and 250 inclusive)

4. Show the game menu: (I)nstructions (P)lay golf (Q)uit

The user will enter the first letter of each option to choose it.

5. If the user chooses (I) then the following message is to be displayed, given the par and distance amounts obtained above.

This is a simple golf game in which each hole is 230m game away with par 5. You are able to choose from 3 clubs, the Driver, Iron or Putter.

The Driver will hit around 100m, the Iron around 30m and the Putter around 10m. The putter is best used very close to the hole.

After the instructions are displayed the game menu will be presented again.

6. If the player chooses (Q) then the following message is to be displayed:
Farewell and thanks for playing <user name>.

7. After displaying the instructions, or playing a round of golf, the program is to return to the menu and loop until the user chooses to quit

8. If the user chooses (P) then a game of golf will begin as described below

Playing the game:

• The player is first notified of the distance to the hole, which was specified in step 3 above.

• For each swing, the player chooses a club and then the program generates the distance hit for each shot, updating the distance to the hole accordingly. After each swing the distance the ball travelled, and the distance remaining is displayed along with the current score using a message similar to the one below:

Your shot went 103m.
You are 127m from the hole, after 1 shot/s.

• The player has three clubs to choose from for each shot. Each club hits the ball a set average distance, but the actual distance randomly varies between 80% and 120% of the average. For the Driver you will need to generate a random number between 80 and 120 to do this.

• The clubs and their average distances are:
o Driver: 100m (actual distance will be a random number between 80 and 120)
o Iron: 30m (actual distance will be a random number between 24 and 36)
o Putter: 10m (see below for actual distance)

• When the ball is inside 10m and the putter is used, the shot will be between 80% and 120% of the distance to the hole, not the club's average distance. The minimum distance the putter can hit is 1m (no 0m hits). All distances are whole numbers.

• The user will enter the first letter of a club to choose it (i.e. ‘I' or ‘i' for the Iron)

• If an invalid club is chosen, the player is asked to make a valid choice.

• The ball cannot be a negative distance to the hole. Whether it is in front of or behind the hole, it is still a positive distance to the hole. Python has an absolute value function that you can use to help you with this.

• Play proceeds until the ball is in the hole (distance to the hole is zero), and then the program informs the user of their score.

• The players score is the number of shots taken to get the ball in the hole. The final output will display the number of shots taken and how this relates to par. If their score is less than par for this hole, output is "under par", equal to par is called "par", and more than par is "over par". See sample output for exact outputs.
After 10 hits, the ball is in the hole! Disappointing. You are 5 over par.
After 5 hits, the ball is in the hole! And that's par.
After 3 hits, the ball is in the hole! Congratulations, you are 2 under par.

• If the player has done a previous round (i.e. this is the second time the game is played), the game should then display the total score with an appropriate message, and then show the game menu again.

Implementation:

Python file:
You are to divide your solution into functions, following the principles shown in class. These may involve one for each menu option (other than Quit) as well as functions for parts of the program (e.g. calculating the current player score could be implemented as a function).

You may show your assignment to your tutor during practical time to get comments or suggestions. It is important to note that you can only get help from staff in practical time after your prac work is finished.

General Principles:
In this assignment, you will be focusing on implementation using selections, repetition and functions. Lists and string formatting should be used where they are feasible.

Use the techniques and patterns that you have learned and seen demonstrated in class.

• Coding standards:
o Variables:
- Local constants should be set at the top of the function
- Although Python does not use constants you may set variables to values that will remain the same for the life of the program. These should be named in all caps
• You should be able to modify these variables to adjust the various values of items such as PAR, STARTING_DISTANCE, etc. This is an important aspect of this assignment, so consider carefully how to use constants. Remember to use these variables everywhere you can.
• You will need to decide the best position to place these variables.
- You should AVOID the use of global variables.
• In other words, you should pass the values from a function to another as parameters; variables and constants should be local only when needed by a single function.
o Identifier Names
- Variables should be named appropriately using either camelCase or snake_case
- No variables should be a single character such as "x" or "y" unless they are used in a loop as an index. Variable names should be meaningful, and describe their use and/or purpose
- Any list variable should be named with plurals to show multiple data is held (e.g. prices versus price).

- Function names should begin with a verb (they are active), for example getValue() is better than value(). Good verbs include - ‘get', ‘display', ‘calculate', ‘check' etc (not all these are good for this problem...)
o Comments:
- You will need to add at LEAST one comment for each function that you define, including main.
- The comment should either be placed directly above or below the function header
- The comment should describe: (a) the purpose of the function, (b) any inputs and (c) any returned values
- Additional comments should be placed at any position where the functionality of the program may be unclear.
- All code MUST be properly indented
o Error handling:
- Note that menu choice and other character selection should handle upper and lower case letters.
• Look into the upper() or lower() functions in Python
- You also must make sure that any functions that get input from the user do error checking to ensure that the input is within the expected range.
- Use isdigit() and isalpha() functions to validate correct type of user input.
o Output
- Make your output display as close as possible to the given examples, especially formatting and layout.
- Use format() to display tabs and strings at a set width
o Python Functions
• ‘random.randint' to see how to generate a random number in Python
• ‘abs' to see how to use Pythons absolute value function
• ‘upper' or ‘lower' to see case conversion functions
• ‘format' to display output
• ‘isdigit' and ‘isalpha' for validating user input

Attachment:- Implementing the Tropical Golf Game.rar

Reference no: EM132373724

Questions Cloud

Which is quantitative research important to nursing research : What are the criteria for selecting qualitative versus quantitative resources in relation to your literature review? Which is quantitative research so important
Define the target population for your effort : NM208 - Nursing Informatics Telehealth - Perhaps one of the most exciting benefits of nursing informatics is the ability to deliver health information.
Write a short article on Motivating Help Desk Staff : Write a short article (about 500 words) on: Motivating Help Desk Staff, Staff Training for Help Desk Agents and The Future of Help Desk Operations
How venous thrombosis is different from arterial thrombosis : Compare the pathophysiology of chronic venous insufficiency and deep venous thrombosis. Describe how venous thrombosis is different from arterial thrombosis.
Implement a golf game program : CP1401 - Fundamentals of Problem Solving and Programming - Implementing the Tropical Golf Game v2.0 - James Cook University - implement a golf game program
Briefly define the sustainable development goals : Describe the global issues leading to vulnerable populations and disparity at present time. What factors are responsible and what steps can we take.
Determine legislative intent of the bill you have reviewed : NURS6050 - Based on the health-related bill (proposed, not enacted) you selected, complete the Legislation Comparison Grid Template. Be sure to address.
Investment in infrastructure as an economic stimulant : What advice would you give to the government with regard to investment in infrastructure as an economic stimulant?
How you will merge the two sets of information : Plan how you will take further steps to "know yourself" and "know the world of work." Discuss how you will merge these two sets of information to make better.

Reviews

len2373724

9/20/2019 10:55:11 PM

Effective and correct use of branches in the implemented solution. The branches identified are appropriate and correctly used. All branches are efficient and well designed. Effective and correct use of loops in the implemented solution. All loops used are appropriate and correctly used All loops exit when appropriate Definite and indefinite loops used accordingly.

len2373724

9/20/2019 10:55:04 PM

Exemplary (9 – 10) Correct use of Python syntax No syntax errors that prevent the program running as required. Correct use of Python comments All comments are correctly inserted, clear, and appropriate. Effective and correct use of variables and constants in the implemented solution All variables are correctly used. All variable names are clear and meaningful No inappropriate use of global or constant variables. Effective and correct use of functions in the implemented solution Functions are all appropriate and correctly used All names are valid and meaningful No unnecessary inputs or outputs All necessary inputs and outputs are correct. Functions follow SRP.

len2373724

9/20/2019 10:54:53 PM

Upload one Python 3 (.py) file containing your code. Please name the file like: FirstnameLastnameA2.py if your name were Miles Davis, the filename would be MilesDavisA2.py Submit your file by uploading it on LearnJCU under Assessment.

Write a Review

Basic Computer Science Questions & Answers

  Discuss the different types of malware

Discuss the different types of malware that can pose a threat to computer memory and processes.

  Profit-maximizing assumption

Does this result suggest why economists are not overly concerened about wheather the profit-maximizing assumption is exactly correct?

  Create a web page to describe the course

Pretend that your instructor has asked you and two friends to create a Web page to describe the course to potential students and provide current class information (e.g., syllabus, assignments, and readings) to current students.

  Name the four essential characteristics of cloud computing

What is the benefit of a hybrid cloud deployment approach?

  Design an adt for a shoe

Then write a Java interface for a shoe's methods. Include javadoc-style comments in your code.

  Throughout this course you have been asked to research and

throughout this course you have been asked to research and respond to various ethical dilemmas and regulations that

  Characteristics of successful information governance program

Identification and the introduction of the principles, and the characteristics of a successful Information Governance program.

  Which of the following input technologies has been

1. telewire a mobile manufacturer offers free connections to customers who buy its mobile phones. this cost of

  Academy of management review

Considering the concepts of methodological fit presented in the article and your assigned text readings.

  Write a c function that calculates the least common multiple

Integers m and n are parameters to this function. Also write a main program to test this function with several pairs of integers. Use the library functions to convert and output the results.

  Development of secure encryption algorithms

1. Briefly summarize the history of RC4 and what it tells us about the development of secure encryption algorithms.

  Program to strip all occurrences of characters

Write a program to strip all occurrences of these characters: '(', ')' and '-'. Also, strip all the leading and trailing whitespace characters. Display the stripped phone number

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd