def choose_town_job(self): print("=========================================================================") print("Which job would you like to perform?\n\t<1> Help the guards clean up town\n\t<2> Gamble in the casino" "\n\t<3> Beg for money \n\t<h> Help \n\t<t> Go back to town \n\t<q> Quit ") job_choice = input("Input: ") if job_choice == "1": pass elif job_choice == "2": Job.gamble(self) elif job_choice == "3": Job.beg_for_money(self) elif job_choice.lower() == "h": print("=========================================================================") print("\t-Helping the guards involves doing smaller jobs for money.\n\t-Gambling in the casino" " takes a random luck roll and rewards you \n\twell or hurts you\n\t-Begging for money takes a " "random charisma roll and can cause \n\tsome odd effects...") print("=========================================================================") time.sleep(3) Job.choose_town_job(self) elif job_choice.lower() == "t": game = Game() game.town_actions() elif job_choice.lower() == "q": exit() else: Job.choose_town_job(self)
def test_set_score(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) game.score = PLAYER_NAME_ONE self.assertIsInstance(game.score, str)
def train(self): self.student.graph.updateGraph() id_node, number, instruction, question, correct, wrong = self.student.graph.selectExercise( ) game = Game(self, instruction, question, correct, wrong, number, id_node) game.askExercises()
def join(self, message): """ This function checks if there is a player waiting for a game. If there is then it creates a game and sends a message to the two players to start the game """ # Check if player is waiting if self.application.waitingPlayer is not None: # Create Game if player is waiting # Find starting player and assign cross or knots to player player1 = self.application.waitingPlayer player2 = Player(message["name"], self) # Set the waiting player to none self.application.waitingPlayer = None # Add Lookup table newIndex = self.application.gameIndex self.application.gameLookup[player1.socket] = newIndex self.application.gameLookup[player2.socket] = newIndex # Create Game Object game = Game(player1, player2, newIndex) # Add Game to list of games self.application.games[newIndex] = game # Increment Game index self.application.gameIndex += 1 game.start_game() else: # Make player wait if there is no other player waiting newPlayer = Player(message["name"], self) self.application.waitingPlayer = newPlayer
def main(): pygame.init() game = Game() game.main_loop() pygame.quit() print('Goodbye.')
def test_score_tie_breaker(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, True) game.score = PLAYER_NAME_ONE self.assertEqual(game.score, '1 - 0')
def test_get_score(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) game.score = PLAYER_NAME_ONE self.assertEqual(game.score, '15 - 0')
def startGame(): if config.conn["server"]: threading.Thread(target=startServer).start() host = config.conn["host"] port = config.conn["port"] game = Game(host, port) game.run()
def test_set_publisher(self): g = Game() g.setPublisher('Apogee Software [1]') self.assertEqual('Apogee', g.publisher) g.setPublisher('Ariolasoft UK Ltd') self.assertEqual('Ariolasoft UK', g.publisher) g.setPublisher('Incentive Software Ltd') self.assertEqual('Incentive', g.publisher) g.setPublisher('16/48 Tape Magazine') self.assertEqual(g.publisher, '16-48 Tape Magazine')
def test_game_jsonable(self): player1 = Player("Marto") player2 = Player("Pesho") player3 = Player("Nasko") player4 = Player("Petko") team1 = Team("Wolf") team2 = Team("Lion") team1.add_team_members([player1, player2]) team2.add_team_members([player3, player4]) round1 = Round("All trumps", 1) round1.add_round_members([team1, team2]) game = Game([team1, team2], 1) game.rounds.append(round1) self.assertEqual( game.to_json(), json.dumps( { "game 1": [{ "round 1": [{ "Wolf": [{ "Marto": { "points": 0, "announcements": [], "cards": [] } }, { "Pesho": { "points": 0, "announcements": [], "cards": [] } }] }, { "Lion": [{ "Nasko": { "points": 0, "announcements": [], "cards": [] } }, { "Petko": { "points": 0, "announcements": [], "cards": [] } }] }] }] }, cls=OurEncoder))
def test_get_score_deuce(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) for index in range(4): game.score = PLAYER_NAME_ONE game.score = PLAYER_NAME_TWO # Check the Deuce game self.assertEqual(game.score, 'Deuce')
def test_cyrillic(self): g = Game('Треугольник') r = GameRelease(game=g) self.assertEqual(["Треугольник"], r.aliases) g = Game('3угольник') r = GameRelease(game=g) self.assertEqual(["3угольник"], r.aliases) g = Game('Минидрайвер дисковых операций') r = GameRelease(game=g) aliases = r.getAllAliases() self.assertEqual(aliases, ['Минидрайвер дисковых операций'])
def test_players(players, total_games, verbose=False, turn_limit=100): num_wins = [0] * len(players) for i in range(total_games): if i % 10 == 0: print("Episodes:", i) game = Game(random.sample(players, len(players)), verbose=verbose) game.turn_limit = turn_limit winner = game.play() num_wins[players.index(winner)] += 1 for i in range(len(players)): wins_array[i] = num_wins[i] / total_games print(players[i].name, ": ", num_wins[i] / total_games)
def test_get_score_advantage(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) # Set previous score for index in range(3): game.score = PLAYER_NAME_ONE game.score = PLAYER_NAME_TWO # Set the advantage point game.score = PLAYER_NAME_TWO self.assertEqual(game.score, f'Advantage {PLAYER_NAME_TWO}')
def test_get_score_tie_breaker_games(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, True) for index in range(6): game.score = PLAYER_NAME_ONE game.score = PLAYER_NAME_TWO # Check score self.assertEqual(game.score, '6 - 6') game.score = PLAYER_NAME_TWO # Check score self.assertEqual(game.score, '6 - 7')
def scrapeGameData(self, game=Game()): url = game.getWosUrl() selector = self.loadUrl(url) tables = selector.xpath('//table').extract_all() desc_table = Selector(text=tables[5]) desc_rows = desc_table.xpath('//tr').extract_all() for row in desc_rows: row_text = self.getTextFromDescriptionRow(row) if not row_text: continue caption = row_text[0] value = row_text[1] if caption == 'Full title': if value.startswith('[MOD]'): value = row_text[2] game.setTitle(value) elif caption == 'Year of release': game.setYear(value) elif caption == 'Publisher': game.setPublisher(value) elif caption == 'Machine type': game.setMachineType(value) elif caption == 'Number of players': game.setNumberOfPlayers(value) elif caption == 'Type': game.setGenre(value) elif caption == 'Availability': game.setAvailability(value) has_tipshop_pokes = selector.xpath( '//img[@title="Search The Tipshop"]/@title').extract_first() if has_tipshop_pokes == 'Search The Tipshop': game.has_tipshop_pokes = True game_files, additional_materials = self.getFilesLists(tables[4:]) self.scrapeGameFiles(game, game_files) self.scrapeAdditionalMaterials(game, additional_materials)
def test_desc_in_brackets_and_multiline_cheat(self): game = Game('Myth', 3354) self.ts.scrapePokes(game) self.assertEqual(game.cheats[0].description, 'Credits') self.assertEqual(game.cheats[1].description, 'Number of lives') self.assertEqual(game.cheats[2].description, 'Level 1') self.assertEqual(len(game.cheats), 6)
def test_desc_in_brackets_and_broken_brackets(self): game = Game('Flynn' 's Adventure In Bombland', 26114) self.ts.scrapePokes(game) self.assertEqual(game.cheats[0].description, 'Infinite lives') self.assertEqual(game.cheats[1].description, 'Infinite time') #Bug on website: need manual fixing self.assertEqual(game.cheats[2].description, '(number of lives')
def test_get_winner_2(self): player_one = Player(PLAYER_NAME_ONE) player_two = Player(PLAYER_NAME_TWO) game = Game(player_one, player_two, False) # Set previous score for index in range(3): game.score = PLAYER_NAME_ONE self.assertEqual(game.score, '40 - 0') # Check the Winner game game.score = PLAYER_NAME_ONE self.assertIsInstance(game.winner, Player) self.assertEqual(game.winner, player_one) self.assertEqual(game.winner.game, 1)
def test_multipoke_cheats_scraping(self): game = Game(name="Apulija-13", zxdb_id=27997) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(len(game.cheats), 7) multipoke_cheat = game.cheats[-1] self.assertEquals(len(multipoke_cheat.pokes), 9)
def load_from_database(): db_rooms = [] try: with db_session: db_rooms += db.DB_Room.select() except Exception as e: print(e) rooms = [] for room in db_rooms: new_room = Room(room.name, room.max_players, room.owner) new_room.users = room.users["users"] new_room.emails = room.emails["emails"] if room.status == RoomStatus.PREGAME.value: new_room.set_status(RoomStatus.PREGAME) elif room.status == RoomStatus.IN_GAME.value: new_room.set_status(RoomStatus.IN_GAME) else: new_room.set_status(RoomStatus.FINISHED) if (new_room.get_status() != RoomStatus.PREGAME and room.game is not {}): new_room.game = Game(new_room.get_user_list()) new_room.game.build_from_json(room.game) rooms.append(new_room) return rooms
def __init__(self, player_one: Player, player_two: Player): self.player_one = player_one self.player_two = player_two self.is_tie_breaker = self.tie_breaker() self.game = Game(self.player_one, self.player_two, self.is_tie_breaker) self.score = '0 - 0, 0 - 0' self.winner = None
def test_franknstein(self): game = Game(zxdb_id=3316) self.ts.scrapePokes(game) print(game.cheats) self.assertEqual(game.cheats[0].description, 'Infinite lives (One player mode)') self.assertTrue(self.game_has_cheat_named(game, 'immunity')) self.assertTrue(self.game_has_cheat_named(game, 'silent game'))
def test_medium_pokes_scraping(self): game = Game(name="Gimme Bright", zxdb_id=25640) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(game.cheats[0].description, "Lives") self.assertEquals(game.cheats[1].description, "Time") self.assertEquals(game.cheats[2].description, "Lives") self.assertEquals(game.cheats[3].description, "Time")
def test_complex_pokes_scraping(self): game = Game(name="Ghost Hunters", zxdb_id=9350) self.ts.scrapePokes(game) pp.pprint(game.cheats) self.assertEquals(game.cheats[2].description, 'You don\'t need blood goblet (Platform "A")') self.assertEquals(game.cheats[2].pokes[0].address, 41530) self.assertEquals(game.cheats[2].pokes[0].value, 130)
class TestGame(unittest.TestCase): def setUp(self): self.loto = Game() def tearDown(self): del self.loto def test_loto_init(self): self.assertEqual(self.loto.lap, 1) self.assertTrue(self.loto.is_running) def test_loto_pull_out_barrel(self): self.assertTrue( self.loto.pull_out_barrel() in range(1, QUANTITY_BARRELS + 1)) def test___str__(self): self.assertTrue(self.loto.__str__())
def test_cowboy(self): #THIS SHOULD BE FIXED MANUALLY game = Game(name='Cowboy', zxdb_id=15419, db=self.db) game = self.db.getGameByWosID(game.zxdb_id) print(game.cheats) self.assertEqual(len(game.cheats), 2) self.ts.scrapePokes(game) self.assertEqual(len(game.cheats), 3)
def test_variable_poke(self): game = Game(name="Pinball", zxdb_id=3718) self.ts.scrapePokes(game) cheat = game.cheats[1] pp.pprint(game.cheats) self.assertEqual(cheat.description, 'Lives') self.assertEqual(len(cheat.pokes), 1) self.assertEqual(cheat.pokes[0].address, 28950) self.assertEqual(cheat.pokes[0].value, 256)
def index(postVars): global votesToFinish global couchdbServer templateVars = dict() try: db = couchdbServer["currentgame"] except ResourceNotFound as exception: print "There's no active game" return output_template("error.html", templateVars) except: print "Unexpected error on get current game" return output_template("error.html", templateVars) currentGameId = "" for gameid in db: currentGameId = gameid game = Game.load(db,currentGameId) templateVars["opponent"] = game.opponent try: db = couchdbServer["players"] except ResourceNotFound as exception: print "Unable to access players database" return output_template("error.html", templateVars) except: print "Unexpected error accessing players database" return output_template("error.html", templateVars) # select randomly two different players faultSelectingPlayer = True; while faultSelectingPlayer: randomPlayersIds = game.getRandomPlayers() player0 = Player.load(db,randomPlayersIds[0]) player1 = Player.load(db,randomPlayersIds[1]) # are the two players valid? if player0 != None and player1 != None: faultSelectingPlayer = False # save photo files to static content directory player0.updatePhotoFileOnDisk(db) player1.updatePhotoFileOnDisk(db) templateVars["votesToFinish"] = votesToFinish templateVars["player0"] = player0 templateVars["player1"] = player1 return output_template("index.html", templateVars)
def test_hashsums(self): print(os.getcwd()) game = Game(zxdb_id=1660) game_file = GameFile('\pub\sinclair\games\e\E.T.X..tap.zip', game=game) expected_md5 = 'b04c5d9bf88eb5a008696d83eeee69ac' self.assertEqual(expected_md5, game_file.getMD5()) expected_sha1 = 'a879037fd3ba64170e83d4d44652681b1eb097e3' self.assertEqual(expected_sha1, game_file.getSHA1()) expected_crc32 = '3699934d' self.assertEqual(expected_crc32, game_file.getCRC32())
def test_double_tr_ru(self): game = Game('Saboteur II') file = GameFile('Saboteur II (19xx)(-)[h Crudesoft ru][t][tr ru].tap') file.getParamsFromTOSECPath('Saboteur II (19xx)(-)[tr ru Rybkin].tap') self.assertEqual(file.mod_flags, '[h Crudesoft ru][t][tr ru Rybkin]') file = GameFile( 'Saboteur II (19xx)(-)[h Crudesoft ru][t][tr ru Rybkin].tap') file.getParamsFromTOSECPath('Saboteur II (19xx)(-)[tr ru].tap') file.sortModFlags() self.assertEqual(file.mod_flags, '[h Crudesoft ru][t][tr ru Rybkin]')
def test_simple_pokes_scraping(self): game = Game(name='Tujad', zxdb_id=5448) self.ts.scrapePokes(game) self.assertEqual(len(game.cheats), 8) self.assertEqual(game.cheats[0].description, "Infinite lives") self.assertEqual(len(game.cheats[0].pokes), 1) self.assertEqual(game.cheats[0].pokes[0].value, 58) self.assertEqual(game.cheats[1].description, "Infinite energy") self.assertEqual(len(game.cheats[1].pokes), 1) self.assertEqual(game.cheats[1].pokes[0].address, 31443)
def saveGame(postVars): opponent = postVars["opponent"].value.decode("utf-8") date = postVars["date"].value.decode("utf-8") playerIds = postVars["playerIds"].value.decode("utf-8") jsonReturn = dict(error = False) game = Game() game.opponent = opponent game.date = date game.players = playerIds; try: db = couchdbServer.create("currentgame") except: couchdbServer.delete("currentgame") db = couchdbServer.create("currentgame") game.store(db) templateVars = dict(json = json.dumps(jsonReturn)) return output_template("json.html", templateVars )
import logging from classes.game import Game logger = logging.getLogger(__name__) if __name__ == "__main__": logger.info("Game starts now!") g = Game() g.main()
from classes.game import Game game = Game() Game.play(game)
def main (): # Initialize PyGame pygame.init() # Instantiate game game = Game ("Snake") # Load game game.load() # ------ Main Program Loop ------ while game.is_running(): # Process events (e.g. keystrokes, mouseclicks) game.process_events() # Run game logic (e.g. object positions, player attributes) game.run_logic() # Draw the current frame (e.g. the graphics) game.display_frame() # Pause until next frame game.update_clock() # Once the main program loop has stopped (program finished running), # Close all open windows pygame.quit()