def __init__(self, trigger_event): self.options = ['play', 'record', 'macro', 'sequence'] MenuState.__init__(self, outcomes=self.options, trigger_event=trigger_event, page_title='Main menu', fixed_options=[])
def __init__(self, trigger_event): outcomes = ['back', 'play'] MenuState.__init__(self, outcomes=outcomes, trigger_event=trigger_event, page_title='Sequence menu', fixed_options=outcomes, input_keys=['sequence_idx', 'sequence_item'], output_keys=['sequence', 'new_sequence']) self.sequence = ["Add"]
def __init__(self, trigger_event): fixed_options = ['back', 'start'] MenuState.__init__(self, outcomes=fixed_options, trigger_event=trigger_event, page_title='Macro menu', fixed_options=fixed_options, input_keys=['macro_idx', 'macro_item'], output_keys=['macros']) self.macro_slots = ["Empty", "Empty", "Empty"]
def __init__(self): MenuState.__init__(self) self.ui = HudQuad("UI Overlay", 'highscore-ui.png', 0, 0, 800, 600) self.view.Add(self.ui) tracknames = {} laps = {} self.stats = [] self.loaded = False self.menu = [ ApplyMenuItem('Back', self.Menu_Back), ] try: if os.path.exists(Config.USER_STATS): for line in open(Config.USER_STATS, 'r').readlines(): line = line.split('\t') stat = Struct(track=line[0], laps=int(line[1]), name=line[2], time=float(line[3])) self.stats.append(stat) tracknames[stat.track] = 1 laps[stat.laps] = 1 self.current = [] self.curLaps = len(laps.keys()) and laps.keys()[0] trackoptions = [] for track in tracknames: if track in Track.tracks: trackoptions.append((Track.tracks[track].NAME,track)) self.curTrack = None if len(trackoptions)==0: return self.curTrack = trackoptions[0][1] self.menu.append(SelectMenuItem('Track', self.Menu_Track, trackoptions, 0, labelwidth=110)) self.menu.append(SelectMenuItem('Laps', self.Menu_Laps, [(i and str(i) or 'Best',i) for i in laps.keys()], 0, labelwidth=110)) self.loaded = True self.update() self.setBackground('Trackbg-%s.png' % self.curTrack) except: import traceback traceback.print_exc()
def update(self, deltaTime: float) -> bool: super().update(deltaTime) # Terminal check if self.exit: from MenuState import MenuState self.pushState = MenuState() # Update object tree BaseState.update(self, deltaTime) self.objectRoot.update(deltaTime) # Update playground if self.mouseHold: dx, dy = pygame.mouse.get_rel() rotationX = dy * cfg.mouseRotationSensitivity rotationY = dx * cfg.mouseRotationSensitivity self.playgroundRotationX += rotationX if -cfg.playGroundMaxRotationX <= self.playgroundRotationX <= cfg.playGroundMaxRotationX: glRotatef(rotationX, 1, 0, 0) else: self.playgroundRotationX -= rotationX self.playGround.transform.rotation[1] -= rotationY # Check picking self.updatePicking() # Game over if not self.isGameOver(): self.controller() return True
def __init__(self, window): self.window = window self.menu_state = MenuState(self.window) self.game_state = GameState(self.window) self.score_state = ScoreState(self.window) self.current_state = self.menu_state self.running = True
def __init__(self, outcomes, trigger_event, page_title, output_keys=[], input_keys=[], fixed_options=[]): MenuState.__init__(self, outcomes=outcomes, trigger_event=trigger_event, page_title=page_title, output_keys=output_keys, input_keys=input_keys, fixed_options=fixed_options) if not debug: rospy.wait_for_service('files') self.list = rospy.ServiceProxy('files', ListFiles)
class ATMMachine: currentUser = "" users = { "1234" : 1500, "5678" : 200, "4321" : 500, "8765" : 10000, } def __init__(self): self.state = NotLoggedInState(self) #returns value of current user's balance def getVal(self): return self.users.get(self.currentUser, "none") def setNotLoggedInState(self): self.state = NotLoggedInState(self) def setMenuState(self): self.state = MenuState(self) def setInsertPasswordState(self): self.state = InsertPasswordState(self) def setMenuState(self): self.state = MenuState(self) def readInput(self): print(self.state.getStateOptions()) def main(self): print("error") def requestMoney(self): print("error") def insertMoney(self): print("error") def checkBalance(self): print("error") def logoff(self): print("error") def quit(self): print("error")
def create_state(self, s_type): """ Create a state @return State : an instance of a subclass of State @author """ if s_type == 'game': return GameState() elif s_type == 'menu': return MenuState()
import tkinter as tk from Settings import * from MenuState import MenuState # TODO: hightscore?? root = tk.Tk() root.title(settings['states']['menu']['window']['title']) app = MenuState(master=root) app.mainloop()
def setMenuState(self): self.state = MenuState(self)
def setInsertPasswordState(self): self.state = InsertPasswordState(self)
def setNotLoggedInState(self): self.state = NotLoggedInState(self)
def __init__(self): self.state = NotLoggedInState(self)
from MenuState import MenuState ################### # Main Program Loop: State machine using MenuState class as an object to track states and contain useful methods. ################### menu = MenuState() while 1: if menu.state=='Insert Card': menu.query_card() elif menu.state=='Enter Pin': menu.query_pin() elif menu.state=='Select Account': menu.query_account() elif menu.state == 'Select Account Action': menu.query_account_action() else: print('Invalid menu state: ', menu.state) menu.state = 'Insert Card'
import sys import pygame as pg from Game import Game from MenuState import MenuState from GameplayState import GameplayState from GameOverState import GameOverState pg.init() screen = pg.display.set_mode((224 * 3, 256 * 3)) icon = pg.image.load("Assets/Textures/arkanoid_icon.png") states = { "Menu": MenuState(), "Gameplay": GameplayState(), "GameOver": GameOverState() } game = Game(screen, states, "Menu", "Arkanoid", icon) game.run() pg.quit() sys.exit()