0

I was just wondering if within pygame it was possible to make an anagram game: What I was thinking was making an array with a list of anagrams in it and then when the scene is launched a text line paired with import random would pick a random anagram.

My first question would be with my idea stated above could I set something up so the same anagram won't display twice?

The second question would be how could/ can I integrate an input text box within the game itself and not by using the interpreter?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Pthyon
  • 152
  • 10
  • Yes, it's possible. If you don't want the same anagram to display twice in the same session, you can just maintain a "seen" list (or even better, use a set of anagrams and just remove an anagram from the set when you use it). If you don't want the same anagram to ever occur twice, you might have a .anagram_game_seen.txt somewhere with the words that have occurred in it, and you add a word when it comes up. For your second question (which is quite broad), you could for instance do [this](https://stackoverflow.com/questions/46390231/how-to-create-a-text-input-box-with-pygame). – davidlowryduda Apr 03 '19 at 12:59
  • Pygame is all about drawing on the screen. Drawing in pygame means coloring pixels. What you described is text, text input field and some logic. Sounds very simple in terms of graphics. I recommend to start with tkinter or any other gui framework. https://stackabuse.com/python-gui-development-with-tkinter/ –  Apr 03 '19 at 13:18
  • There's a few text-input boxes/controls available from various people. Once of these could be used to input the text in PyGame. Of course, you could make your own too. They're not too complicated. – Kingsley Apr 03 '19 at 22:14

1 Answers1

0

Yes, this is possible.

To answer the first question, "could I set something up so the same anagram won't display twice?":

import random

anagrams = ["here", "is", "an", "example"]
remaining_anagrams = anagrams.copy()

def choose_anagram():
    global remaining_anagrams
    current_anagram = random.choice(remaining_anagrams)
    remaining_anagrams.remove(current_anagram)
    return current_anagram

def reset_anagrams():
    global remaining_anagrams, anagrams
    current_anagrams = anagrams.copy()

If you prefer not to use global you can pass the global variables in as arguments instead.

As far as to create a text input on screen with Pygame I recommend following this guide. Good luck!