Skip to main content
The tag isn't actually supposed to be appended to the title like that. The system does it for you, in certain cases, but it's not meant as a template.
Source Link
Cody Gray
  • 4.6k
  • 20
  • 30

python - Terminal Typing Game

A few weeks ago, I developed a terminal game that increases your typing speed. The game is all about typing with difficulties, providing difficulty levels from easy to hard. I feel like this terminal game won't become as popular as my others. So, so I need tips on how I could improve this code to make it shorter and, easier to run, and make more entertaining.

Here is the code developed by me, PYWPM.:

python - Terminal Typing Game

A few weeks ago, I developed a terminal game that increases your typing speed. The game is all about typing with difficulties from easy to hard. I feel like this terminal game won't become as popular as my others. So I need tips on how I could improve this code to make it shorter and easier to run and make more entertaining.

Here is the code developed by me, PYWPM.

Terminal Typing Game

A few weeks ago, I developed a terminal game that increases your typing speed. The game is all about typing, providing difficulty levels from easy to hard. I feel like this terminal game won't become as popular as my others, so I need tips on how I could improve this code to make it shorter, easier to run, and more entertaining.

Here is the code developed by me, PYWPM:

Tweeted twitter.com/StackCodeReview/status/1397704149437976580
Became Hot Network Question
Source Link
Theodore
  • 243
  • 1
  • 8

python - Terminal Typing Game

A few weeks ago, I developed a terminal game that increases your typing speed. The game is all about typing with difficulties from easy to hard. I feel like this terminal game won't become as popular as my others. So I need tips on how I could improve this code to make it shorter and easier to run and make more entertaining.

Here is the code developed by me, PYWPM.

import time
import random

logo = '''
  _____    __          _______  __  __ 
 |  __ \   \ \        / /  __ \|  \/  |
 | |__) |   \ \  /\  / /| |__) | \  / |
 |  ___/ | | \ \/  \/ / |  ___/| |\/| |
 | |   | |_| |\  /\  /  | |    | |  | |
 |_|    \__, | \/  \/   |_|    |_|  |_|
         __/ |                         
        |___/                          
'''
print(logo)
print(" ")
difficulty = input("Enter difficulty level (easy/hard): ")
if difficulty == "easy":
  openPlz = open('easywordbank.txt','r')
  readPlz = openPlz.read()
  wordBank = readPlz.split()
elif difficulty == "hard":
  openPlz = open('hardwordbank.txt','r')
  readPlz = openPlz.read()
  wordBank = readPlz.split()

open2 = open('highscore.txt','r+')
open2lst = open2.readlines()

stat = True
strike = 0
score = 0

def gameMain(wordBank):
    #Primary game loop. Returns a lst:
    #lst[0] = added points, lst[1] = added strikes
    lst = [0,0]
    start = time.time()
    wordQuiz = wordBank[random.randint(0,(len(wordBank)-1))]
    wordType = input('Enter the word, '+ wordQuiz + ' : ')
    if wordType == wordQuiz and time.time()-start < 3:
        lst[0] += 1
    elif time.time()-start >= 3:
        print('STRIKE! Too Slow! ')
        lst[1] += 1
    else:
        print('STRIKE! Watch your spelling. Be careful with strikes!')
        lst[1] += 1
    return lst

def highScore(name,score,highScoreLst,zFile):    
    for line in highScoreLst:
        if score >= int(line[-3:-1]): 
            highScoreLst.insert(highScoreLst.index(line),name+'-'+str(score)+'\n')
            highScoreLst.pop()
            zFile.seek(0,0)
            zFile.writelines(highScoreLst)
            break

def rsg():
    print('Ready?')
    time.sleep(1)
    print('Set?')
    time.sleep(1)
    print('Go!')
    time.sleep(1)

name = input('Enter a username for this session: ')
print("Type the word then press enter in under 3 seconds!")
time.sleep(2)
rsg()

#MainState

while stat == True:
    lst = gameMain(wordBank)
    score += lst[0]
    strike += lst[1]
    if strike == 3:
        time.sleep(.5)
        print('Game Over! The game has ended..!\n')
        time.sleep(2)
        print('Your Typing & Accuracy Score: ' + str(score))
        highScore(name,score,open2lst,open2)
        time.sleep(2)
        break
print('\nHighscores for PyWPM:')
time.sleep(2)
for line in open2lst:
    print(line, end='')
    time.sleep(1.5)
time.sleep(5)



openPlz.close()
open2.close()
  1. Yes, this game includes a word bank that randomizes words.
  2. The high scores aren't global.

How could I make this better?