CLASS CREATION #5
T/Th, Oct 30-Nov 1
This week we will undertake the
somewhat ambitious project of coding
MasterMind, the game in which a player
attempts to determine a secret word and is
told after each guess how many letters in
their guess are correct, and how many of those
are in the correct place. Our program
will feature a graphical display to make the
game more entertaining.
Once everyone understands the
overall structure of the program we will
employ a "divide and conquer" strategy to
accomplish the entire task in just two class
sessions. Each person will be in charge
of writing and testing one of the functions
below. Once your function is working as
intended, you will email your code to Dr. V,
who will assemble all the functions into our
final program. With any luck we'll soon
have a great game to play!
- instructions()
This function should welcome the player and
carefully describe the rules of the
game. All text will be printed to the
Terminal shell, not to the graphics
window. After waiting a suitable time
interval, the computer should ask the user
to press [ENTER] when they are ready to
play.
- drawborder()
This function will initialize a 600 x 900
pygame window with a black background and
draw a decorative border around the
edge. The border should only be 50
pixels wide to leave room in the middle of
the screen for game play. The word
'MasterMind' should appear centered along
the top of the screen.
- welcome()
This function should create an exciting
graphical display of some sort within the
central 500 x 800 portion of the
screen. Include a message such as
"Game on!" or "Ready to play?" or something
similar. It should then wait three
seconds and erase the display by drawing a
black rectangle over this central region of
the screen.
- prepscreen()
This function will prepare the screen for
the actual game. It should divide the
central 500 x 800 portion of the screen into
different blocks, as described in class,
using white lines. It should print
headers "Guesses" and "Clues" across
the top, and number the guesses down the
left side, all in small font.
- getguess()
This function will ask the player to enter
an ordinary English five-letter word in the
Terminal shell. It should strip off
extra spaces and make sure that the word is
the correct length. (And repeatedly
ask until a suitable word is entered.)
It should then convert the word to all upper
case and return this word.
- printword(turn,word)
This function will print the given word in
large font at the appropriate place within
the screen, next to the corresponding turn
number.
- showclues(turn,right,good)
This function will draw a sequence of five
circles in the appropriate part of the
screen. There should be one gold
circle for each right letter, one green
circle for each good letter that is not
already right, and the rest red
circles. Put a time delay between
drawing each circle, just to build suspense.
- testforright(guess,secret)
This function will check how many letters in
the guess and secret word match
exactly. For instance, the pair of
words house
and south
have exactly two matching letters. The
function should return the number of
matching letters.
- testforgood(guess,secret)
This function will check how many letters
the guess and secret words have in common,
taking into account repeated letters.
For instance, the pair of words apple
and plate
have four letters in common. The
function should return the number of common
letters. Warning:
this task is tricky. Dr. V will
provide a strategy for coding this function.
- winscreen()
This function will draw an exciting and
colorful display within the central 500 x
800 portion of the screen. Some part
of the display should announce that the
player has won the game.
- losescreen()
This function will draw a considerably less
exciting display within the central 500 x
800 portion of the screen. Some part
of the display should announce that the
player has lost the game.
|
|