Unofficial tetris for Numwork (needs others modules)
from math import * from ion import * from calculatris_2of3 import * from time import * from calculatris_3of3 import * size=[10,20] pieces=[ [".",[(0,0)],(1,1,1)], ["-",[(-1,0),(0,0)],(1,0.75,1)], ["_",[(-1,0),(0,0),(1,0)],(0.75,0.75,1)], [",",[(-1,0),(0,0),(0,-1)],(1,0.75,0.75)], ["i",[(-2,0),(-1,0),(0,0),(1,0)],(0,1,1)], ["t",[(-1,0),(0,0),(1,0),(0,-1)],(1,0,1)], ["o",[(-1,-1),(0,-1),(-1,0),(0,0)],(1,1,0)], ["l",[(-1,0),(0,0),(1,0),(1,-1)],(0,0,1)], ["j",[(-1,-1),(-1,0),(0,0),(1,0)],(1,0.5,0)], ["s",[(-1,0),(0,0),(0,-1),(1,-1)],(0,1,0)], ["z",[(-1,-1),(0,-1),(0,0),(1,0)],(1,0,0)], ["I",[(-2,0),(-1,0),(0,0),(1,0),(2,0)],(0,0.75,0.75)], ["P",[(-1,-1),(0,-1),(-1,0),(0,0),(1,0)],(0.75,1,0)], ["Q",[(-1,-1),(0,-1),(-1,0),(0,0),(1,-1)],(1,0.75,0.25)], ["X",[(-1,0),(0,0),(1,0),(0,-1),(0,1)],(1,0.5,1)], ["U",[(-1,-1),(-1,0),(0,0),(1,0),(1,-1)],(1,0.5,0.25)], ["T",[(-1,-1),(0,-1),(1,-1),(0,0),(0,1)],(1,0.25,1)], ["2",[(-2,0),(-1,0),(0,0),(0,1),(1,1)],(1,0,0.25)], ["5",[(-2,0),(-1,0),(0,0),(0,-1),(1,-1)],(0,1,0.25)], ["J",[(-1,-1),(-1,0),(0,0),(1,0),(2,0)],(1,0.75,0)], ["L",[(-1,1),(-1,0),(0,0),(1,0),(2,0)],(0,0.25,1)], ["7",[(-1,-1),(0,-1),(0,0),(1,0),(0,1)],(0,0,0.75)], ["F",[(1,-1),(0,-1),(0,0),(-1,0),(0,1)],(0.75,0.25,0)], ["Z",[(-1,1),(-1,0),(0,0),(1,0),(1,-1)],(0.75,0,0)], ["S",[(-1,-1),(-1,0),(0,0),(1,0),(1,1)],(0,0.75,0)], ["W",[(-1,-1),(-1,0),(0,0),(0,1),(1,1)],(0.75,0.75,0)], ["V",[(-1,-1),(-1,0),(-1,1),(0,1),(1,1)],(0.25,1,1)], ["y",[(-2,0),(-1,0),(0,0),(1,0),(0,1)],(0,1,0.5)], ["1",[(-2,0),(-1,0),(0,0),(1,0),(0,-1)],(0,0.5,1)]] tetrominos=[pieces[i][1]for i in range(4,11)] colors=[pieces[i][2]for i in range(4,11)] tile=[[int(blocks[0][1][i*8+j]) for j in range(8)]for i in range(8)] tile_name=blocks[0][0] sspeed=5 menu=0 def etiquettes_refreash(): global etiquettes etiquettes = [[ # main menu [" size : "+str(size)+" ","switch_menu(1)"], [" pieces : "+str(len(tetrominos))+"/29 ","switch_menu(3)"], [" starting difficulty : "+str(sspeed)+" ","switch_menu(2)"], [" tiling : "+tile_name+" ","switch_menu(4)"], [" PLAY ","play()"]], # grid size [["[10,20]","set_size([10,20])"],["[12,24]","set_size([12,24])"],["[8,16]","set_size([8,16])"]], # starting speed [[str(i+1),"set_sspeed("+str(i+1)+")"] for i in range(10)], # pieces [["tetrominos","set_tetrominos(4,11)"],["pentaminoes","set_tetrominos(11,29)"],["bits and pieces","set_tetrominos(0,4)"],["mixup","set_tetrominos(0,29)"]], # [[blocks[c][0],"set_tile("+str(c)+")"]for c in range(len(blocks))]] yh=0 def set_size(x): global size size = x switch_menu(0) def set_tetrominos(s,f): global tetrominos,colors tetrominos=[pieces[i][1] for i in range(s,f)] colors=[pieces[i][2] for i in range(s,f)] switch_menu(0) def set_sspeed(x): global sspeed sspeed = x switch_menu(0) def set_tile(x): global tile, tile_name tile_name=blocks[x][0] tile=[[int(blocks[x][1][i*8+j])for j in range(8)]for i in range(8)] switch_menu(0) def play(): e=1 A___play(size,tetrominos,colors,sspeed,tile) switch_menu(0) def switch_menu(new_menu): global menu, yh etiquettes_refreash() menu=new_menu yh=0 fill_rect(0,0,320,222,(20,20,20)) i=0 for etiquette in etiquettes[new_menu]: i+=1 fill_rect(i*5+39,20*i-11,len(etiquette[0])*10+2,25,(0,100,100)) fill_rect(i*5+40,20*i+9,len(etiquette[0])*10,4,(0,150,150)) draw_string(etiquette[0],i*5+40,20*i-10,(0,0,0),(0,255,255)) draw_cursor(yh,200) if new_menu == 0: print_logo() def draw_cursor(yh,tone): for x in range(9): for y in range(9): if cursor[y][x]==1: set_pixel(x+20+yh*5,y+16+yh*20,(tone,tone,tone)) def input_detection(): global yh if keydown(KEY_UP) and yh > 0: draw_cursor(yh,20) yh-=1 draw_cursor(yh,200) sleep(0.3) elif keydown(KEY_DOWN) and yh < len(etiquettes[menu])-1: draw_cursor(yh,20) yh+=1 draw_cursor(yh,200) sleep(0.2) elif keydown(KEY_OK): eval(etiquettes[menu][yh][1]) sleep(0.3) switch_menu(0) e=0 while e == 0: input_detection()