Introduction to Perl - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Introduction to Perl

Description:

2. Input exercise ... End the program if they don't like it, at least until the next exercise. ... a simple driver (main program) that calls the functions in ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 5
Provided by: test243
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Perl


1
Introduction to Perl
  • Unit 10 - Hangman

2
Project Hangman
  • The project you will be completing is the game of
    Hangman.
  • You will give the user a set number of guesses to
    determine what the preset word is.
  • Commenting and neat code design are all important
    throughout the program

3
Part 1 Welcome to Hangman
  • The first part of the Hangman program will be to
    display a welcome screen to the user, using the
    print function you previously learned.
  • Write a program that prints your
  • welcome screen for Hangman.

Hangman123
4
All You Need To Know
  • 1. Print exercise
  • Print your title screen for hangman. Use \t and
    \n to change the location that your welcome
    message appears on the screen. 2. Input
    exercise
  • Prompt the user for a word to be used for
    hangman, and then print that out for them to see.
    (Like echo.) 3. Get Guess exercise
  • Get a guess from the user. Print out the first
    letter of the guess. 4. Modified Input with
    Conditional
  • Alter your input exercise to ask the user if they
    are satisfied with the word that they entered.
    End the program if they don't like it, at least
    until the next exercise. 5. Modified Input with
    Looping
  • Alter exercise four to repeatedly ask them for a
    word until they respond that they are satisfied.
    6. Simple Subroutine exercise
  • Write a function that extends the welcome screen
    to also display the state of the game. The
    recommended fields to display would include the
    numbers of guesses left, the correctly guessed
    letters, the incorrectly guessed letters, and the
    masked word. Don't worry about calculating these
    values. Have your function take these values when
    it is invoked, and display them. Run several
    trials with different values to make sure that
    your function is presenting the different values
    that are passed to it as you would like it to.
    (Hint This is essentially a print exercise using
    subroutines.) 7. A Little More with Subroutines
  • Transfer the input exercise and the get guess
    exercise into functions in the same file as your
    previous function. The order that the functions
    appear in the file doesn't really matter. Make a
    simple driver (main program) that calls the
    functions in order to display the welcome screen
    or ask the user for the word that they want, show
    the state of the game, and take a guess from the
    user. Don't worry about displaying the state of
    the game a second time, or displaying the word
    correctly at this time. 8. Regular Expression
    Modification for Guessing
  • Alter the guess subroutine that had been
    previously modified. Check if the user entered a
    letter for their guess, and if they did not, then
    ask them again to enter a letter. Use regular
    expressions. To check your subroutine, run the
    program. 9. Check the Guess
  • Write a new subroutine that takes the secret word
    and the guessed letter, and then two strings,
    which will represent the correct and incorrect
    guesses. Have the function append the guess to
    the appropriate string (correct or incorrect),
    and return the two of them in a list. (Hint
    Concatenate strings with a period.) Assuming the
    guess in incorect incorrect incorrect.guess
    10. Display the Word
  • Have this subroutine take in the secret word and
    the correct guesses. You want to create a new
    word that will be displayed, showing the
    correctly guessed letters in their appropriate
    spots, and underscores "hiding" the other
    letters.To construct a new wordFor each letter
    in the word that has been guessed correctly, add
    that onto another the new word. For each letter
    that has not been guessed, add an underscore "_".
    After the loop, return the new word. 11. Check
    the Word
  • Write a function that checks to see if all of the
    letters in the word have been guessed and return
    1 (true) if they have or a 0 (false) if there are
    letters that have not been guessed yet. David P
    WaliaLast modified Tue Jul 29 141011 EDT 2003
Write a Comment
User Comments (0)
About PowerShow.com