def main_function(): global SHARED_DATA ge = GameEngine() for frame in range(FRAMES_LIMIT): ge.set_params(NUM_OF_OBSTACLE, METHOD) ge.cycle() SHARED_DATA = ge.to_json() sleep(TIME_EPSILLON * GAME_SPEED)
def run_tests(filename): players = [] f = open(filename,'r') for script_name in f: try: user_module = importlib.import_module(script_name[:-4]) if hasattr(user_module, 'Player'): try: user_module = user_module.Player() except: print("\nPlayer did not instantiate, make sure it is a class. " "Proceeding assuming non OO code.\n") except: print ("\nCould not import %s\n" % script_name) raise players.append(user_module) test_player_functions(players) game = GameEngine(players) game.start()
def __init__(self, network): self.gameEngine = GameEngine() self.network = network self.lastConnection = None self.serverClock = 0 self.count_down_time = 0 self.client_received_list = [] self.listPkg = PyDatagram() self.clientInputList = PyDatagram() self.clientInputList.addUint16(SERVER_INPUT) self.clientInputList.addUint64(self.serverClock) self.clientsAlive = [] self.clientsDead = [] self.display_text = GameUI.createDisplayUI("Loading...") self.count = 0
def main(stdscr): stdscr.clear() room1 = Room(2, 2, 20, 10,[Door (11,12)]) room2 = Room(30, 8, 20, 10, [Door(40,18),Door(50,13)]) room3 = Room(70,10,30,10,[Door(70,13),Door(88,20)]) room5 = Room(3,30,20,6,[Door(23,33)]) room4 = Room(72,30,20,8,[Door(88,30),Door(72,33)]) a=curses.KEY_UP p1=[4,4] p=perso # MAP 1 rooms_1=[room1,room2,room3,room4,room5] link1= Link([room1.getdoorpos ()[0], [room1.getdoorpos ()[0][0], room2.getdoorpos ()[0][1] + 8], [room2.getdoorpos ()[0][0], room2.getdoorpos ()[0][1] + 8], room2.getdoorpos ()[0] ]) link3=Link([room3.getdoorpos()[1],room4.getdoorpos()[0]]) link4=Link([room5.getdoorpos()[0],room4.getdoorpos()[1]]) a=room2.getdoorpos()[1] a[0]-=2 link2=Link([a,room3.getdoorpos()[0]]) links_1=[link1,link2,link3,link4] corner1=Corner("bl",room1.getdoorpos ()[0][0],room2.getdoorpos ()[0][1] + 9) corner2=Corner("br",room2.getdoorpos ()[0][0]+2,room2.getdoorpos ()[0][1] + 9) corners_1=[corner1,corner2] mob1=Dragon("Fred",200,50,8,8,50,20,Weapon("La Huguette",200,500)) mob2=Bat("Jamie the bat",50,30,10,10,30,10,Belt("The Balt",200,30,30)) mob3=Dragon("Freddy",200,50,38,10,80,90) mobs_1=[] mobs_1.append(mob1) mobs_1.append(mob2) mobs_1.append(mob3) seller1=Seller("Jackie",89,37,[Weapon("La Quentinette",300,600),Consummable("Big pot",100,400)]) PNJs_1=[seller1,levelUpper(5,32)] gmap1=GameMap(stdscr,rooms_1,links_1,corners_1) ### # MAP 2 rooms_2=[room1,room2,room3] links_2=[link1,link2] corner1=Corner("bl",room1.getdoorpos ()[0][0],room2.getdoorpos ()[0][1] + 9) corner2=Corner("br",room2.getdoorpos ()[0][0]+2,room2.getdoorpos ()[0][1] + 9) corners_2=[corner1,corner2] gmap2=GameMap(stdscr,rooms_2,links_2,corners_2) mobs_2=[Dragon("El Cactus",300,200,10,10,150,500)] PNJs_2=[Seller("Bernie",17,4,[Weapon("La Cheatée",1000,1000)]),levelDowner(4,5)] ### # GENERAL gmap=[gmap1,gmap2] gmobs=[mobs_1,mobs_2] gPNJs=[PNJs_1,PNJs_2] gpos=[p1,[4,4]] game=GameEngine(stdscr,p,gmobs[0],gPNJs[0],0) #gamei=copy.deepcopy(game) #gmapi=copy.deepcopy(gmap) #Initialisation gmap[game.level].drawAll() game.drawAll() game.majMobs() game.display.refresh() a=game.display.getch() while(a!= 113 and game.perso.gethp()>1): if(a!=114): l=game.level game=GameEngine(stdscr,p,gmobs[l],gPNJs[l],l) gmap[l].drawAll() game.action(a,gpos) gmap[l].drawAll() game.drawAll() game.majMobs() game.majLevel() game.display.refresh() a=game.display.getch() game.display.clear() #else: #game=copy.deepcopy(gamei) #gmap=copy.deepcopy(gmapi) #a=game.display.getch() if game.perso.gethp()<1: game.display.clear() game.display.addstr(0,0,"GAME OVER") game.display.refresh() game.display.getch() curses.nocbreak() game.display.keypad(False) curses.echo() curses.endwin()
user_module = importlib.import_module(script_name[:-4]) if hasattr(user_module, 'Player'): try: user_module = user_module.Player() except: print("\nPlayer did not instantiate, make sure it is a class. " "Proceeding assuming non OO code.\n") except: print ("\nCould not import %s\n" % script_name) raise players.append(user_module) winners = [] for i in range(0, 10000): game = GameEngine(players) game.start() winners.append(game.living) asdf = {} for i in winners: x = i[0] if x.module.name in asdf.keys(): asdf[x.module.name] += 1 else: asdf[x.module.name] = 1 for i in asdf.keys(): print i + ": " + str(asdf[i])
class Main(QWidget): def __init__(self, **kwargs): super().__init__(**kwargs) self.game = GameEngine() self.board_view = BoardView(self.game.get_svg_board(), parent=self) self.game.set_board_view(self.board_view) self.game.start() self.command = QLineEdit() layout = QGridLayout(self) layout.addWidget(self.board_view) layout.addWidget(self.command) # Signaling self.command.returnPressed.connect(self.execute_command) self.commands = dict( # Exit application. qq=self.quit, # Save current board state to svg. sb=self.save_board, # Halt auto play. q=self.game.halt, # Toggle edit mode. ee=self.game.toggle_edit_mode, # Check result. cc=(lambda: logger.info(self.game.board.result())), # Print legal moves. lm=(lambda: logger.info(', '.join( [str(move) for move in self.game.board.legal_moves]))), # Print available commands. hh=(lambda: logger.info('Commands: ' + ', '.join( list(self.commands.keys()) + list(self.game.commands.keys()))) )) def execute_command(self): cmd, *args = self.command.text().split(' ') self.command.clear() try: self.commands[cmd](*args) except KeyError: if self.game.auto_play: logger.info('Auto-play in progress. Send q to halt.') else: self.execute_game_command(cmd) except Exception as e: logger.exception(e) logger.error('cmd: {cmd}, args: {args}') def execute_game_command(self, cmd): self.game.execute(cmd) def closeEvent(self, event): super().closeEvent(event) self.game.stop() def quit(self): self.game.stop() sys.exit(0) def save_board(self, filename='board.svg'): filename = next(uniquename(filename)) with open(filename, 'w') as file: file.write(str(self.game.get_svg_board())) logger.info('Board written to: ' + filename)
menu = MainMenu(screen) config = menu.menu_loop() while config['player_number'] != 0: n = config['player_number'] players = config['players'] sprites = players['sprites'] controls = players['controls'] orientations = config['map']['orientations'] positions = config['map']['positions'] if n > 0: background = pg.transform.scale( pg.image.load('assets/img/background.jpg'), (60 * gunity, 30 * gunity)) arena = InterfaceObject(screen, background) game = GameEngine(screen, arena, config['map']) for i in range(n): game.add_player(sprites[i], orientations[i], *positions[i], controls[i]) winners = game.game_loop() menu.ending_screen(winners) del game
from game import GameEngine if __name__ == "__main__": game = GameEngine() while len(game.answer_dict) > 0: print() print(game.story_text) print() game.execute_actions() input_flag = True while input_flag: user_input = input("> ").lower() if game.check_answer(user_input) != "Incorrect Answer": input_flag = False elif "hint" in user_input.lower(): print("TODO: Complete Hint List") elif "help" in user_input.lower(): print("No.") print() print(game.story_text)
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """This demo file creates a simple client with TTS support.""" import wx from ytranslate import init, select from game import GameEngine import init from ui.window import ClientWindow app = wx.App() # Load the user configuration engine = GameEngine() engine.load() # Select the configured language lang = engine.settings.get_language() select(lang) # Create the client and ClientWindow window = ClientWindow(engine) world = window.world if world is not None: window.panel.CreateClient() app.MainLoop()