Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

how do i write this in shell script, ubuntu linux For this assignment, we will create a Blackjack game in which the user will play

how do i write this in shell script, ubuntu linux

For this assignment, we will create a Blackjack game in which the user will play against the computer. We will use the following game rules:

Aces may be counted as 1 or 11 points. 2 to 9 according to pop value and tens and face cards count as ten points.

The value of a hand is the sum of the point values of the individual cards. Except, a "blackjack" is the highest hand, consisting of an ace and any 10-point card, and it outranks all other 21-point hands.

Game play:

The game will use a file based database to store the player's information which consists of their name and amount of money the user has to play.

One the shell script is started, the system asks the user for a user name. The system then checks to see if the user has played before by looking for a file named userName.txt

If the file exists, the system will read the file contents which only has the user name and balance into two variables.

If the file does not exist, the system will create a new file using the user name as the file name with a txt extension and initialize the user's balance to 100 dollars. After the file is created the user name and balance are loaded into two variables.

After the user information is loaded, the system will start the game as follows.

System will ask for bet. This information will also be saved into a variable.

Once the user places the bet, the system will give the user his first card. The value if the card must be calculated using a number random generator.

After the card is given to the user, the system will ask the user if he or she will stay or to continue with another card. This will be accomplished by printing a message that reads:Hit or Stay [H/S] :

If the user pressed H the system will hand another card and ask the same question again.

If the user hits S, the system will stop. And start it's turn by getting a card. At this point you will need to program how aggressive the computer will play.

Conservative: The computer stays once it's cards reach 15

Moderate: The computer stays once it's cards reach 18

Aggressive: The computer stays once it's cards reach 20

Once the computer is done getting it's cards it must calculate it's hand and compare it with the user's hand. If the computer has a better hand the user looses and the bet is deducted from the user's balance. Otherwise, the bet is added to the user's balance and the appropriate message is displayed (Depending on the case, You loose or You win!)

Once this game is done, the computer will ask the user if he or she wants another game.

The system will print a menu with two options, play again or Quit [P/Q] If the user hits P, the game will start again and if the user hits Q the game will be over and the user's balance will be saved in the users file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Write an elaborate note on marketing environment.

Answered: 1 week ago