generated from mwc/project_game
I finished!!!!!!!
This commit is contained in:
@@ -3,7 +3,8 @@ from retro.agent import Agent
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
3
|
|
||||||
|
|
||||||
def clear_terminal():
|
def clear_terminal():
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
os.system("cls")
|
os.system("cls")
|
||||||
@@ -17,14 +18,77 @@ class RandomKeyAgent(Agent):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MysteryCodingLadderGame(Game):
|
class MysteryCodingLadderGame(Game):
|
||||||
def __init__(self, agents, state):
|
def __init__(self, agents, state):
|
||||||
super().__init__(agents=agents, state=state)
|
super().__init__(agents=agents, state=state)
|
||||||
self.word = "coding" 3
|
self.word = "coding"
|
||||||
self.index = 0
|
self.index = 0
|
||||||
self.position = 0
|
self.position = 0
|
||||||
self.ladder_height = len(self.word) 0
|
self.ladder_height = len(self.word)
|
||||||
|
|
||||||
self.running = True
|
self.running = True
|
||||||
|
|
||||||
|
def draw_ladder(self):
|
||||||
|
"""Draws the ladder with the orb at the current height."""
|
||||||
|
clear_terminal()
|
||||||
|
print("Hint: What this class is about\n")
|
||||||
|
|
||||||
|
for i in range(self.ladder_height - 1, -1, -1):
|
||||||
|
if i == self.position:
|
||||||
|
print(" | ● |")
|
||||||
|
else:
|
||||||
|
print(" | |")
|
||||||
|
|
||||||
|
print("\nSpell the mystery word one letter at a time.")
|
||||||
|
print("The circle climbs the ladder with each correct letter!\n")
|
||||||
|
|
||||||
|
|
||||||
|
progress = []
|
||||||
|
for i in range(len(self.word)):
|
||||||
|
if i < self.index:
|
||||||
|
progress.append(self.word[i].upper())
|
||||||
|
else:
|
||||||
|
progress.append("_")
|
||||||
|
print("Word progress:", " ".join(progress))
|
||||||
|
print(f"Next letter to guess: {self.word[self.index].upper()}\n")
|
||||||
|
|
||||||
|
def update(self, action):
|
||||||
|
"""Check the player's typed letter."""
|
||||||
|
if not action:
|
||||||
|
return
|
||||||
|
|
||||||
|
guess = action.lower()[0]
|
||||||
|
correct = self.word[self.index]
|
||||||
|
|
||||||
|
if guess == correct:
|
||||||
|
print("Correct letter! The orb climbs!")
|
||||||
|
self.index += 1
|
||||||
|
self.position += 1
|
||||||
|
else:
|
||||||
|
print("Incorrect! The ladder resets!")
|
||||||
|
self.index = 0
|
||||||
|
self.position = 0
|
||||||
|
|
||||||
|
if self.position >= self.ladder_height:
|
||||||
|
self.running = False
|
||||||
|
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print("Game Start!")
|
||||||
|
while self.running:
|
||||||
|
self.draw_ladder()
|
||||||
|
letter = input("Your letter: ")
|
||||||
|
self.update(letter)
|
||||||
|
|
||||||
|
clear_terminal()
|
||||||
|
print(" | ● | TOP OF LADDER!")
|
||||||
|
print("\n🎉 You spelled CODING correctly! Great job Buffalo Bull! 🎉\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
agents = [RandomKeyAgent()]
|
||||||
|
state = {}
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
game = MysteryCodingLadderGame(agents=agents, state=state)
|
||||||
|
game.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user