Preview

Hangman Script

Powerful Essays
Open Document
Open Document
487 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Hangman Script
#!/bin/bash
#hangman game
#author ****************
#purpose: for science

play_again()
{
echo "Would you like to play again?" read play_again if [[ "$play_again" =~ ^[yY] ]] ; then echo "Enjoy another game." game else echo "Thanks for playing. Have a good day." exit fi } echo echo " Welcome to Dan's hangman game!" echo " all letters are lower cased " sleep 1 echo echo " Also all words are related to OS2" echo sleep 2 game() { blank=".................." # must be longer than longest word
#List of secret words secret_word() { case $(( $$ % 8 )) in 0 ) echo "linux" ;; 1 ) echo "bash" ;; 2 ) echo "open" ;; 3 ) echo "peguin" ;; 4 ) echo "awesome" ;; 5 ) echo "ubuntu" ;; 6 ) echo "chmod" ;; 7 ) echo "file" ;; esac
}

actual_word()
{
# This function replaces all '.' in template with guess # then updates remaining to be the number of empty slots left

letter=1 while [ $letter -le $letters ] ; do if [ "$(echo $word | cut -c$letter)" = "$guess" ] ; then #cut -c is so that it will only show that letter in the word before="$(( $letter - 1 ))" after="$(( $letter + 1 ))" if [ $before -gt 0 ] ; then tbefore="$(echo $template | cut -c1-$before)" else tbefore= fi if [ $after -gt $letters ] ; then template="$tbefore$guess" else template="$tbefore$guess$(echo $template | cut -c$after-$letters)" fi fi letter=$(( $letter + 1 )) done

remaining=$(echo $template|sed 's/[^\.]//g'|wc -c|sed 's/[[:space:]]//g') #sed s is to replace portion that matches the word where the "." are g is to append the templete of what the word is "g" appends the the .... remaining=$(( $remaining - 1 )) # fix to ignore '\n'
}
word=$(secret_word) letters=$(echo $word | wc -c | sed 's/[[:space:]]//g') letters=$(( $letters - 1 )) # fix character count to ignore \n template="$(echo $blank | cut -c1-$letters)"

You May Also Find These Documents Helpful

  • Good Essays

    It210 Week 4 Psuedocode

    • 584 Words
    • 3 Pages

    = Yes || yes|| No || no Write: “That is not a correct entry!” Write: “Please enter Yes or No.” Input QuitNow…

    • 584 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    CEIS100 W5 ILab Report

    • 320 Words
    • 2 Pages

    Code—copy and paste (or type) your code below. You can also post a screenshot of the program working if you would like.…

    • 320 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    10.Write a program to prompt the user to enter a line of text. On the next line display the capital letter that come first alphabetically and the one that comes last. If no capital letters…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Nt1310 Unit 3 Assignment

    • 256 Words
    • 2 Pages

    Write a program to input a string and then display it in Upper Case and also print the frequency of any character from the string.…

    • 256 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    This student’s assignment prompts the user to enter a word. I see the prompt output on the screen at the beginning of the program.…

    • 204 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    The movie entailed Gloucesterman in a celebration of people of this historic Massachusetts town over 400 period a rousing story told in song and dance and historic action at sea. Paired with not for ourselves alone, a record of victory in four U. S. Military crises, here is a great tribute to American courage and resourcefulness. This movie illustrates the importance of the military and American war, the gratitude we owe to these soldier. This rich and passionate tribute to these fighting forces for four hundred years. The tribute of great action at sea, the abundance of great warrior, the intensity of battled, the entertainment remind us of the time of war. The courage of men and women on the battle field fighting for for us, the dignity,…

    • 133 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    It 210 Week 7

    • 286 Words
    • 2 Pages

    2. Display the contents of the file GRADES created in Problem 1. Each student’s record should appear on a separate line and include the total score (the sum of the three tests) for that student. For example, a line of output might be as follows:…

    • 286 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    2. Write a line of code that will cause the word Hello to be printed.…

    • 83928 Words
    • 594 Pages
    Powerful Essays
  • Satisfactory Essays

    Notes for Final Paper

    • 2734 Words
    • 10 Pages

    put only the letter choice of your answer. Also, do not put any spaces before or after the letter…

    • 2734 Words
    • 10 Pages
    Satisfactory Essays
  • Good Essays

    COS wa 10

    • 297 Words
    • 2 Pages

    Create a set/list of enumerated constants called week that contains the days of the week. Have a variable called today that is of type week. Assign a value to today. If the day is Monday through Friday, print "Go to work!" If the day is Saturday or Sunday, print "You can rest today!"…

    • 297 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    This Is a Paper

    • 469 Words
    • 2 Pages

    Consider the following selection statement where X is an integer test score between 0 and 100.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Beware: World War I

    • 791 Words
    • 4 Pages

    On the line provided, write the letter of the best answer to each of the following items.…

    • 791 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Lesson 2

    • 959 Words
    • 4 Pages

    Select the correct answer for each of the following questions. Choose all answers that are correct.…

    • 959 Words
    • 4 Pages
    Good Essays
  • Good Essays

    accounting

    • 1420 Words
    • 5 Pages

    Student Name and ID (Print Legibly) ________________________________________________________________ True or False/Multiple Guess/Fill in the blank Identify the choice that best completes the statement or answers the question. Carefully and completely fill out this test with the answer that best fits the question. For each answer, clearly circle your choice from the options provided (a, b, c, d, etc.). Dont make me guess, I wont award credit if it isnt obvious.…

    • 1420 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    What is an immigration ban? An immigration ban is an executive order that is being enforced by the US president, Donald Trump. This ban has been around for many years but has been very lenient and has allowed many illegal Muslims, Mexicans, and other nationalities into the country that have killed US citizens or have destroyed cities or jobs of the hard working Americans. “You now have a president who really takes seriously the tremendous threat of international terrorism and is prepared to take steps that are very tough-minded and that are going to inconvenience some people,” former Speaker Newt Gingrich said. I think that an immigration ban is one of the best things that Donald Trump could do for this country in order to make America great…

    • 129 Words
    • 1 Page
    Satisfactory Essays