Skip to content

Commit

Permalink
Improved hangman
Browse files Browse the repository at this point in the history
  • Loading branch information
1Prototype1 committed Sep 14, 2020
1 parent a162992 commit 8b33302
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cogs/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def _wumpus(self, ctx):
"""Play Wumpus game"""
await wumpus.play(self.bot, ctx)

@commands.command(name='hangman')
@commands.command(name='hangman', aliases=['hang'])
async def hangman(self, ctx):
"""Play Hangman"""
await hangman.play(self.bot, ctx)
Expand Down
35 changes: 28 additions & 7 deletions games/hangman.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import random
import asyncio

words = ['rainbow', 'computer', 'science', 'programming',
'python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board', 'geek']

words = ['conversation', 'bowtie', 'skateboard', 'penguin', 'hospital', 'player', 'kangaroo',
'garbage', 'whisper', 'achievement', 'flamingo', 'calculator', 'offense', 'spring',
'performance', 'sunburn', 'reverse', 'round', 'horse', 'nightmare', 'popcorn',
'hockey', 'exercise', 'programming', 'platypus', 'blading', 'music', 'opponent',
'electricity', 'telephone', 'scissors', 'pressure', 'monkey', 'coconut', 'backbone',
'rainbow', 'frequency', 'factory', 'cholesterol', 'lighthouse', 'president', 'palace',
'excellent', 'telescope', 'python', 'government', 'pineapple', 'volcano', 'alcohol',
'mailman', 'nature', 'dashboard', 'science', 'computer', 'circus', 'earthquake', 'bathroom',
'toast', 'football', 'cowboy', 'mattress', 'translate', 'entertainment', 'glasses',
'download', 'water', 'violence', 'whistle', 'alligator', 'independence', 'pizza',
'permission', 'board', 'pirate', 'battery', 'outside', 'condition', 'shallow', 'baseball',
'lightsaber', 'dentist', 'pinwheel', 'snowflake', 'stomach', 'reference', 'password', 'strength',
'mushroom', 'student', 'mathematics', 'instruction', 'newspaper', 'gingerbread',
'emergency', 'lawnmower', 'industry', 'evidence', 'dominoes', 'lightbulb', 'stingray',
'background', 'atmosphere', 'treasure', 'mosquito', 'popsicle', 'aircraft', 'photograph',
'imagination', 'landscape', 'digital', 'pepper', 'roller', 'bicycle', 'toothbrush', 'newsletter']

images = ['```\n +---+\n O | \n /|\\ | \n / \\ | \n ===```',
'```\n +---+ \n O | \n /|\\ | \n / | \n ===```',
'```\n +---+ \n O | \n /|\\ | \n | \n ===```',
'```\n +---+ \n O | \n /| | \n | \n ===```',
'```\n +---+ \n O | \n | | \n | \n ===```',
'```\n +---+ \n O | \n | \n | \n ===```',
'```\n +---+ \n | \n | \n | \n ===```']
async def play(bot, ctx):
def check(m):
return m.author == ctx.author
guesses = ''
turns = 8
turns = 6
word = random.choice(words)
await ctx.send("Guess the characters:")
guess_msg = await ctx.send(f"Guesses left: `{turns}`")
guess_msg = await ctx.send(images[turns])
word_msg = await ctx.send(f"`{' '.join('_'*len(word))}`")
while turns > 0:
out = ''
Expand Down Expand Up @@ -47,6 +67,7 @@ def check(m):
if guess not in word:
turns -= 1
await ctx.send("Wrong :x:", delete_after=1.0)
await guess_msg.edit(content=f"Guesses left: `{turns}`")
await guess_msg.edit(content=images[turns])
if turns == 0:
await word_msg.edit(content=f'**{word}**')
return await ctx.send("You Loose :x:")

0 comments on commit 8b33302

Please sign in to comment.