Python pygame.K_KP_ENTER Examples
The following are 22
code examples of pygame.K_KP_ENTER().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.
Example #1
Source File: game115.py From eduActiv8 with GNU General Public License v3.0 | 6 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #2
Source File: game085.py From eduActiv8 with GNU General Public License v3.0 | 6 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and lhv < 3 and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset()
Example #3
Source File: game087.py From eduActiv8 with GNU General Public License v3.0 | 6 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and lhv < self.sollen and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset()
Example #4
Source File: cli.py From stuntcat with GNU Lesser General Public License v2.1 | 5 votes |
def __pgbox(title, message): try: import pygame as pg pg.quit() #clean out anything running pg.display.init() pg.font.init() screen = pg.display.set_mode((460, 140)) pg.display.set_caption(title) font = pg.font.Font(None, 18) foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210) ok = font.render('Ok', 1, foreg, liteg) okbox = ok.get_rect().inflate(200, 10) okbox.centerx = screen.get_rect().centerx okbox.bottom = screen.get_rect().bottom - 10 screen.fill(backg) screen.fill(liteg, okbox) screen.blit(ok, okbox.inflate(-200, -10)) pos = [10, 10] for text in message.split('\n'): if text: msg = font.render(text, 1, foreg, backg) screen.blit(msg, pos) pos[1] += font.get_height() pg.display.flip() stopkeys = pg.K_ESCAPE, pg.K_SPACE, pg.K_RETURN, pg.K_KP_ENTER while 1: e = pg.event.wait() if e.type == pg.QUIT or \ (e.type == pg.KEYDOWN and e.key in stopkeys) or \ (e.type == pg.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)): break pg.quit() except pg.error: raise ImportError
Example #5
Source File: loginscreen.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def onKeyDown(self, event): if event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: self.fsubmit() self.update_trigger()
Example #6
Source File: loginscreen.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def onKeyDown(self, event): if not self.select_item: if event.type == pygame.KEYDOWN and event.key == pygame.K_DELETE: pass elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER and event.key != pygame.K_TAB: lhv = len(self.value) if event.key == pygame.K_BACKSPACE: if lhv > 0: if self.ls.lang.ltr_text: self.value = self.value[0:lhv - 1] else: self.value = self.value[1:lhv] else: char = event.unicode if len(char) > 0 and lhv < 21: if self.ls.lang.ltr_text: self.value = self.value + char else: self.value = char + self.value if self.selection_modifier: if self.ls.prev_user_checked: if self.value != self.ls.prev_user_checked.value: self.ls.prev_user_checked.update_me = True self.ls.prev_user_checked.checked = False self.ls.reload_selects() self.ls.set_scrollbar_top(self.ls.scroll_min_top) elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or event.key == pygame.K_TAB: self.nextFocus() self.update_trigger()
Example #7
Source File: game084.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][18]: char = event.unicode if len(char) > 0 and lhv < 2 and char in self.digits: self.home_square.value += char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][18]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each) if self.board.grid[4][18]: self.check_result() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #8
Source File: game096.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #9
Source File: game034.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][16]: char = event.unicode if len(char) > 0 and char in self.digits: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][16]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each) if self.board.grid[4][16]: self.home_square.value = "" self.home_square.update_me = True self.check_result() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #10
Source File: game095.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #11
Source File: game118.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn2(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn2(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn2(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn2(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #12
Source File: game097.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #13
Source File: game035.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] elif not self.board.grid[4][18]: char = event.unicode if len(char) > 0 and char in self.digits: self.home_square.value = char self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEMOTION and self.drag: if self.board.grid[4][18]: self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each) if self.board.grid[4][18]: self.check_result() self.home_square.value = "" self.home_square.update_me = True elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() if event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #14
Source File: game110.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if self.missing_number == 1: if active == 0: self.change_fract_btn(-1, 0) elif active == 1: self.change_fract_btn(1, 0) else: if active == 0: self.change_fract_btn(0, -1) elif active == 1: self.change_fract_btn(0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: lhv = len(self.active_num.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.active_num.value = self.active_num.value[0:lhv - 1] else: char = event.unicode if self.typed and len(char) > 0 and lhv < 3 and char in self.digits: self.active_num.value += char elif char in self.digits: self.active_num.value = char self.typed = True if len(self.active_num.value) > 0: self.result[self.missing_number - 1] = int(self.active_num.value) else: self.result[self.missing_number - 1] = 0 self.active_num.update_me = True self.mainloop.redraw_needed[0] = True self.auto_check_reset()
Example #15
Source File: game094.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(self.numbers, -1, 0) elif active == 1: self.change_fract_btn(self.numbers, 1, 0) elif active == 2: self.change_fract_btn(self.numbers, 0, -1) elif active == 3: self.change_fract_btn(self.numbers, 0, 1) elif active == 4: self.change_fract_btn(self.numbers2, -1, 0) elif active == 5: self.change_fract_btn(self.numbers2, 1, 0) elif active == 6: self.change_fract_btn(self.numbers2, 0, -1) elif active == 7: self.change_fract_btn(self.numbers2, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset()
Example #16
Source File: game068.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: active = self.board.active_ship if active == 0: self.change_fract_btn(-1) elif active == 1: self.change_fract_btn(1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset() lhv = len(self.nm1.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 2: self.nm1.value = self.nm1.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and char in self.digits: self.numbers_disp[0] = int(char) self.nm1.set_value("0.%s" % char) self.check_result() self.nm1.update_me = True self.mainloop.redraw_needed[0] = True
Example #17
Source File: game040.py From eduActiv8 with GNU General Public License v3.0 | 4 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] self.auto_check_reset() for each in self.units: if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \ each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height: self.toggle_active_unit(each) elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each) self.mainloop.redraw_needed[0] = True if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): if self.active_unit in self.units: self.auto_check_reset() lhv = len(self.active_unit.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.active_unit.value = self.active_unit.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and ((char in self.digits) or (lhv == 0 and self.allow_dash and char == "-")): if lhv < self.imput_limit: self.active_unit.value += char else: self.active_unit.value = char self.active_unit.update_me = True self.mainloop.redraw_needed[0] = True if event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or event.key == pygame.K_TAB or event.key == pygame.K_DOWN): if self.all_completed(): self.custom_check_result() if self.active_unit is not None: self.toggle_active_unit(self.units[(self.active_unit.id + 1) % 5]) elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: if self.active_unit is not None: self.toggle_active_unit(self.units[(self.active_unit.id + 4) % 5]) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #18
Source File: game117.py From eduActiv8 with GNU General Public License v3.0 | 4 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] for each in self.text_fields: if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \ each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height: self.toggle_active_fract(each) active = self.board.active_ship if active == 0: self.change_fract_btn(self.response, -1, 0) elif active == 1: self.change_fract_btn(self.response, 1, 0) elif active == 2: self.change_fract_btn(self.response, 0, -1) elif active == 3: self.change_fract_btn(self.response, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset() lhv = len(self.current_txt) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.current_txt = self.current_txt[0:lhv - 1] self.active_fract.value = self.current_txt self.active_fract.update_me = True if len(self.current_txt) > 0: if self.active_fract == self.sm1a: self.response[0] = int(self.active_fract.value) elif self.active_fract == self.sm1b: self.response[1] = int(self.active_fract.value) elif event.key == pygame.K_TAB: if self.active_fract == self.sm1a: self.toggle_active_fract(self.sm1b) else: self.toggle_active_fract(self.sm1a) else: char = event.unicode if char in self.digits: if len(char) > 0 and lhv < 3 and self.active_fract.value != self.qm: self.current_txt += char else: self.current_txt = char self.active_fract.value = self.current_txt if self.active_fract == self.sm1a: self.response[0] = int(self.active_fract.value) if self.response[0] == self.sum_numbers[0]: self.toggle_active_fract(self.sm1b) elif self.active_fract == self.sm1b: self.response[1] = int(self.active_fract.value) self.active_fract.update_me = True self.mainloop.redraw_needed[0] = True
Example #19
Source File: game030.py From eduActiv8 with GNU General Public License v3.0 | 4 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] self.auto_check_reset() for each in self.units: if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \ each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height: self.toggle_active_unit(each) elif event.type == pygame.MOUSEBUTTONUP: for each in self.board.units: if each.is_door is True: self.board.all_sprites_list.move_to_front(each) self.mainloop.redraw_needed[0] = True if not self.show_msg: if event.type == pygame.KEYDOWN and (event.key != pygame.K_RETURN and event.key != pygame.K_KP_ENTER): if self.active_unit in self.units: self.auto_check_reset() lhv = len(self.active_unit.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.active_unit.value = self.active_unit.value[0:lhv - 1] else: char = event.unicode if len(char) > 0 and ((char in self.digits) or (lhv == 0 and self.allow_dash and char == "-")): if lhv < self.imput_limit: self.active_unit.value += char else: self.active_unit.value = char self.active_unit.update_me = True self.mainloop.redraw_needed[0] = True if event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER or event.key == pygame.K_TAB or event.key == pygame.K_DOWN): if self.all_completed(): self.custom_check_result() if self.active_unit is not None: self.toggle_active_unit(self.units[(self.active_unit.id + 1) % 5]) elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: if self.active_unit is not None: self.toggle_active_unit(self.units[(self.active_unit.id + 4) % 5]) if event.type == pygame.MOUSEMOTION or event.type == pygame.MOUSEBUTTONUP: self.default_hover(event)
Example #20
Source File: game067.py From eduActiv8 with GNU General Public License v3.0 | 4 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] if self.nm1.rect.topleft[0] < pos[0] < self.nm1.rect.topleft[0] + self.nm1.rect.width and \ self.nm1.rect.topleft[1] < pos[1] < self.nm1.rect.topleft[1] + self.nm1.rect.height: self.toggle_active_fract(self.nm1, self.nm2) elif self.nm2.rect.topleft[0] < pos[0] < self.nm2.rect.topleft[0] + self.nm2.rect.width and \ self.nm2.rect.topleft[1] < pos[1] < self.nm2.rect.topleft[1] + self.nm2.rect.height: self.toggle_active_fract(self.nm2, self.nm1) active = self.board.active_ship if active == 0: self.change_fract_btn(-1, 0) elif active == 1: self.change_fract_btn(1, 0) elif active == 2: self.change_fract_btn(0, -1) elif active == 3: self.change_fract_btn(0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset() lhv = len(self.active_fract.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.active_fract.value = self.active_fract.value[0:lhv - 1] elif event.key == pygame.K_TAB: if self.active_fract == self.nm1: self.toggle_active_fract(self.nm2, self.nm1) else: self.toggle_active_fract(self.nm1, self.nm2) else: char = event.unicode if len(char) > 0 and char in self.digits: self.active_fract.set_value("%s" % char) if self.active_fract == self.nm1: self.numbers_disp[0] = int(char) self.toggle_active_fract(self.nm2, self.nm1) else: self.numbers_disp[1] = int(char) self.toggle_active_fract(self.nm1, self.nm2) if self.nm1.value != self.qm and self.nm2.value != self.qm: self.check_result() self.mainloop.redraw_needed[0] = True
Example #21
Source File: game120.py From eduActiv8 with GNU General Public License v3.0 | 4 votes |
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: pos = [event.pos[0] - self.layout.game_left, event.pos[1] - self.layout.top_margin] for each in self.text_fields: if each.rect.topleft[0] < pos[0] < each.rect.topleft[0] + each.rect.width and \ each.rect.topleft[1] < pos[1] < each.rect.topleft[1] + each.rect.height: self.toggle_active_fract(each) active = self.board.active_ship if active == 0: self.change_fract_btn(self.response, -1, 0) elif active == 1: self.change_fract_btn(self.response, 1, 0) elif active == 2: self.change_fract_btn(self.response, 0, -1) elif active == 3: self.change_fract_btn(self.response, 0, 1) self.auto_check_reset() elif event.type == pygame.KEYDOWN and (event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER): self.check_result() elif event.type == pygame.KEYDOWN: self.auto_check_reset() lhv = len(self.current_txt) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.current_txt = self.current_txt[0:lhv - 1] self.active_fract.value = self.current_txt self.active_fract.update_me = True if len(self.current_txt) > 0: if self.active_fract == self.sm1a: self.response[0] = int(self.active_fract.value) elif self.active_fract == self.sm1b: self.response[1] = int(self.active_fract.value) elif event.key == pygame.K_TAB: if self.active_fract == self.sm1a: self.toggle_active_fract(self.sm1b) else: self.toggle_active_fract(self.sm1a) else: char = event.unicode if char in self.digits: if len(char) > 0 and lhv < 3 and self.active_fract.value != self.qm: self.current_txt += char else: self.current_txt = char self.active_fract.value = self.current_txt if self.active_fract == self.sm1a: self.response[0] = int(self.active_fract.value) if self.response[0] == self.sum_numbers[0]: self.toggle_active_fract(self.sm1b) elif self.active_fract == self.sm1b: self.response[1] = int(self.active_fract.value) self.active_fract.update_me = True self.mainloop.redraw_needed[0] = True
Example #22
Source File: engine.py From Fruit-API with GNU General Public License v3.0 | 4 votes |
def __human_control(self, key): if self.player1_human_control and self.player2_human_control: if self.two_players: if key == pygame.K_LEFT: self.player1.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: self.player1.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: self.player1.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: self.player1.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_KP_ENTER: self.__fire_bullet(self.player1, False) if key == pygame.K_a: self.player2.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_d: self.player2.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_w: self.player2.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_s: self.player2.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_SPACE: self.__fire_bullet(self.player2, False) else: if key == pygame.K_LEFT: self.player1.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: self.player1.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: self.player1.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: self.player1.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_SPACE: self.__fire_bullet(self.player1, False) else: if not self.player1_human_control: if self.two_players: if key == pygame.K_LEFT: self.player2.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: self.player2.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: self.player2.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: self.player2.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_SPACE: self.__fire_bullet(self.player2, False) else: if key == pygame.K_LEFT: self.player1.move(GlobalConstants.LEFT_ACTION, self.sprites) if key == pygame.K_RIGHT: self.player1.move(GlobalConstants.RIGHT_ACTION, self.sprites) if key == pygame.K_UP: self.player1.move(GlobalConstants.UP_ACTION, self.sprites) if key == pygame.K_DOWN: self.player1.move(GlobalConstants.DOWN_ACTION, self.sprites) if key == pygame.K_SPACE: self.__fire_bullet(self.player1, False)