def cookie_test(self,target,top,data,log): miss = 0 correct_resp = 0 sw = Stop_Watch() log.set_top('trial_nr\tkey_pressed\tresponse\tresponse_time') for i in range(data.get_n_trials()): self.surface.fill(self.bg_blank) trial = data.get_trial() sprite = target[trial[1]] if trial[2] == '"2"': correct = 0 else: correct = 1 self.draw_three_sprites(top,sprite) sw.start() key_pressed = False press = -1 pygame.event.clear() while(True): for event in pygame.event.get(): self.standart_event(event) if event.type == MOUSEBUTTONDOWN: try: if event.button == 1: sw.stop() press = 0 key_pressed = True elif event.button == 3: sw.stop() press = 1 key_pressed = True except UnicodeDecodeError: print(event.key) if key_pressed: log.add([i,press,int(press==correct),sw.get_time()]) self.surface.fill(self.bg_blank) pygame.display.update() break self.mainClock.tick(40) pygame.time.wait(500)
def start(self): sw = Stop_Watch() self.log.set_top('trial_nr\tsyllable_l\tsyllable_m\tsyllable_r\tsound\tkey_pressed\tresponse\tresponsetime') trials = Trial_Data(self.order) n = trials.get_n_trials() side = [] miss = 0 for i in range(n): size = self.surface.get_size() self.bg = pygame.transform.scale(self.bg,size) self.surface.blit(self.bg,(0,0)) accept = False while not accept: trial_index, trial = trials.get_trial() syllable = trial[1] syllable_sprite = trial[2],trial[3],trial[4] if syllable_sprite[0] == syllable: correct = 0 elif syllable_sprite[1] == syllable: correct = 1 else: correct = 2 if len(side) == 0 or trials.get_n_trials() <= 1 or i > 20: side.append(correct) accept = True elif side[len(side)-1] != correct: side = [correct] accept = True elif len(side) < 2: side.append(correct) accept = True trials.accept(trial_index) # print(syllable+'\t'+str(correct)+'\t'+str(syllable_sprite)) sprite = self.sprites[trial[5]][trial[6]] if trial[6] == 'l': direction = 1 else: direction = 0 self.enter_sprite(sprite,direction) self.surface.blit(self.syllable_images[syllable_sprite[0]]['l'],(size[0]/4-self.syllable_images[syllable_sprite[0]]['l'].get_size()[0]/2,self.surface.get_size()[1]/3)) self.surface.blit(self.syllable_images[syllable_sprite[1]]['m'],(self.position_center_width(self.syllable_images[syllable_sprite[1]]['m']),self.surface.get_size()[1]/3)) self.surface.blit(self.syllable_images[syllable_sprite[2]]['r'],(3*size[0]/4-self.syllable_images[syllable_sprite[2]]['r'].get_size()[0]/2,self.surface.get_size()[1]/3)) pygame.display.update() self.syllable_sounds[trial[1]][str(random.randint(1,3))].play() sw.start() key_pressed = False repeat = True pressed = 0 pygame.event.clear() while repeat: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: try: if self.left.find(unichr(event.key)) >= 0: sw.stop() pressed = 0 key_pressed = True elif self.right.find(unichr(event.key)) >= 0: sw.stop() pressed = 2 key_pressed = True elif event.key == K_SPACE: sw.stop() pressed = 1 key_pressed = True except UnicodeDecodeError: print(event.key) if key_pressed: log_line = [trial[0],trial[2],trial[3],trial[4],trial[1],pressed,int(pressed==correct),sw.get_time()] self.log.add(log_line) self.surface.blit(self.bg,(0,0)) self.draw_sprite(sprite) if correct == 0: self.surface.blit(self.syllable_images[syllable_sprite[0]]['l'],(size[0]/4-self.syllable_images[syllable_sprite[0]]['l'].get_size()[0]/2,self.surface.get_size()[1]/3)) elif correct == 1: self.surface.blit(self.syllable_images[syllable_sprite[1]]['m'],(self.position_center_width(self.syllable_images[syllable_sprite[1]]['m']),self.surface.get_size()[1]/3)) else: self.surface.blit(self.syllable_images[syllable_sprite[2]]['r'],(3*size[0]/4-self.syllable_images[syllable_sprite[2]]['r'].get_size()[0]/2,self.surface.get_size()[1]/3)) pygame.display.update() if pressed == correct: self.syllable_sounds[syllable_sprite[correct]]['pos'+str(random.randint(1,4))].play() pygame.time.wait(4000) repeat = False else: self.syllable_sounds[syllable_sprite[correct]]['neg'+str(random.randint(1,2))].play() pygame.time.wait(4500) miss += 1 if correct == 0: self.surface.blit(self.syllable_images[syllable_sprite[1]]['m'],(self.position_center_width(self.syllable_images[syllable_sprite[1]]['m']),self.surface.get_size()[1]/3)) self.surface.blit(self.syllable_images[syllable_sprite[2]]['r'],(3*size[0]/4-self.syllable_images[syllable_sprite[2]]['r'].get_size()[0]/2,self.surface.get_size()[1]/3)) elif correct == 1: self.surface.blit(self.syllable_images[syllable_sprite[0]]['l'],(size[0]/4-self.syllable_images[syllable_sprite[0]]['l'].get_size()[0]/2,self.surface.get_size()[1]/3)) self.surface.blit(self.syllable_images[syllable_sprite[2]]['r'],(3*size[0]/4-self.syllable_images[syllable_sprite[2]]['r'].get_size()[0]/2,self.surface.get_size()[1]/3)) else: self.surface.blit(self.syllable_images[syllable_sprite[0]]['l'],(size[0]/4-self.syllable_images[syllable_sprite[0]]['l'].get_size()[0]/2,self.surface.get_size()[1]/3)) self.surface.blit(self.syllable_images[syllable_sprite[1]]['m'],(self.position_center_width(self.syllable_images[syllable_sprite[1]]['m']),self.surface.get_size()[1]/3)) pygame.display.update() self.syllable_sounds[syllable_sprite[correct]][str(random.randint(1,3))].play() sw.start() key_pressed = False pygame.event.clear() self.mainClock.tick(40) self.exit_sprite(sprite,direction) return miss
class CatchMeIfYouCan(Engine): def __init__(self,log,surface,bg,syllable_sounds,sprites,order,neo=True): Engine.__init__(self,surface,bg,None,syllable_sounds,None,False,order,neo) self.log = log self.sprites = sprites def play_instruction(self,instr1,instr2,instr_image): self.surface.blit(instr_image,(0,0)) pygame.display.update() instr1.play() pygame.time.wait(5000) instr2.play() pygame.time.wait(18000) def start(self): self.sw = Stop_Watch() self.log.set_top('trial_nr\tsound\tsprite\tdirection\tpressed\tresponse_time') trials = Trial_Data(self.order) n = trials.get_n_trials() miss = 0 for i in range(n): trial_index, trial = trials.get_trial() trials.accept(trial_index) sprite = self.sprites[trial[1]][trial[3]] sound = trial[2] correct = trial[1] == trial[2] retry = True while retry: pressed = self.fly_through(sprite,trial[3],self.syllable_sounds[sound][str(random.randint(1,3))]) log_line = [trial[0],sound,trial[1],trial[3],pressed,self.sw.get_first_time()] if correct: self.surface.blit(self.bg,(0,0)) self.surface.blit(sprite,(self.position_center_width(sprite),self.position_center_height(sprite))) pygame.display.update() if pressed: retry = False self.syllable_sounds[sound]['pos'+str(random.randint(1,4))].play() pygame.time.wait(3700) else: self.syllable_sounds[sound]['miss'].play() pygame.time.wait(5500) miss += 1 else: if pressed: self.surface.blit(self.bg,(0,0)) self.surface.blit(self.sprites[trial[2]][trial[3]],(self.position_center_width(sprite),self.position_center_height(sprite))) pygame.display.update() self.syllable_sounds[sound]['neg'+str(random.randint(1,2))].play() pygame.time.wait(4500) miss += 1 else: retry = False return miss def fly_through(self,sprite,direction,sound): size_sprite = sprite.get_size()[0] size_surface = self.surface.get_size()[0] if direction == 'r': x0 = -1*size_sprite dx = 5 else: x0 = size_surface dx = -5 s = Engine.Sprite(self.surface,sprite,(x0,self.position_center_height(sprite))) move = True moved = 0 while move: s.move(dx,0) self.surface.blit(self.bg,(0,0)) s.draw() pygame.display.update() moved += abs(dx) if moved > size_sprite: move = False self.mainClock.tick(36) pygame.event.clear() self.sw.start() sound.play() move = True pressed = False while move: s.move(dx,0) self.surface.blit(self.bg,(0,0)) s.draw() pygame.display.update() if direction == 'r': if s.get_position()[0] > size_surface + size_sprite: move = False else: if s.get_position()[0] < -1*size_sprite: move = False for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: if event.key == K_SPACE: self.sw.stop() dx = dx * 3 pressed = True else: try: print(chr(event.key)) except ValueError: print('blubb') self.mainClock.tick(36) self.sw.stop() return pressed
def start(self): sw = Stop_Watch() self.log.set_top('trial_nr\tsyllable_l\tsyllable_m\tsyllable_r\tsound\tkey_pressed\tresponse\trespones_time') trials = Trial_Data(self.order) n = trials.get_n_trials() side = [] miss = 0 for i in range(n): size = self.surface.get_size() bg = pygame.transform.scale(self.bg,size) self.surface.blit(bg,(0,0)) accept = False k = 0 while not accept: ++k trial_index, trial = trials.get_trial() syllable = trial[1] sprite = trial[2],trial[3],trial[4] if syllable == sprite[0]: correct = 0 elif syllable == sprite[1]: correct = 1 else: correct = 2 if len(side) == 0 or trials.get_n_trials() <= 1 or k > 20: side.append(correct) accept = True elif side[len(side)-1] != correct: side = [correct] accept = True elif len(side) < 2: side.append(correct) accept = True trials.accept(trial_index) left = Engine.Sprite(self.surface,self.sprites[sprite[0]]['r'],(self.position_center_width(self.sprites[sprite[0]]['r'])-300,self.surface.get_size()[1])) middle = Engine.Sprite(self.surface,self.sprites[sprite[1]]['y'],(self.position_center_width(self.sprites[sprite[1]]['y']),self.surface.get_size()[1])) right = Engine.Sprite(self.surface,self.sprites[sprite[2]]['g'],(self.position_center_width(self.sprites[sprite[2]]['g'])+300,self.surface.get_size()[1])) if correct == 0: sprite_correct = left sprite_wrong = [middle,right] elif correct == 1: sprite_correct = middle sprite_wrong = [left,right] elif correct == 2: sprite_correct = right sprite_wrong = [left,middle] self.surface.blit(bg,(0,0)) [x.draw() for x in [left,middle,right]] pygame.display.update() while (left.get_position()[1] > self.position_center_height(left.get_sprite())): self.surface.blit(bg,(0,0)) [x.move(0,-13) for x in [left,middle,right]] [x.draw() for x in [left,middle,right]] pygame.display.update() self.mainClock.tick(24) #raw_input('press any key to proceed') self.syllable_sounds[syllable][str(random.randint(1,3))].play() sw.start() f = True key_pressed = False pressed = -1 while f: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: try: if self.left.find(unichr(event.key)) >= 0: sw.stop() key_pressed = True pressed = 0 elif self.right.find(unichr(event.key)) >= 0: sw.stop() key_pressed = True pressed = 2 elif event.key == K_SPACE: sw.stop() key_pressed = True pressed = 1 except ValueError: print(event.key) if key_pressed: log_line = [trial[0],sprite[0],sprite[1],sprite[2],syllable,pressed,int(pressed==correct),sw.get_time()] self.log.add(log_line) if pressed == correct: self.syllable_sounds[syllable]['pos'+str(random.randint(1,4))].play() self.balloon_wrong_exit(sprite_correct,sprite_wrong) pygame.time.wait(2100) self.balloon_correct_exit(sprite_correct) f = False else: self.syllable_sounds[syllable]['neg'+str(random.randint(1,2))].play() miss += 1 self.balloon_wrong_exit(sprite_correct,sprite_wrong) pygame.time.wait(2600) self.balloon_wrong_enter(sprite_correct,sprite_wrong) pygame.event.clear() self.syllable_sounds[syllable][str(random.randint(1,3))].play() sw.start() key_pressed = False return miss
def start(self): sw = Stop_Watch() self.log.set_top('trial_nr\tsyllable_l\tsyllable_r\tsound\tkey_pressed\tresponse\tresponsetime') trials = Trial_Data(self.order) n = trials.get_n_trials() side = [] miss = 0 for i in range(n): size = self.surface.get_size() self.bg = pygame.transform.scale(self.bg,size) self.surface.blit(self.bg,(0,0)) accept = False while not accept: trial_index,trial = trials.get_trial() syllable = trial[1] sprite = trial[2],trial[3] if syllable == sprite[0]: correct = 0 else: correct = 1 if len(side) == 0 or trials.get_n_trials() <= 1 or i > 20: side.append(correct) accept = True elif side[len(side)-1] != correct: side = [correct] accept = True elif len(side) < 2: side.append(correct) accept = True trials.accept(trial_index) position = self.sprite_fly_in(self.sprites[sprite[0]],self.sprites[sprite[1]]) pygame.display.update() self.syllable_sounds[syllable][str(random.randint(1,3))].play() sw.start() key_pressed = False f = True pressed = -1 while f: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: try: if self.left.find(unichr(event.key)) >= 0: sw.stop() pressed = 0 key_pressed = True elif self.right.find(unichr(event.key)) >= 0: sw.stop() pressed = 1 key_pressed = 1 except UnicodeDecodeError: print(event.key) if key_pressed: log_line = [trial[0],sprite[0],sprite[1],syllable,pressed,int(pressed==correct),sw.get_time()] self.log.add(log_line) self.surface.blit(self.bg,(0,0)) self.surface.blit(self.sprites[sprite[correct]],position[correct]) pygame.display.update() if pressed == correct: self.syllable_sounds[syllable]['pos'+str(random.randint(1,4))].play() pygame.time.wait(3700) pygame.event.clear() f = False if pressed != correct: key_pressed = False self.syllable_sounds[syllable]['neg'+str(random.randint(1,2))].play() pygame.time.wait(4500) miss += 1 self.surface.blit(self.sprites[sprite[pressed]],position[pressed]) pygame.display.update() self.syllable_sounds[syllable][str(random.randint(1,3))].play() sw.start() pygame.event.clear() self.mainClock.tick(24) return miss
def start(self,n=10): miss = 0 sw = Stop_Watch() self.reset_syllables_called() self.log.set_top('trial_nr\tsyllable_l\tsyllable_r\tsound\tkey_pressed\tresponse\tresponsetime\tsprite') if not self.random_order: trials = Trial_Data(self.order) n = trials.get_n_trials() site = [] for i in range(n): size = self.surface.get_size() self.bg = pygame.transform.scale(self.bg,size) self.surface.blit(self.bg,(0,0)) if self.random_order: correct = random.randint(0,1) direction = random.randint(0,1) if direction == 0: direction_str = 'l' else: direction_str = 'r' sprite_str = self.sprites.keys()[random.randint(0,self.n_sprites-1)] check = True i = 0 while check: i += 1 syllable = self.choose_two(self.n_syllables) if i < 20: check = not self.check_correct_syllable(self.syllables[syllable[correct]]) else: check = False syllable_str = [self.syllables[syllable[0]],self.syllables[syllable[1]]] else: accept = False while not accept: trial_index,trial = trials.get_trial() syllable_correct = trial[2] syllable_left = string.lower(trial[3]) syllable_right = string.lower(trial[4]) syllable_str = [syllable_left,syllable_right] if syllable_correct == syllable_left: correct = 0 else: correct = 1 if len(site) == 0 or trials.get_n_trials() <= 1 or i > 20: site.append(correct) accept = True else: if site[len(site)-1] != correct: site = [correct] accept = True else: if len(site) < 2: site.append(correct) accept = True trials.accept(trial_index) sprite = trial[1] sprite_str = sprite[:-2] direction_str = string.lower(sprite[-1:]) if direction_str == 'l': direction = 0 else: direction = 1 sprite = self.sprites[sprite_str][direction_str] self.enter_sprite(sprite,direction) pygame.event.clear() self.draw_syllable_left(self.syllable_images[syllable_str[0]]['l']) self.draw_syllable_right(self.syllable_images[syllable_str[1]]['r']) pygame.display.update() self.syllable_sounds[syllable_str[correct]][str(random.randint(1,3))].play() sw.start() key_pressed = False press = 0 while True: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: try: if self.left.find(unichr(event.key))>= 0: sw.stop() press = 0 key_pressed = True if self.right.find(unichr(event.key)) >=0: sw.stop() press = 1 key_pressed = True except UnicodeDecodeError: print(event.key) if press == correct and key_pressed: log_line = [trial[0],syllable_str[0],syllable_str[1],syllable_str[correct],press,int(press==correct),sw.get_time(),sprite_str] # print(log_line) self.log.add(log_line) self.syllable_sounds[syllable_str[correct]]['pos'+str(random.randint(1,4))].play() self.surface.blit(self.bg,(0,0)) self.draw_sprite(sprite) if correct == 0: self.draw_syllable_left(self.syllable_images[syllable_str[0]]['l']) else: self.draw_syllable_right(self.syllable_images[syllable_str[1]]['r']) pygame.display.update() pygame.time.wait(3700) pygame.event.clear() break if press != correct and key_pressed: log_line = [i,syllable_str[0],syllable_str[1],syllable_str[correct],press,int(press==correct),sw.get_time(),sprite_str] self.log.add(log_line) key_pressed = False self.syllable_sounds[syllable_str[correct]]['neg'+str(random.randint(1,2))].play() self.surface.blit(self.bg,(0,0)) self.draw_sprite(sprite) if correct == 0: self.draw_syllable_left(self.syllable_images[syllable_str[0]]['l']) else: self.draw_syllable_right(self.syllable_images[syllable_str[1]]['r']) pygame.display.update() pygame.time.wait(4500) miss += 1 if correct == 0: self.draw_syllable_right(self.syllable_images[syllable_str[1]]['r']) else: self.draw_syllable_left(self.syllable_images[syllable_str[0]]['l']) pygame.display.update() self.syllable_sounds[syllable_str[correct]][str(random.randint(1,3))].play() sw.start() pygame.event.clear() self.mainClock.tick(40) self.exit_sprite(sprite,direction) return miss
class Morse1(Stage): def __init__(self,beep=False): self.log = Monster_Logger2('morse1') Stage.__init__(self,True,title='Morse',) self.start('Teil 1') self.surface.fill(self.bg_blank) pygame.display.update() self.load_sound(os.path.join(self.path,'audio/morse1/Instr1.ogg')).play() self.blank() pygame.time.wait(5000) image = pygame.image.load(os.path.join(self.path,'images/morse/dot.tif')) self.draw(image,(self.position_center_width(image),self.position_center_height(image))) pygame.display.update() pygame.time.wait(4300) image = pygame.image.load(os.path.join(self.path,'images/morse/dash.tif')) self.draw(image,(self.position_center_width(image),self.position_center_height(image))) pygame.display.update() pygame.time.wait(4200) self.play_instruction('audio/morse1/Instr2.ogg') self.draw_stuff('images/morse/dot.tif') self.stopwatch = Stop_Watch() self.stopwatch.start() self.play_instruction('audio/morse1/ta.ogg',False) pygame.time.wait(500) self.surface.fill(self.bg_blank) pygame.display.update() pygame.time.wait(500) self.draw_stuff('images/morse/dash.tif') self.play_instruction('audio/morse1/maa.ogg',False) pygame.time.wait(500) self.surface.fill(self.bg_blank) pygame.display.update() pygame.time.wait(500) self.play_instruction('audio/morse1/Instr3.ogg') self.log.add_new_log('learn1') self.stuff(Trial_Data('level/data/mor1/learn1.dat')) self.load_sound(os.path.join(self.path,'audio/morse1/Instr4.ogg')).play() self.blank() pygame.time.wait(2000) image = pygame.image.load(os.path.join(self.path,'images/morse/dot_dash.tif')) self.draw(image,(self.position_center_width(image),self.position_center_height(image))) pygame.display.update() pygame.time.wait(8500) self.draw(pygame.image.load(os.path.join(self.path,'images/morse/show_dot.jpg'))) pygame.display.update() pygame.time.wait(3000) self.draw(pygame.image.load(os.path.join(self.path,'images/morse/show_dash.jpg'))) pygame.display.update() pygame.time.wait(3500) self.blank() pygame.time.wait(500) self.play_instruction('audio/morse1/Instr5.ogg') self.log.add_new_log('learn2') self.stuff(Trial_Data('level/data/mor1/learn2.dat')) self.play_instruction('audio/morse1/intro_test.ogg') self.log.add_new_log('test') self.stuff(Trial_Data('level/data/mor1/test.dat'),True) self.play_instruction('audio/morse1/quit.ogg') def draw_stuff(self,path): image = pygame.image.load(os.path.join(self.path,path)) self.surface.fill(self.bg_blank) self.surface.blit(image,(self.position_center_width(image),self.position_center_height(image))) pygame.display.update() def stuff(self,trialdata,test=False): correct = 0 self.log.set_top('trial\timage\tcorrect\ttime') for i in range(trialdata.get_n_trials()): if not test and correct >= 10: break else: trial = trialdata.get_trial() image = trial[1][1:-1] # self.play_instruction(self.noise) pygame.time.wait(500) #self.play_instruction('audio/beep.ogg') self.draw_stuff(os.path.join('images/morse/',image)) self.stopwatch.stop() time = self.stopwatch.get_time() stop = False while not stop: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: if event.key == K_RETURN: correct += 1 self.log.add([trial[0],image,int(True),time]) stop = True self.blank() pygame.time.wait(500) elif event.key == K_SPACE: self.log.add([trial[0],image,int(False),time]) self.blank() pygame.time.wait(500) if not test: # self.play_instruction(self.noise) pygame.time.wait(500) self.draw_stuff(os.path.join('images/morse',image)) self.stopwatch.stop() time = self.stopwatch.get_time() else: stop = True
def test_monster(self,monster,dic,data,log,response=True,n=8,break_when=False): miss = 0 correct_resp = 0 counter = 0 sw = Stop_Watch() log.set_top('trial_nr\tkey_pressed\tresponse\tresponse_time') side = [] for i in range(data.get_n_trials()): self.surface.fill(self.bg_blank) trial = data.get_trial() image = pygame.image.load(os.path.join(self.path,monster[trial[0]])) if trial[2] == '"congruent"': correct = 1 else: correct = 0 self.draw(image,(self.position_center_width(image),self.position_center_height(image))) pygame.display.update() sound = int(trial[1][2]) - 1 dic[sound]['bla'][random.randint(0,4)].play() sw.start() key_pressed = False press = 0 pygame.event.clear() while True: for event in pygame.event.get(): self.standart_event(event) if event.type == MOUSEBUTTONDOWN: try: if event.button == 1: sw.stop() press = 0 key_pressed = True if event.button == 3: sw.stop() press = 1 key_pressed = True except UnicodeDecodeError: print(event.key) if press == correct and key_pressed: log.add([i+1,press,int(press==correct),sw.get_time()]) if response: if correct == 1: dic[sound]['pos'][random.randint(0,2)].play() else: dic[int(bin(sound+1)[-1])]['pos'][random.randint(0,2)].play() correct_resp += 1 counter += 1 pygame.time.wait(3700) else: pygame.time.wait(250) pygame.event.clear() self.surface.fill(self.bg_blank) pygame.display.update() pygame.time.wait(250) break if press != correct and key_pressed: log.add([i+1,press,int(press==correct),sw.get_time()]) miss += 1 counter += 1 if response: if correct == 1: dic[sound]['neg'][random.randint(0,2)].play() else: dic[int(bin(sound+1)[-1:])]['neg'][random.randint(0,2)].play() correct_resp -= 1 pygame.time.wait(4500) dic[sound]['bla'][random.randint(0,4)].play() key_pressed = False sw.start() else: pygame.time.wait(250) self.surface.fill(self.bg_blank) pygame.display.update() pygame.time.wait(250) break pygame.event.clear() self.mainClock.tick(40) print('counter: '+str(counter)+' | correct: '+str(correct_resp)) pygame.time.wait(500) if (correct_resp >= 10 or counter >= 30) and break_when: break return miss
def test_syllable(self,syllable,dic,letter=False,n=8): miss = 0 sw = Stop_Watch() log = Trial_Logger('test_'+syllable) log.set_top('trial_nr\tkey_pressed\tresponse\tresponse_time') m = 1 side = [] for i in range(n): self.surface.fill(self.bg_blank) a = True while a: correct = random.randint(1,2) if len(side) == 0: side.append(correct) a = False elif side[len(side)-1] == correct: if len(side) < 2: side.append(correct) a = False else: side = [correct] a = False image = pygame.image.load(os.path.join(self.path,'images/syllables/'+syllable.upper()+'.gif')) dimension = (self.windowwidth/3,self.transform_height(image,self.windowwidth/3)) image = pygame.transform.scale(image,dimension) if letter: distr = pygame.image.load(os.path.join(self.path,'images/distr/DISTR'+str(random.randint(11,20))+'.gif')) else: distr = pygame.image.load(os.path.join(self.path,'images/distr/DISTR'+str(random.randint(1,10))+'.gif')) distr = pygame.transform.scale(distr,dimension) if correct == 1: self.draw_left(image) self.draw_right(distr) else: self.draw_left(distr) self.draw_right(image) pygame.display.update() dic[str(random.randint(1,3))].play() sw.start() key_pressed = False press = 0 while True: for event in pygame.event.get(): self.standart_event(event) if event.type == KEYDOWN: try: if self.left.find(unichr(event.key)) >= 0: sw.stop() press = 1 key_pressed = True if self.right.find(unichr(event.key)) >= 0: sw.stop() press = 2 key_pressed = True except UnicodeDecodeError: print(event.key) if press == correct and key_pressed: log.add([m,press,int(press==correct),sw.get_time()]) dic['pos'+str(random.randint(1,4))].play() self.surface.fill(self.bg_blank) if correct == 1: self.draw_left(image) else: self.draw_right(image) pygame.display.update() pygame.time.wait(3700) pygame.event.clear() break if press != correct and key_pressed: log.add([m,press,int(press==correct),sw.get_time()]) key_pressed = False dic['neg'+str(random.randint(1,2))].play() self.surface.fill(self.bg_blank) if correct == 1: self.draw_left(image) else: self.draw_right(image) pygame.display.update() miss += 1 pygame.time.wait(4500) if correct == 1: self.draw_right(distr) else: self.draw_left(distr) pygame.display.update() dic[str(random.randint(1,3))].play() sw.start() pygame.event.clear() self.mainClock.tick(40) pygame.time.wait(500) m += 1 log.save() return miss