A simple memory test. You play using the arrows keys. A suite of directions (colors: Left=red; Up=blue; Down=green; Right=purple) appear and then, you have to repeat it in the exact order. If you fail on a single color, you lose and you get your score. If you are on Omega or Upsilon, your best score is automatically saved in a file named “mt.sav” Don’t hesitate to tell me if you find any bug on discord (@elnix91) or by mail: elnix91@gmail.com
from kandinsky import draw_string as txt,fill_rect as rect from time import sleep,monotonic from random import randint as r from ion import keydown as k SKY,IMP,TXT=(0,0,0),(0,255,0),(255,)*3 C=((255,0,0),(0,0,255),(0,255,0),(255,0,255)) v=lambda:k(4)|k(52) s=lambda:k(0)|k(1)|k(2)|k(3) clean=lambda x=SKY:rect(0,0,320,222,x) save="mt.sav" try: import os OS=1 except:OS=0 sa=1 if OS: if save in os.listdir(): with open(save,"r")as f: best=int(f.read()) sa=0 if sa: best=0 def d(a,on=1): if a==0:x,y=85,90 elif a==1:x,y=140,35 elif a==2:x,y=140,145 elif a==3:x,y=195,90 if on:c=C[a] else:c=SKY rect(x,y,40,40,c) def e(i,p=0): d(i) if p: while s():1 else:sleep(0.2) d(i,0) if p: while s():1 else:sleep(0.2) clean() txt("MEMORY TEST!",100,0,IMP,SKY) txt("Created by Elnix",80,18,C[0],SKY) d(0);d(1);d(2);d(3) txt("Use arrows keys",85,186,IMP,SKY) txt("Press [OK] or [EXE] to play",25,204,C[3],SKY) while 1: S=1 A=[] while v():1 while not v():1 while v():1 clean() while 1: clean() for i in A:e(i) A.append(r(0,3)) e(A[-1]) while s():1 B=[] failed=0 for i in A: while 1: if s(): if k(0):b=0 elif k(1):b=1 elif k(2):b=2 elif k(3):b=3 break if b==i: e(i,1) continue else: failed=1 break if failed: SKY=(0,0,0) score=len(A)-1 if score>best: txt("You beat best score!",55,5,C[2],SKY) best=score if OS: with open(save,"w")as f: f.write(str(best)) txt("You lose!",115,100,C[0],SKY) txt("Score: "+str(score),160-(7+len(str(score)))*5,130,C[1],SKY) txt("Best score: "+str(best),160-(12+len(str(best)))*5,155,C[1],SKY) txt("[OK] or [EXE] to play again",25,200,C[3],SKY) while not v():1 break sleep(0.7)