Created
May 7, 2013 21:20
-
-
Save nuclearsandwich/5536221 to your computer and use it in GitHub Desktop.
CoderDojo Wheel of Fortune Game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###############################FUNCTIONS CREATED BY GROUPS#################################### | |
#INTERMEDIATE GROUP 1 | |
#TAKES A STRING INPUT AND RETURNS A STRING THAT HAS ALL THE | |
#LETTERS REPLACED WITH DASHES (THE SPACES REMAIN AS SPACES) | |
def replaceWithDashes(string): | |
dashes = "" | |
#fill in here | |
return dashes | |
#INTERMEDIATE GROUP 2 | |
#FUNCTION THAT TAKES THREE INPUTS: THE CURRENT PHRASE (MOSTLY DASHES), THE SPOT IN THE | |
#PHRASE TO BE REPLACED, AND THE ORIGINAL PHRASE. THIS FUNCTION REPLACES THE DASH AT THE GIVEN | |
#SPOT WITH THE LETTER FROM THE ORIGINAL PHRASE. IT RETURNS THE NEW STRING | |
def revealSpotInPhrase(phrase,spot,original_phrase): | |
#fill in here | |
return new_phrase | |
#BEGINNER GROUP 1 | |
#FUNCTION THAT TAKES ONE INPUT OF THE CURRENT PLAYERS TURN | |
#IF IT IS CURRENTLY THE 1ST PLAYERS TURN, THIS FUNCTION RETURNS 2 | |
#IF IT IS CURRENTLY THE 2ND PLAYERS TURN, THIS FUNCTION RETURNS 1 | |
def nextPlayersTurn(current_turn): | |
#fill in here | |
return nextTurn | |
#BEGINNER GROUP 2 | |
#FUNCTION THAT TAKES A STRING AND A LETTER AS AN INPUT | |
#IT RETURNS THE STRING "true" IF THE LETTER APPEARS IN THE STRING AND THE | |
#STRING "false" IF IT DOES NOT. ALSO PRINTS A MESSAGE TO LET THE PLAYER KNOW | |
def isLetterInPhrase(string,letter): | |
#fill in here | |
return "false" | |
#BEGINNER GROUP 3 | |
#FUNCTION THAT TAKES A LETTER AS AN INPUT AND RETURNS THE | |
#STRING "true" IF IT IS A VOWEL AND "false" IF IT IS NOT | |
def isGuessAVowel(letter): | |
#fill in here | |
return "false" | |
##################################FUNCTIONS PROVIDED########################################### | |
#PROVIDED, BUT CAN MODIFY | |
#FUNCTION THAT DOESN'T HAVE ANY INPUTS AND USES THE GAME'S VARIABLES TO | |
#PRINT THE CURRENT PHRASE, THE PLAYERS TURN, AND THEIR SCORE | |
def printGameState(): | |
print("******************************************************") | |
if playerTurn == 1: | |
print(player1Name + "'s turn, $" + str(player1Score)) | |
else: | |
print(player2Name + "'s turn, $" + str(player2Score)) | |
print("Board: " + current_phrase) | |
#PROVIDED, BUT CAN MODIFY | |
#FUNCTION THAT DOESN'T HAVE ANY INPUTS AND USES THE GAME'S VARIABLES TO | |
#PRINT THE FINAL PHRASE AND THE WINNER | |
def gameOverMessage(): | |
#PRINT OUT FINAL PHRASE, WINNER | |
print("******************************************************") | |
print("Game Over!") | |
print("Board: " + original_phrase) | |
print(player1Name + "'s Score: " + str(player1Score) + ", " + player2Name + "'s Score: " + str(player2Score)) | |
if player1Score > player2Score: | |
print(player1Name + " wins!") | |
else: | |
print(player1Name + " wins!") | |
#PROVIDED, BUT CAN MODIFY | |
#RETURNS A RANDOM NUMBER BETWEEN 1 AND 10 | |
#THE GAME LOGIC WILL USE THIS FUNCTION TO MAKE 1 - LOSE TURN, | |
#2 - BANKRUPT, #3 - $300, 4 - $400, ETC. | |
import random | |
def spinWheel(): | |
spin = random.randint(1,10) | |
return spin | |
#PROVIDED | |
#FUNCTION THAT READS IN THE PLAYERS GUESS FOR A LETTER AND RETURNS | |
#THE UPPERCASE OF IT | |
#NOTE: THIS CAN BE ENHANCED TO 1) VERIFY EXACTLY ONE LETTER WAS TYPED IN | |
#2) VERIFY THE LETTER HASN'T BEEN GUESSED BEFORE | |
def playerGuess(): | |
guess = raw_input("Your guess: ") | |
guess = guess.upper() | |
return guess | |
#PROVIDED | |
#FUNCTION THAT TAKES THE CURRENT PHRASE, ORIGINAL PHRASE, AND GUESS AS INPUTS | |
#IT CALLS THE revealSpotInPhrase FUNTION TO REPLACE ALL THE DASHES FOR THE GUESSED | |
#LETTER. IT RETURNS THE NEW PHRASE WITH THE DASHES REPLACED | |
def revealAllOfGuess(current_phrase, original_phrase, guess): | |
count = original_phrase.count(guess) | |
startSpot = 0 | |
new_phrase = current_phrase | |
for i in range(0, count): | |
replaceSpot = original_phrase.find(guess, startSpot) | |
new_phrase = revealSpotInPhrase(new_phrase,replaceSpot, original_phrase) | |
startSpot = replaceSpot + 1 | |
return new_phrase | |
#PROVIDED | |
#FUNCTION THAT TAKES THE CURRENT PLAYERS NUMBER AS AN INPUT AND | |
#UPDATES THAT PLAYERS SCORE VARIABLE TO ZERO | |
#Note: "global" is needed to modify the variable in a function | |
def makePlayerBankrupt(playerNumber): | |
if playerNumber == 1: | |
global player1Score | |
player1Score = 0 | |
else: | |
global player2Score | |
player2Score = 0 | |
#PROVIDED | |
#FUNCTION THAT TAKES THE CURRENT PLAYERS NUMBER AND AMOUNT TO INCREASE AS | |
#INPUTS. IT ADDS THE AMOUNT TO THE PLAYERS SCORE | |
#Note: "global" is needed to modify the variable in a function | |
def addToPlayersScore(playerNumber,amount): | |
if playerNumber == 1: | |
global player1Score | |
player1Score = player1Score + amount | |
else: | |
global player2Score | |
player2Score = player2Score + amount | |
##########################PLAY THE GAME USING THE FUNCTIONS ABOVE############################### | |
original_phrase = "THE SAN FRANCISCO GIANTS" | |
current_phrase = replaceWithDashes(original_phrase) | |
#print the welcome message and ask for player names | |
print("Welcome to Wheel of Fortune!") | |
player1Name = raw_input("Player 1 name: "); | |
player1Score = 0 | |
player2Name = raw_input("Player 2 name: "); | |
player2Score = 0 | |
playerTurn = 1 | |
#REPLACE THIS PSUEDO-CODE WITH PYTHON TO PLAY THE GAME | |
#while the game is not over | |
#print the current game state | |
#spin the wheel | |
#if spin is 1, lose turn | |
#print message | |
#set playerTurn to next players turn | |
#else if spin is 2, go bankrupt | |
#print message | |
#set players money to 0 | |
#set playerTurn to next players turn | |
#else spin was a $ | |
#print message that your spin money was 100 times spin value | |
#take user input for guess | |
#if the letter is in the phrase | |
#reveal the letters in the phrase | |
#if the letter is a consonant (vowels don't make money) | |
#change the player's score (add the letter count times spin money) | |
#else set playerTurn to next players turn | |
#print the game over message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment