From 8b33302182e15c1980d329d031ed67d7c96cedea Mon Sep 17 00:00:00 2001 From: 1Prototype1 Date: Mon, 14 Sep 2020 15:20:23 +0530 Subject: [PATCH] Improved hangman --- cogs/games.py | 2 +- games/hangman.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cogs/games.py b/cogs/games.py index e644c5e..c86cf3e 100644 --- a/cogs/games.py +++ b/cogs/games.py @@ -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) diff --git a/games/hangman.py b/games/hangman.py index f20a19b..10c51eb 100644 --- a/games/hangman.py +++ b/games/hangman.py @@ -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 = '' @@ -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:") \ No newline at end of file