Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * from random import randint telesmooth = [15,15,13,12,9,8,7,6,5,4,3,2,1,0,0,0] game = {'click':0,'enable':1,'telenum':0,'free':1,'score':0,'timer':'- - -'} disp0 = [randint(0,9),randint(0,9),randint(0,9)] dispd = {'disp0y':350,'disp1y':250,'disp2y':150,'num':0,'filler':50,'filler2':450,'fdisp':str(disp0[0])+str(disp0[1])+str(disp0[2])} disp1 = [randint(0,9),randint(0,9),randint(0,9)] disp2 = [randint(0,9),randint(0,9),randint(0,9)] start = {'y':100} ans = ['_','_','_'] class tele(): instance = [] x = 250 y = 250 def __init__(self,x,y): self.x = x self.y = y tele.instance.append(self) def setup(): size(500,500) tele(250,550); tele(250,450); tele(250,350); tele(250,250); tele(250,150); tele(250,50); tele(250,-50) def mousePressed(): game['click'] += 1 def mouseReleased(): game['click'] = 0 def keyPressed(): if keyboard.key in ['1','2','3','4','5','6','7','8','9','0']: ans.remove(ans[0]) ans.append(keyboard.key) def draw(): try: game['timer'] -= 1 except: pass if game['click'] > 30: game['click'] = 30 if game['click'] >= 1: game['click'] += 1 rectMode(CENTER,CENTER) background(0xffffffaa) fill(240,0,0) rect(50,350,180,100) rect(450,350,180,100) for i in tele.instance: fill(40) rect(i.x,i.y,160,80) beginShape() vertex(i.x+80,i.y+40) vertex(i.x+80,i.y-40) vertex(i.x+100,i.y-80) vertex(i.x+100,i.y) vertex(i.x+80,i.y+40) endShape() beginShape() vertex(i.x+80,i.y-40) vertex(i.x+100,i.y-80) vertex(i.x-60,i.y-80) vertex(i.x-80,i.y-40) vertex(i.x+80,i.y-40) endShape() fill(130) rect(i.x,i.y,140,60) textSize(40) fill(0,240,0) textAlign(CENTER,CENTER) if dispd['num'] == 1: text(disp0[0],220,dispd['disp0y']) text(disp0[1],250,dispd['disp0y']) text(disp0[2],280,dispd['disp0y']) text(disp2[0],220,dispd['disp2y']) text(disp2[1],250,dispd['disp2y']) text(disp2[2],280,dispd['disp2y']) text('_',220,dispd['disp1y']) text('_',250,dispd['disp1y']) text('_',280,dispd['disp1y']) if dispd['num'] == 0: text(disp1[0],220,dispd['disp1y']) text(disp1[1],250,dispd['disp1y']) text(disp1[2],280,dispd['disp1y']) text(disp2[0],220,dispd['disp2y']) text(disp2[1],250,dispd['disp2y']) text(disp2[2],280,dispd['disp2y']) text('_',220,dispd['disp0y']) text('_',250,dispd['disp0y']) text('_',280,dispd['disp0y']) if dispd['num'] == 2: text(disp1[0],220,dispd['disp1y']) text(disp1[1],250,dispd['disp1y']) text(disp1[2],280,dispd['disp1y']) text(disp0[0],220,dispd['disp0y']) text(disp0[1],250,dispd['disp0y']) text(disp0[2],280,dispd['disp0y']) text('_',220,dispd['disp2y']) text('_',250,dispd['disp2y']) text('_',280,dispd['disp2y']) text('?',220,dispd['filler']);text('?',220,dispd['filler']-100); text('?',250,dispd['filler']);text('?',250,dispd['filler']-100); text('?',280,dispd['filler']);text('?',280,dispd['filler']-100); text(dispd['fdisp'][0],220,dispd['filler2']);text(dispd['fdisp'][1],250,dispd['filler2']);text(dispd['fdisp'][2],280,dispd['filler2']) fill(0) text('Score',50,25) text(game['score'],50,75) text('Time',50,150) text(game['timer'],50,200) if game['enable'] == 1: if dispd['num'] == 0: if ans[0] == str(disp0[0]) and ans[1] == str(disp0[1]) and ans[2] == str(disp0[2]): game['enable'] = 0 game['score'] += 1 if dispd['num'] == 1: if ans[0] == str(disp1[0]) and ans[1] == str(disp1[1]) and ans[2] == str(disp1[2]): game['enable'] = 0 game['score'] += 1 if dispd['num'] == 2: if ans[0] == str(disp2[0]) and ans[1] == str(disp2[1]) and ans[2] == str(disp2[2]): game['enable'] = 0 game['score'] += 1 if game['free'] > 0: if game['click'] == 2: game['enable'] = 0 game['free'] -= 1 if game['enable'] == 0: game['timer'] = 201 if len(telesmooth) == 0: game['enable'] = 1 tele.instance[game['telenum']].y -= 700 tele(250,-50) tele.instance.remove(tele.instance[0]) if dispd['num'] == 0: dispd['disp0y'] = 150 if dispd['num'] == 1: dispd['disp1y'] = 150 if dispd['num'] == 2: dispd['disp2y'] = 150 dispd['filler'] -= 100 dispd['filler2'] -= 100 if dispd['num'] == 0: dispd['fdisp'] = str(disp0[0])+str(disp0[1])+str(disp0[2]) disp0[0] = randint(0,9);disp0[1] = randint(0,9);disp0[2] = randint(0,9); if dispd['num'] == 1: dispd['fdisp'] = str(disp1[0])+str(disp1[1])+str(disp1[2]) disp1[0] = randint(0,9);disp1[1] = randint(0,9);disp1[2] = randint(0,9); if dispd['num'] == 2: dispd['fdisp'] = str(disp2[0])+str(disp2[1])+str(disp2[2]) disp2[0] = randint(0,9);disp2[1] = randint(0,9);disp2[2] = randint(0,9); dispd['num'] = (dispd['num'] + 1) % 3 telesmooth.extend([15,15,13,12,9,8,7,6,5,4,3,2,1,0,0,0]) else: k = telesmooth.pop() for i in tele.instance: i.y += k dispd['disp0y'] += k; dispd['disp1y'] += k; dispd['disp2y'] += k; dispd['filler'] += k; dispd['filler2'] += k start['y'] += k*-3 fill(0x66e10000) rect(250,350,220,100) fill(200) rect(250,start['y'],250,150) fill(0) textSize(25) text('Type in the number',250,start['y']-50) text('when it reaches the',250,start['y']-25) text('red line',250,start['y']) text('Click to start',250,start['y']+40) textSize(40) text(str(ans[0])+str(ans[1])+str(ans[2]),70,350) if game['timer'] == 0: textSize(40) if dispd['num'] == 0: text(str(disp0[0])+str(disp0[1])+str(disp0[2]),430,350) if dispd['num'] == 1: text(str(disp1[0])+str(disp1[1])+str(disp1[2]),430,350) if dispd['num'] == 2: text(str(disp2[0])+str(disp2[1])+str(disp2[2]),430,350) exitp() run()
3numbergame.py
( around 173 lines python code )
Published By:
luyfru
Published on
2024-06-06T23:46:40Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here