patternpythonMinor
Simple word shuffling game
Viewed 0 times
wordgamesimpleshuffling
Problem
I have made a game (I like to code when in my spare time) where words are taken at random from a list and displayed on a label. If they type it correctly, their
```
try:
from tkinter import *
except ImportError:
from Tkinter import *
import time
import random
time_score = 0
high_score = 60.00
name = "A really slow typer"
words = ["Games",
"Development",
"Keyboard",
"Speed",
"Typer",
"Anything",
"Alpha",
"Zealous",
"Accurate",
"Basics",
"Shortcut",
"Purpose",
"Window",
"Counter",
"Fortress",
"Modification",
"Computer",
"Science",
"History",
"Football",
"Basketball",
"Solid",
"Phantom",
"Battlefield",
"Advanced",
"Warfare",
"Download",
"Upload",
"Antidisestablishmentarianism",
"Supercalifragilisticexpialidocious",
"Discombobulation",
"Liberated",
"Assassin",
"Brotherhood",
"Revelation",
"Unity",
"Syndicate",
"Victory"]
wordcount = 0
skips = 0
start_time = time.time()
def restart(event):
global wordcount, skips, time_score
start_time = time.time()
wordcount = 0
skips = 0
time_score = 0
label.config(text="")
time_scoreLabel.config(text="Time: " + str(time_score) + "s")
wordcounter.config(text="Words: " + str(wordcount))
skipcounter.config(text="Skips: " + str(skips))
wronglabel.config(text="")
hilab.pack_forget()
enter.pack_forget()
time_scoreLabel.pack_forget()
wordcounter.pack_forget()
wordcount goes up by 1 and the word is removed from the list. If they get it wrong, the word remains. If they enter nothing in an attempt to skip the long words, they get a skip. After their wordcount has reached 12 and their time is less than 60 seconds, they get the new high score.```
try:
from tkinter import *
except ImportError:
from Tkinter import *
import time
import random
time_score = 0
high_score = 60.00
name = "A really slow typer"
words = ["Games",
"Development",
"Keyboard",
"Speed",
"Typer",
"Anything",
"Alpha",
"Zealous",
"Accurate",
"Basics",
"Shortcut",
"Purpose",
"Window",
"Counter",
"Fortress",
"Modification",
"Computer",
"Science",
"History",
"Football",
"Basketball",
"Solid",
"Phantom",
"Battlefield",
"Advanced",
"Warfare",
"Download",
"Upload",
"Antidisestablishmentarianism",
"Supercalifragilisticexpialidocious",
"Discombobulation",
"Liberated",
"Assassin",
"Brotherhood",
"Revelation",
"Unity",
"Syndicate",
"Victory"]
wordcount = 0
skips = 0
start_time = time.time()
def restart(event):
global wordcount, skips, time_score
start_time = time.time()
wordcount = 0
skips = 0
time_score = 0
label.config(text="")
time_scoreLabel.config(text="Time: " + str(time_score) + "s")
wordcounter.config(text="Words: " + str(wordcount))
skipcounter.config(text="Skips: " + str(skips))
wronglabel.config(text="")
hilab.pack_forget()
enter.pack_forget()
time_scoreLabel.pack_forget()
wordcounter.pack_forget()
Solution
Bug
You imported
Minor imprecision
The information text lacks spaces, some words stick to each other, giving a feeling of lack of professionality.
Lack of focus on the important
The most important part of the program is the entry when the user types its text, yet it is tiny. Parts of the program should have sizes proportional to their importance.
Lack of separation of code and data
You have a wordlist right inside your code. This makes it pretty annoying to change it and a non-programmer might actually be scared to change something inside a code-file. I suggest reading the words from a file, it is very easy:
Constants are uppercase by convention
A constant is a value that never changes, as a convention they are uppercase, for example
Multiline widgets
There is no need to make a new widget for each line, you can use the same widget for many lines.
You imported
tkinter as a wildcard (*) so you should remove tkinter. from your program for proper operation.Minor imprecision
The information text lacks spaces, some words stick to each other, giving a feeling of lack of professionality.
Lack of focus on the important
The most important part of the program is the entry when the user types its text, yet it is tiny. Parts of the program should have sizes proportional to their importance.
Lack of separation of code and data
You have a wordlist right inside your code. This makes it pretty annoying to change it and a non-programmer might actually be scared to change something inside a code-file. I suggest reading the words from a file, it is very easy:
with open(WORDS_FILE) as f:
WORDS = list(f.readlines())Constants are uppercase by convention
A constant is a value that never changes, as a convention they are uppercase, for example
WORDS.Multiline widgets
There is no need to make a new widget for each line, you can use the same widget for many lines.
Code Snippets
with open(WORDS_FILE) as f:
WORDS = list(f.readlines())Context
StackExchange Code Review Q#113778, answer score: 6
Revisions (0)
No revisions yet.