Edit: I have updated this for Renpy 8.0 with the lines I edited marked by #former comments for education purposes. I understand the need to add "encode" to open file statements. Had to change align to anchor because align sets both pos and anchor, so using both align and pos is not correct, one will overwrite the other.
The resulting code below works in both Renpy 8.0 and Renpy 7.5
Code: Select all
# The script of the game goes in this file.
# Declare characters used by this game. The color argument colorizes the
# name of the character.
define guesscount = 0
define guess = ""
define answer = ""
define guessmatrix = [" "," "," "," "," "," "]
define Werd = ""
define Letr = ""
define Keyboard = ["QWERTYUIOP","ASDFGHJKL","ZXCVBNM"]
define greenlist = []
define yellowlist = []
define displaystring = ""
define displaykeyboard = ""
init python:
def get_word():
# former Words = renpy.file('wordlist.txt')
Words = renpy.open_file('wordlist.txt', encoding='utf-8')
wordlist = Words.read().splitlines()
return renpy.random.choice(wordlist).upper()
def check_word(word):
# former guess_file = renpy.file('allowed.txt')
guess_file = renpy.open_file('allowed.txt', encoding='utf-8')
guesslist = guess_file.read().splitlines()
# former Words = renpy.file('wordlist.txt')
Words = renpy.open_file('wordlist.txt', encoding='utf-8')
wordlist = Words.read().splitlines()
if word.lower() in guesslist or word.lower() in wordlist:
return True
else:
return False
def color_word(word):
Temp = ""
Colz = 0
while Colz < len(word):
Letr = word[Colz].upper()
if Letr in answer:
if answer.find(Letr) == Colz or answer.rfind(Letr) == Colz: #for double letters
Temp = Temp + "{color=#0c0}"+Letr+" {/color}"
greenlist.append(Letr)
else:
Temp = Temp + "{color=#aa0}"+Letr+" {/color}"
yellowlist.append(Letr)
else:
Temp = Temp + "{color=#888}"+Letr+" {/color}"
Colz += 1
return Temp
def color_keyboard(word):
Temp = ""
Guesses = guessmatrix[0]+guessmatrix[1]+guessmatrix[2]+guessmatrix[3]+guessmatrix[4]+guessmatrix[5]
Colz = 0
while Colz < len(word):
Letr = word[Colz].upper()
if Letr in Guesses:
if Letr in greenlist:
Temp = Temp + "{color=#3F3}"+Letr+"{/color}"
elif Letr in yellowlist:
Temp = Temp + "{color=#FF0}"+Letr+"{/color}"
else:
Temp = Temp + "{color=#888}"+Letr+"{/color}"
else:
Temp = Temp + "{color=#fff}"+Letr+"{/color}"
Colz += 1
return Temp
screen GameMatrix():
# former text "[displaystring]" size 80 outlines [(1, "#000")] pos (960,300) align (0.5,0.5)
text "[displaystring]" size 80 outlines [(1, "#000")] pos (960,300) anchor (0.5,0.5)
# former text "[displaykeyboard]" size 30 outlines [(1, "#000")] pos (960,700) align (0.5,0.5)
text "[displaykeyboard]" size 30 outlines [(1, "#000")] pos (960,700) anchor (0.5,0.5)
# The game starts here.
label start:
$ guesscount = 0
$ guess = ""
$ answer = ""
$ guessmatrix = [" "," "," "," "," "," "]
$ Werd = ""
$ Letr = ""
$ Keyboard = ["QWERTYUIOP","ASDFGHJKL","ZXCVBNM"]
$ greenlist = []
$ yellowlist = []
$ displaystring = ""
$ displaykeyboard = ""
scene black
$ answer = get_word() #generate random 5 digit word
$ guesscount = 0
label GuessLoop:
$ guess = renpy.input("Guess?", allow="abcdefghijklmnopqrstuvwxyz", length=5)
$ guess = guess.upper()
if len(guess) < 5:
"Not long enough, try again"
jump GuessLoop
if check_word(guess): #checks if it is a valid word
$ guessmatrix[guesscount] = guess
# Text based display guesses
$ Werd = color_word(guessmatrix[0])
$ displaystring = Werd+"\n"
$ Werd = color_word(guessmatrix[1])
$ displaystring = displaystring+Werd+"\n"
$ Werd = color_word(guessmatrix[2])
$ displaystring = displaystring+Werd+"\n"
$ Werd = color_word(guessmatrix[3])
$ displaystring = displaystring+Werd+"\n"
$ Werd = color_word(guessmatrix[4])
$ displaystring = displaystring+Werd+"\n"
$ Werd = color_word(guessmatrix[5])
$ displaystring = displaystring+Werd
# Test based display used letters
$ Werd = color_keyboard(Keyboard[0])
$ displaykeyboard = Werd+"\n"
$ Werd = color_keyboard(Keyboard[1])
$ displaykeyboard = displaykeyboard+Werd+"\n"
$ Werd = color_keyboard(Keyboard[2])
$ displaykeyboard = displaykeyboard+Werd
show screen GameMatrix()
if guess == answer:
"You Win!"
else:
$ guesscount += 1
if guesscount >= 6:
"You Lose, the answer was [answer]"
else:
jump GuessLoop
else:
"That word is not allowed"
jump GuessLoop
# This ends the game.
return