1# PYTHON TERMINAL GAMES 7/01/2025
Before I start documenting my proper game development I thought it would be nice to show some python games I made about seven months ago now. These two games I made while bord on the train or in class. This game creates grids and you simply have to find the cordinate that X is located.
# find the grid marked with X and lauch the missile in that sector.
import random # used for all the random factors of the game
answer = 0 # the answer given by the user
solution = 0 # the correct answer
verticalList = ["a", "b", "c", "d",] # used to label co-ordinates
iconList = ["?", "#", "!", "+", "=", "-", "*", "^", "&", "@", "_", "_", "_", "_", "_", "_"]
answerList = ["11", "21", "31", "41", "51", "12", "22", "32", "42", "52", "13", "23", "33", "43", "53", "14", "24", "34", "44", "54", "15", "25", "35", "45", "55"] # list of co-ordinate answers
gridList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] # number of co-ordinates
gameList = ["_"] # used for empty co-ordinates
lmScore = 0 # stands for Launch Missile Score
number = 0
for all in range(3):
C = 1# C for co-ordinate
X = random.choice(gridList) # random number between 1 and 25
print(f" 1 2 3 4 5 ") # displays co-ordinate positions
for number in range(25): # runs the co-ordinate code 25 times
number += 1 # increases the number by one.
if number % 5 == 0: # if number is a mutiple of 5
print(f"{str(gameList)} {C}") # print list of 5 co-ordinates and the co-ordinate number.
C += 1 # co-ordinate number increases by one.
gameList = [] # resets gameList to a blank list
if number == X:
number = "X" # used to mark target co-ordinate
else:
number = random.choice(iconList) # used to mark black co-ordinates
gameList.append(number) # adds either X or _ to the list
print("Launch the missle in the grid marked X.")
print("Example if x=2 and y=2 the answer is 22")
solution = answerList[X] # solution = random number corresponding to the co-ordinate list
answer = input(": ")
if answer != solution:# if answer is wrong
print("Wrong co-ordinates")
print("-15 points")
lmScore -= 15
else:
print("Correct!")# if answer is correct
print("+15 points")
lmScore += 15
print(f"Final Score: {lmScore}") # print final score
This next game is best played using pyCharm as it uses colours
# simple game where you must enter 3 commands in quick succession
# NEED TO ADD TIME
import random
import time
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
qcScore = 0
str = ""
answer = ""
solution = ""
commandList = ["ARM THE CANNONS", "POWER ON THE SHIELD", "ALERT THE SOLDIERS", "INFORM HIGH COMMAND", "TURN UP THE MUSIC", "LAUNCH THE NUKES", "EQUIP THE SIGNAL JAMMER", "SAY YOUR PRAYERS", "PRESS THE RED BUTTON"]
characterList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s", "d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m", ",", ".",]
for all in range(10):
print(f"{bcolors.WARNING}ALIENS ARE ATTACKING! PREPARE THE BASE!!!{bcolors.ENDC}")
time.sleep(0.2)
print("\nENTERING DEFENCE MODE:", end=' ')
for i in range(3):
time.sleep(0.5)
print(end='.')
print("\n")
for all in commandList:
commandRNG = random.randint(0,1)
characterRNG = []
for char in range(10): # this loop runs 10 times
randomCharacter = random.choice(characterList) # this creates a random character from the characterList
characterRNG.append(randomCharacter) # this adds the character to a list
solution = str.join(characterRNG) # this joins all the characters in the list together.
if commandRNG == 0:
time.sleep(0.5)
print(f"{all} =", end=' ')
time.sleep(1)
print(f"", end='.')
time.sleep(0.2)
print(f"", end='.')
time.sleep(0.2)
print(f"", end='.')
time.sleep(0.2)
print(f"{bcolors.FAIL}FAILED{bcolors.ENDC}")
time.sleep(1)
while answer != solution:
print(f"TO REBOOT {all} ENTER CODE: {bcolors.OKCYAN}{solution}{bcolors.ENDC}")
answer = input(": ")
if answer == solution:
print(f"{all} = {bcolors.OKGREEN}RUNNING{bcolors.ENDC}")
print(f"+15 POINTS\n")
qcScore += 15
if answer != solution:
print(f"{all} CODE ENTERED INCORRECTLY")
print(f"-15 POINTS")
qcScore -= 15
else:
time.sleep(0.5)
print(f"{all} =", end=' ')
time.sleep(0.2)
print(f"", end='.')
time.sleep(0.2)
print(f"", end='.')
time.sleep(0.2)
print(f"", end='.')
time.sleep(0.2)
print(f"{bcolors.OKGREEN}RUNNING\n{bcolors.ENDC}")
print(f"FINAL SCORE: {bcolors.UNDERLINE}{qcScore}{bcolors.ENDC}")
Hope you enjoy these games! Have a great day.