Beispiel #1
0
    def __init__(self):
        self._game = Game()
        self._window = Window(self._game)
        self._character = self._game.character
        self._window.draw()

        self.ifHasFailed = False
def init():
    global game, player, screen
    # init screen:
    lines, columns = get_terminal_size()
    lines -= 1 + 4  # to fit in cmd properly + score line
    matrix = [[SPACE_CHR * columns] for j in range(lines)]
    screen = Screen(lines, columns, matrix)
    # init game, enemies and player:
    game = Game(1, screen.columns, screen.lines)
    game.generate_enemies()
    player = Player.generate(screen)
Beispiel #3
0
    def __init__(self, num_decks, hotseat, window, time, bet):
        self.num_decks = num_decks
        self.hotseat = hotseat
        self.time_left = time
        self.bet = bet
        self.font = pygame.font.Font("OpenSans-Regular.ttf", 25)#('Arial', 25)
        self.font_arrow = pygame.font.Font("OpenSans-Regular.ttf", 20)#pygame.font.SysFont('Arial', 20)
        self.font_color = (0, 0, 0)
        self.basic_col = (29, 59, 207)
        self.bet_col = (29, 186, 207)
        self.time_col = (29, 207, 56)
        self.grey = (192, 192, 192)
        self.width_rect = 100
        self.height_rect = 50
        self.width_card = 80
        self.center_x = int((width_w - self.width_rect) / 2)
        self.dist = 50
        self.can_click = False
        self.load_it = 0

        self.y = height_w - self.dist - self.height_rect;
        self.x_start = int((width_w - 5 * self.width_rect - 4 * self.dist)/2)
        self.x_hit = self.x_start
        self.x_stand = self.x_start + self.dist + self.width_rect
        self.x_double = self.x_start + 2*(self.dist + self.width_rect)
        self.x_split = self.x_start + 3*(self.dist + self.width_rect)
        self.x_insure = self.x_start + 4*(self.dist + self.width_rect)

        self.button_back = pygame.Rect(self.dist, self.dist, self.width_rect+50, self.height_rect)
        self.button_hit = pygame.Rect(self.x_hit, self.y, self.width_rect, self.height_rect)
        self.button_stand = pygame.Rect(self.x_stand, self.y, self.width_rect, self.height_rect)
        self.button_double = pygame.Rect(self.x_double, self.y, self.width_rect, self.height_rect)
        self.button_split = pygame.Rect(self.x_split, self.y, self.width_rect, self.height_rect)
        self.button_time = pygame.Rect(950-self.dist-self.width_rect, self.dist, self.width_rect+50, self.height_rect)
        self.button_insure = pygame.Rect(self.x_insure, self.y, self.width_rect, self.height_rect)
        self.button_bet = pygame.Rect(self.x_double, self.y - self.dist - self.height_rect, self.width_rect, self.height_rect)
        self.button_player = pygame.Rect(self.x_double, self.y - self.dist - 2*self.height_rect, self.width_rect, self.height_rect)
#        self.cards = Cards(self.num_decks)
        self.it_x = 0
        self.it_y = 0
        self.odslon = False
        self.in_split = False
        self.game = Game()
#        self.deck = Deck()
        self.game.first_round()
        self.game.first_turn()
        print(self.game)
        self.current_player = 0
        self.split_bust = [-1,-1,-1,-1,-1,-1,-1,-1]
Beispiel #4
0
    async def on_message(self, message):

        # verify author
        game = Game.get(str(message.channel.id) + "rps")
        if not game or message.author.id not in game.ids:
            return

        if not message.content:
            return

        # end case
        if message.content.lower() == "end":
            await message.delete()
            await game.end(cancelled=True)

        move = message.content[0]  # only first character
        if move not in "123":
            return

        if message.author.id == game.players[0].id and not game.p1_move:
            game.p1_move = game.p1_moves[int(move)]
            await game.evaluate()

        elif message.author.id == game.players[1].id and not game.p2_move:
            game.p2_move = game.p2_moves[int(move)]
            await game.evaluate()
def load_file(file, sheet="Sheet1"):

    team_manager = TeamManager()

    # load excel sheet into an iterable object
    wb = load_workbook(filename=file, read_only=True)
    ws = wb.active

    # loop through every row
    for row in ws.iter_rows(min_row=2):
        teamA = row[0].value  # Name of Team A
        scoreA = row[1].value  # Team A's Score

        scoreB = row[2].value  # Team B's Score
        teamB = row[3].value  # Name of Team B

        TeamA = team_manager.get_team(teamA)
        TeamB = team_manager.get_team(teamB)

        # if a team with the given name wasn't found in the list than create the team
        if not TeamA:
            TeamA = Team(teamA)

        if not TeamB:
            TeamB = Team(teamB)

        Match = Game(TeamA, TeamB, scoreA, scoreB)

        TeamA.add_game(Match)
        TeamB.add_game(Match)

        team_manager.add_team(TeamA)
        team_manager.add_team(TeamB)

    return team_manager
Beispiel #6
0
def game_create():
  """Returns `Game` instance from load, else new."""
  try:
    game = f3.game_load()
  except FileNotFoundError:
    game = Game()
  return game
Beispiel #7
0
def deleteData(option):
    # games
    if option == '1':
        gameID = gameIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteGameObj = Game(gameID, '', 1)

        # if the record has been successfully deleted, delete from the list as well
        if data.gameManipulate(deleteGameObj, 3):
            for game in globalData['games']:
                if game['gameID'] == gameID:
                    globalData['games'].remove(game)

    # merchandise
    elif option == '2':
        mercID = mercIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteMercObj = Merchandise(mercID, '', 1)

        # if the record has been successfully deleted, delete from the list as well
        if data.merchandiseManipulate(deleteMercObj, 3):
            for item in globalData['merchandise']:
                if item['mercID'] == mercID:
                    globalData['merchandise'].remove(item)

    # sales
    elif option == '3':
        gameID, mercID, exist = salesDataValidation()

        # only perform deletion when the record with the same gameID and mercID exists
        if exist:
            # delete object only needs a proper ID to find and delete the records from the table
            deleteSalesObj = Sales(gameID, mercID, 0)

            # if the record has been successfully deleted, delete from the list as well
            if data.salesManipulate(deleteSalesObj, 3):
                for sale in globalData['sales']:
                    if sale['gameID'] == gameID and sale['mercID'] == mercID:
                        globalData['sales'].remove(sale)
        else:
            message(
                'Sales record with the same GameID and MerchandiseID does not exist!'
            )

    # venues
    elif option == '4':
        venueID = venueIDValidation('delete')

        # delete object only needs a proper ID to find and delete the records from the table
        deleteVenueObj = Venue(venueID, '')

        # if the record has been successfully deleted, delete from the list as well
        if data.venuesManipulate(deleteVenueObj, 3):
            for venue in globalData['venues']:
                if venue['venueID'] == venueID:
                    globalData['venues'].remove(venue)
Beispiel #8
0
def fit_couples_in_game(games, couples_round):

    random.shuffle(couples_round)
    for i in range(len(couples_round) // 2):
        if no_duplicates(couples_round[i], couples_round[len(couples_round) - i - 1]):
            games.append(Game(couples_round[i], couples_round[len(couples_round) - i - 1]))
        else:
            if DEBUG:
                logger.debug("Couples don't fit due to rivals number: " + str(couples_round[i]) + " and " +
                             str(couples_round[len(couples_round) - i - 1]))
Beispiel #9
0
def start_game():
    """Funkcja rozpoczynająca grę."""
    global game
    player1, player2 = playerlist[0], playerlist[1]
    game = Game(player1, player2)
    for i in range(2):
    	game.place_ship(player1)
    	game.place_ship(player2)
    game.print_board(player1)
    game.print_board(player2)
    if len(game.ships_player1) != 0 and len(game.ships_player2) != 0:
            dictData = {
                'type': 'begin_battle',
                'data': {
                    'shipData': {
                        game.player1.name: game.ships_player1,
                        game.player2.name: game.ships_player2,
                    },
                    'turn': game.player1.name
                }
            }
            json_data = json.dumps(dictData)

            send_message(json_data, game.player1)
            send_message(json_data, game.player2)
Beispiel #10
0
 def __init__(self):
     self.game = ga.Game()
     self.screen = pygame.display.set_mode((self.WIDTH_WINDOW, self.HEIGHT_WINDOW))
     pygame.display.set_caption("MacGyver's Labyrinth")
     self.image_wall = pygame.image.load(".\img\wall.png").convert_alpha()
     self.image_wall = pygame.transform.scale(self.image_wall, (self.WIDTH_WINDOW//15, self.HEIGHT_WINDOW//15))
     self.image_path = pygame.image.load(".\img\path.png").convert_alpha()
     self.image_path = pygame.transform.scale(self.image_path, (self.WIDTH_WINDOW//15, self.HEIGHT_WINDOW//15))
     self.image_main_char = pygame.image.load(".\img\macgyver.png").convert_alpha()
     self.image_main_char = pygame.transform.scale(self.image_main_char, (self.WIDTH_WINDOW//15, self.HEIGHT_WINDOW//15))
     self.image_guard = pygame.image.load(".\img\guard.png").convert_alpha()
     self.image_guard = pygame.transform.scale(self.image_guard, (self.WIDTH_WINDOW//15, self.HEIGHT_WINDOW//15))
     self.image_loot = pygame.image.load(".\img\loot.png").convert_alpha()
     self.image_loot = pygame.transform.scale(self.image_loot, (self.WIDTH_WINDOW//15, self.HEIGHT_WINDOW//15))
Beispiel #11
0
    def get_players(self, player_list, player_region, database, api_key, i, j,
                    total_num_players):

        #i determines the depth of the execution
        i = i - 1
        if not player_list or i == 0:
            print "returning"
            return
        for player in player_list:
            print player_list
            player_o = Player(player_region, api_key, account_id=player)
            #player_o = Player(player, player_region, api_key)
            recent_games = player_o.get_games()
            if recent_games == -1 or recent_games == -2 or recent_games.__len__(
            ) < 10:
                continue
            print list(recent_games)[:20]
            for game in list(recent_games)[:20]:
                #time.sleep(0.61)
                if not database.insert_items(player_region + "_games_checked",
                                             "id", str(game)):
                    database.update_numberof_games(
                        player_region + "_games_checked", "id", str(game),
                        "times_hit", 1)
                else:
                    player_list1 = []
                    game_details = Game(game, player_region,
                                        api_key).game_details()
                    game_participants = Json_ops(
                        game_details).participants_id()

                    for current_player in game_participants:
                        if database.get_row_count(
                                player_region +
                                "_players_checked") >= total_num_players:
                            print "ads"
                            return
                        if not current_player == player:
                            player_list1.append(current_player)
                            if not database.insert_items(
                                    player_region + "_players_checked", "id",
                                    str(current_player)):
                                database.update_numberof_games(
                                    player_region + "_players_checked", "id",
                                    str(current_player), "times_hit", 1)

                    self.get_players(player_list1, player_region, database,
                                     api_key, i, j, total_num_players)
Beispiel #12
0
def startGame(messageText, channel, custom=False):
    global games
    games = []

    items = messageText.split(" ")
    if custom:
        return

    homeTeamName = items[2]
    awayTeamName = items[3]

    homeID = findTeamIDByName(homeTeamName)
    awayID = findTeamIDByName(awayTeamName)

    if homeID is None or awayID is None:
        print("Invalid Start Game Command")
        return

    games.append(Game(homeID, awayID, channel))

    return wiki.teams[homeID].coach, wiki.teams[awayID].coach
Beispiel #13
0
    async def on_message(self, message):

        # verify author
        game = Game.get(str(message.channel.id) + "tictactoe")
        if not game or message.author.id not in game.ids:
            return

        if message.content == "":
            return

        # end case
        if message.content.lower() == "end":
            await message.delete()
            await game.end()

        move = message.content[0]  # only first character

        # check that space is open and input is valid
        if message.author.id == game.lead.id and move in "012345678":
            # verify move available
            if not game.board[int(move)]:
                await message.delete()
                game.board[int(move)] = game.lead
                await game.update()
Beispiel #14
0
 game = Game(
     background_image=game_data['background-image'],
     publishers=[
         Publisher(
             name=pub['publisher-name'],
             url=pub.get('publisher-url'),
         ) for pub in (game_data['publishers'] if game_data.
                       get('publishers', None) is not None else [])
     ],
     date_added=game_data['date-added'],
     machine_name=game_data['machine_name'],
     humble_original=game_data['humble-original'],
     downloads={
         k: Download(
             name=dl['name'],
             machine_name=dl['machine_name'],
             url=URLs(
                 web=dl['url']['web'],
                 bittorrent=dl['url'].get('bittorrent'),
             ),
             small=dl.get('small'),
             md5=dl['md5'],
             sha1=dl.get('sha1'),
             file_size=dl['file_size'],
             human_size=dl.get('size', human_size(dl['file_size'])),
             uploaded_at=dl.get('uploaded_at'),
         )
         for k, dl in game_data['downloads'].items()
     },
     popularity=game_data['popularity'],
     trove_showcase_css=game_data['trove-showcase-css'],
     youtube_link=game_data['youtube-link'],
     all_access=game_data['all-access'],
     carousel_content=CarouselContent(
         youtube_link=game_data['carousel-content'].get('youtube-link', []),
         thumbnail=game_data['carousel-content']['thumbnail'],
         screenshot=game_data['carousel-content']['screenshot'],
     ),
     human_name=game_data['human-name'],
     logo=game_data['logo'],
     description_text=game_data['description-text'],
     developers=[
         Developer(
             name=dev['developer-name'],
             url=dev.get('developer-url'),
         ) for dev in (game_data['developers'] if game_data.
                       get('developers', None) is not None else [])
     ],
     image=game_data['image'],
     background_color=game_data['background-color'],
     marketing_blurb=game_data['marketing-blurb'],
 )
Beispiel #15
0
    ------------------------------------------------------------------------------------

    Για την εποθήκευση των λέξεων, όπως φαίνεται και στη κλάση WordMaster που περιγράφηκε πορηγουμένως,
    χρησιμοποιούμε δομή dictionary (που υλοποιείται με hashtable) για να έχουμε πρόσβαση σε O(1) πολυπλοκότητα.
    Έτσι, οι αλγόριθμοί μας, είναι αποδοτικοί και εκετούλαι σε πραγματικό χρόνο.

    ------------------------------------------------------------------------------------

    Υλοποιήσαμε το Σενάριο 1 και Σενάριο 2 για τον αλγόριθμο του Υπολογιστή.
    Τα σενάρια δεν υλοποιήθηκαν εντελώς μη επικαλυπτόμενα. Για παράδειγμα, για την υλοποίηση του
    SMART-FAIL χρησιμοποιήθηκε η ήδη υλοποιημένη μέθοδος SMART, που φτιάχτηκε και το Σενάριο 1.

    ------------------------------------------------------------------------------------

    Σχόλια συνοδεύουν τη κάθε κλάση και μέθοδο.

    ------------------------------------------------------------------------------------

    Τα αρχεια ειναι τα:
    "main30903289.py" που περιλαμβάνει το κύριο πρόγραμμα ,
    "classes.py" που περιλαμβάνει τις κλάσεις της εργασίας και
    "greek7.txt" που περιέχει τις λέξεις της ελληνικής γλώσσας που έχουν μέχρι και 7 γράμματα.
    -- Το αρχείο "stats.json" φτιάχνεται με την πρώτη εκτέλση του κώδικα, γι αυτό δεν παραδόθηκε.
    """
    pass


if __name__ == '__main__':
    game = Game()
    game.menu()
Beispiel #16
0
    def run(self):
        database = Database(DATABASE_DETAILS)
        aram_files_path = GAMES_FOLDERS_PATH + self.player_region
        num_games_to_get = 99

        time_check = time.time()
        checking_period = 3600

        keep_running = True
        m = Misc()
        player_count = 0
        checked_players_games = dict()
        second_step = Second_step(self.player_region)
        player_population = database.get_row_count(self.player_region +
                                                   "_players_checked")
        processing_unit = player_population / MAX_THREAD_NUM
        start_position = int(
            round(processing_unit * (self.threadID % MAX_THREAD_NUM)))
        end_position = int(round(start_position + processing_unit - 1))
        if self.threadID % MAX_THREAD_NUM == MAX_THREAD_NUM - 1:
            end_position = player_population
        while True:
            for one_player in list(
                    database.get_all_items(
                        self.player_region + "_players_checked",
                        "id"))[start_position:end_position]:
                self.lock[self.threadID].acquire()
                if keep_running == True:
                    patch_date = Static(API_KEY).get_patch_date()
                    player_id = str(one_player)
                    #print player_id
                    player = Player(self.player_region,
                                    API_KEY,
                                    account_id=player_id)

                    # Check if player already exists in players table. If not, add them.
                    ##        m.logging(self.player_region, "Checking player: " + str(player_id), "log")
                    database.insert_items(self.player_region + "_summoners",
                                          "id", player_id)

                    # Get the timestamp of the last checked game
                    current_last_game_epoch = database.get_database_item(
                        self.player_region + "_summoners", "id", player_id,
                        "last_game_epoch")
                    if current_last_game_epoch < patch_date:
                        current_last_game_epoch = patch_date

                    recent_games = player.get_games(current_last_game_epoch,
                                                    count=num_games_to_get)

                    if player.total_games == 0:
                        self.lock[self.threadID].release()
                        continue

                    if recent_games == -2:
                        m.logging(
                            self.player_region, "Removing " + str(player_id) +
                            " from " + self.player_region + "_summoners and " +
                            self.player_region + "_players_checked", "log")
                        database.delete_line(self.player_region + "_summoners",
                                             "id", player_id)
                        database.delete_line(
                            self.player_region + "_players_checked", "id",
                            player_id)
                        self.lock[self.threadID].release()
                        continue

                    database.update_numberof_games(
                        self.player_region + "_summoners", "id", player_id,
                        "total_games", player.total_games)

                    # If the player has played new games since the last check, update the overall number of games and the time of the last played game.
                    if not current_last_game_epoch == player.date_last_game:
                        database.update_fields(
                            self.player_region + "_summoners", "id", player_id,
                            {"last_game_epoch": player.date_last_game})

            ##            m.logging(self.player_region, "Player " + str(player_id) + " played new games since last check", "log" )

            ##        else:
            ##            m.logging(self.player_region, "Player " + str(player_id) + " Didn't play any new games since last check", "log")

            # If the games are ARAM games, update the table with new number of aram games and the new percentage of played aram games.
                    if player.aram_games is not 0:
                        database.update_numberof_games(
                            self.player_region + "_summoners", "id", player_id,
                            "aram_games", player.aram_games)

                    #if not database.get_database_item(self.player_region + "_summoners", "id", player_id, "total_games") == 0:
                    aram_percentage = (float(
                        database.get_database_item(
                            self.player_region + "_summoners", "id", player_id,
                            "aram_games")) / float(
                                database.get_database_item(
                                    self.player_region + "_summoners", "id",
                                    player_id, "total_games"))) * 100
                    database.update_fields(
                        self.player_region + "_summoners", "id", player_id,
                        {"aram_games_percentage": aram_percentage})
                    # If new ARAM games were played since last check, update the games file for this player with the new games data
                    games = []
                    if not player.aram_games == 0:

                        ##            m.logging(self.player_region, "Updating " + player_id + "'s file with recent ARAM games", "log" )
                        player_file = os.path.join(aram_files_path, player_id)
                        with open(player_file, 'a') as player_history:
                            for game_id in recent_games:
                                if database.insert_items(
                                        self.player_region + "_games",
                                        "id, summoner, date",
                                        game_id + " , " + player_id + " , " +
                                        recent_games[game_id]) == 1:
                                    games.append(game_id)
                                    game = Game(game_id, self.player_region,
                                                API_KEY)
                                    try:
                                        json.dump(game.game_details(),
                                                  player_history)
                                        player_history.write("\n")
                                    except ValueError:
                                        m.logging(
                                            self.player_region,
                                            "Error while saving games " +
                                            game_id + " for " + player_id,
                                            "error")
                                        self.lock[self.threadID].release()
                                        continue

            ##        else:
            ##            m.logging(self.player_region, player_id + " did not play any ARAM games recently", "log")

                    m.logging(
                        self.player_region, self.player_region + "- Thread: " +
                        str(self.threadID) + ", Player: " + str(player_id) +
                        ", All: " + str(player.total_games) + ", ARAM: " +
                        str(player.aram_games), "log")

                    if games:
                        checked_players_games[player_id] = games
                    player_count += 1
                    self.lock[self.threadID].release()

                    if player_count % 2 == 0:
                        if checked_players_games:
                            self.lock[self.threadID].acquire()
                            second_step.update_tables(checked_players_games)
                            self.lock[self.threadID].release()
                            checked_players_games = dict()
                            if time.time() - time_check >= checking_period:
                                time_check = time.time()
                                with open(STATIC_DATA_PATH + "End_Exec",
                                          "r") as end_check:
                                    for line in end_check.readlines():
                                        if line.strip() == "True":
                                            m.logging(
                                                self.player_region,
                                                str(self.threadID) +
                                                ": End of execution was requested. This thread will exit now",
                                                "log")
                                            print str(
                                                self.threadID
                                            ) + ": End of execution was requested. This thread will now exit."
                                            keep_running = False

                else:
                    database.close_db()
                    return

            m.logging(self.player_region, "End of loop reached. Restarting..",
                      "log")
Beispiel #17
0
def main():
    p1 = Player()
    p2 = Player()
    game = Game(p1, p2)
    import pdb
    pdb.set_trace()
Beispiel #18
0
class Main:
    def __init__(self):
        self._game = Game()
        self._window = Window(self._game)
        self._character = self._game.character
        self._window.draw()

        self.n = 0
        self.ifHasFailed = False

    def reset(self):
        self._game.reset()
        self._window = Window(self._game)
        self._character = self._game.character
        self._window.draw()

        self.n = 0
        self.ifHasFailed = False

    def start(self):
        global expectedResult
        global nr
        nr += 1
        if nr == 21:
            stopGame()

        self._codes = expectedResult[f"{nr}"]
        print(f"Initial codes: {self._codes}\n")
        if self._codes == -1:
            # missing start or stop
            self._window.draw()
            return

        elif self._codes == -2:
            # missing condition
            self._window.draw()
            return

        for codeList in self._codes:
            self.function(codeList)
            self._game.update()
            if self._game.run == True:
                self._window.draw()
            else:
                self._window.draw()
                break

        main()

    def function(self, codeList):
        self._game.update()
        self._window.draw()
        if self._game.run == False:
            return

        code = codeList[0]
        if type(code) is list:
            code = code[0]

        self.n += 1
        # print(f"\nFrame {self.n}")
        # print(f"List: {codeList}")
        # print(f"Code: {code}")

        if code == 87:
            # Move forward
            self._character.moveForward()
            self.ifHasFailed = False

        elif code == 79:
            # Turn right
            self._character.turnRight()
            self.ifHasFailed = False

        elif code == 61:
            # Turn left
            self._character.turnLeft()
            self.ifHasFailed = False

        elif code == 47:
            # Start whileloop
            # print(f"Cond: {codeList[1]}")
            while self.condition(codeList[1]):
                for codeSubList in codeList[2]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            self.ifHasFailed = False

        elif code == 59:
            # Start if-statement
            # print(f"Cond: {codeList[1]}")
            if self.condition(codeList[1]):
                self.ifHasFailed = False
                for codeSubList in codeList[2]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            else:
                self.ifHasFailed = True

        elif code == 103:
            # Start else-statement
            if self.ifHasFailed:
                for codeSubList in codeList[1]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            self.ifHasFailed = False

        self._game.update()
        if self._game.run == True:
            self._window.draw()
        else:
            self._window.draw()
            main()

    def condition(self, code):
        if code == 109:
            cond = self._character.pathAhead()
        elif code == 121:
            cond = self._character.notFinished()
        elif code == 117:
            cond = self._character.pathRight()
        elif code == 121:
            cond = self._character.pathLeft()
        # print(cond)
        return cond

    @property
    def game(self):
        return self._game

    @property
    def character(self):
        return self._character

    @property
    def window(self):
        return self._window
Beispiel #19
0
startitems = [
    "Full Bottle of Dirty Water", "Full Bottle of Clean Water",
    "Full Bottle of Clean Water", "Energy Bar", "Bandage", "Walking Stick",
    "Match", "Match", "Match", "Tea Leaves", "Cooking Set", "Silver", "Silver",
    "Silver", "Clothing"
]
randomstarting1 = [
    "Magnesium Fire Starter", "Warming Pack", "Sleeping Bag", "Axe", "Torch",
    "Fishing Rod"
]
randomstarting2 = [
    "Batteries", "Vaseline", "Hygiene Kit", "String", "Camp Set",
    "Fishing Bait"
]

game = Game(SCENES, all_items, startitems, randomstarting1, randomstarting2)


#functions
def Custom_Input():
    return input(colors.gray + ">>> " + colors.stopcolor).strip().lower()


def GenerateRandomScene():
    #randomly pick a scene, a starting item from each of 2 unique starting item lists, and an integer distance to home in [150km through 200km]
    global startitems
    global randomstarting1
    global randomstarting2
    scene = random.choice(SCENES)
    startitems.append(random.choice(randomstarting1))
    startitems.append(random.choice(randomstarting2))
from classes import Deck, Player, Game

eggbert = Player("Eggbert", Deck())
cpu = Player("Cpu", Deck())

game = Game(eggbert, cpu)

game.start()
 def __init__(self):
     self.game = ga.Game()
Beispiel #22
0
class Main:
    """
    Class: Handels game-logic and runs the game, a new instance of Main is a new game, new map etc.
    """
    def __init__(self):
        self._game = Game()
        self._window = Window(self._game)
        self._character = self._game.character
        self._window.draw()

        self.ifHasFailed = False

    def reset(self):
        """
        Function: Resets the state of game but the map remains the same.
        """
        self._game.reset()
        self._window = Window(self._game)
        self._character = self._game.character
        self._window.draw()

        self.ifHasFailed = False

    def start(self):
        """
        Function: Gets codes from webcam, starts game and runs until game is finished or character has bumped into a wall.
        """
        self._codes = getCodes.get_codes()

        if self._codes == -1:
            # missing start or stop
            self._window.draw()
            return

        elif self._codes == -2:
            # missing condition
            self._window.draw()
            return

        for codeList in self._codes:
            self.function(codeList)
            self._game.update()
            if self._game.run == True:
                self._window.draw()
            else:
                self._window.draw()
                break

        main()

    def function(self, codeList):
        """
        Function: args codeList, from current list of codes (codeList) get the current functionality.
        In this game it is:

        while - 47,
        if - 59,
        else - 103,
        pathAhead - 109,
        pathLeft - 115,
        pathRight - 117,
        notFinished - 121,
        forward - 87,
        turnLeft - 61,
        turnRight - 79
        """
        self._game.update()
        self._window.draw()
        if self._game.run == False:
            return

        code = codeList[0]
        if type(code) is list:
            code = code[0]

        if code == 87:
            # Move forward
            self._character.move_forward()
            self.ifHasFailed = False

        elif code == 79:
            # Turn right
            self._character.turn_right()
            self.ifHasFailed = False

        elif code == 61:
            # Turn left
            self._character.turn_left()
            self.ifHasFailed = False

        elif code == 47:
            # Start whileloop
            while self.condition(codeList[1]):
                for codeSubList in codeList[2]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            self.ifHasFailed = False

        elif code == 59:
            # Start if-statement
            if self.condition(codeList[1]):
                self.ifHasFailed = False
                for codeSubList in codeList[2]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            else:
                self.ifHasFailed = True

        elif code == 103:
            # Start else-statement
            if self.ifHasFailed:
                for codeSubList in codeList[1]:
                    self._game.update()
                    if self._game.run == True:
                        self._window.draw()
                        self.function(codeSubList)
                    else:
                        self._window.draw()
                        main()
            self.ifHasFailed = False

        self._game.update()
        if self._game.run == True:
            self._window.draw()
        else:
            self._window.draw()
            main()

    def condition(self, code):
        """
        Function: args code, from given code representing a statement, checks if that statement is true or not and returns either True or False.
        In this game it is:

        pathAhead - 109,
        pathLeft - 115,
        pathRight - 117,
        notFinished - 121
        """
        if code == 109:
            cond = self._character.path_ahead()
        elif code == 121:
            cond = self._character.not_finished()
        elif code == 117:
            cond = self._character.path_right()
        elif code == 121:
            cond = self._character.path_left()
        return cond

    @property
    def game(self):
        """
        Function: game getter
        """
        return self._game

    @property
    def character(self):
        """
        Function: character getter
        """
        return self._character

    @property
    def window(self):
        """
        Function: window getter
        """
        return self._window
Beispiel #23
0
a_teams = set([t[2] for t in all_games_tuples])
teams = h_teams.union(a_teams)

team_objects = [Team(country=t) for t in teams]

session.add_all(team_objects)
session.commit()

all_game_objects = []
all_stats = []
for game in all_games:
    h_team = session.query(Team).filter(
        Team.country == game['home_team_statistics']['country']).one()
    a_team = session.query(Team).filter(
        Team.country == game['away_team_statistics']['country']).one()
    game_object = Game(venue=game['venue'], winner=game['winner'])
    all_game_objects.append(game_object)

    h_name = game['home_team']['country']
    a_name = game['away_team']['country']
    h_goals = game['home_team']['goals']
    h_ball_possession = game['home_team_statistics']['ball_possession']
    a_goals = game['away_team']['goals']
    a_ball_possession = game['away_team_statistics']['ball_possession']
    h_distance_covered = game['home_team_statistics']['distance_covered']
    a_distance_covered = game['away_team_statistics']['distance_covered']
    h_pass_accuracy = game['home_team_statistics']['pass_accuracy']
    a_pass_accuracy = game['away_team_statistics']['pass_accuracy']
    h_on_target = game['home_team_statistics']['on_target']
    a_on_target = game['away_team_statistics']['on_target']
import time

from pymysql.cursors import DictCursor
from classes import TelegramBot, Menu, MainMenu, Game, Booking, Information, Newsletter
from random import shuffle
from telebot import *
from multiprocessing.context import Process

telegram_bot = TelegramBot()
menu_bot = Menu()
main_menu_bot = MainMenu()
booking_bot = Booking()
information_bot = Information()
newsletter = Newsletter()

game_bot = Game()
qNum = 0
correct_answer = ''
question = ''
score = 0
isGame = False
isBooking = False

bot = telegram_bot.bot
booking_date, date_time, free_tables, questions = (0, 0, [], 0)


@bot.message_handler(commands=['start'])
def handle_start_help(message):
    main_menu_bot.start(message.chat.id, bot, telegram_bot.connection)
Beispiel #25
0
def main():
    current_game = Game()
    current_game.play()
Beispiel #26
0
from random import choice
from classes import Game

command = input().split()
print('Input command: ' + ' '.join(command))
while ' '.join(command) != 'exit':
    start = False
    exit_ = False
    while not start:
        try:
            game = Game(*command)
            elements = [[' ' for j in range(3)] for i in range(3)]
            game.print_board(elements)
            start = True
        except TypeError:
            print('Bad parameters!')
            command = input().split()
            print('Input command: ' + ' '.join(command))
            if command == ['exit']:
                exit_ = True
                break
    if exit_:
        break

    player1 = game.Player('X', game.level1)
    player2 = game.Player('O', game.level2)

    while game.check_win(
            elements) == None and player1.free_cells(elements) != []:
        if player1.level == 'user':
            print('Enter the coordinates:')
Beispiel #27
0
from classes import Game
from classes.scenes.menus import MainMenu
from classes.scenes.game_scenes import LevelEditor, SquidGame

myGame = Game()

mainMenu = MainMenu(myGame, "MainMenu")

# Comment out to execute the Squid Game
mainGame = LevelEditor(myGame, "GameScene")

# Comment out to execute the Tile Editor
# mainGame = SquidGame(myGame, "GameScene")

myGame.addScene(mainMenu)
myGame.addScene(mainGame)

# myGame.setActiveScene("MainMenu")
myGame.setActiveScene("GameScene")

if __name__ == '__main__':
    while True:
        myGame.active_scene.runningLoop()
Beispiel #28
0
def init():
    global GAME
    pygame.init()
    GAME = Game()
Beispiel #29
0
import os
from classes import Player, Game

player_1_name = input()
player_2_name = input()
print("Player 1 choose your item (1 - Rock, 2 - Scissors, 3 - Paper): ",
      end='')
player_1_choice = int(input())
os.system("cls")
print("Player 2 choose your item (1 - Rock, 2 - Scissors, 3 - Paper): ",
      end='')
player_2_choice = int(input())
os.system("cls")

firstgame = Game(player_1_name, player_2_name)
firstgame.set_player_1_choice(player_1_choice)
firstgame.set_player_2_choice(player_2_choice)
firstgame.winner()
Beispiel #30
0
class Interface_GUI():
    def __del__(self):
        print("interface usuniety")
    def __init__(self, num_decks, hotseat, window, time, bet):
        self.num_decks = num_decks
        self.hotseat = hotseat
        self.time_left = time
        self.bet = bet
        self.font = pygame.font.Font("OpenSans-Regular.ttf", 25)#('Arial', 25)
        self.font_arrow = pygame.font.Font("OpenSans-Regular.ttf", 20)#pygame.font.SysFont('Arial', 20)
        self.font_color = (0, 0, 0)
        self.basic_col = (29, 59, 207)
        self.bet_col = (29, 186, 207)
        self.time_col = (29, 207, 56)
        self.grey = (192, 192, 192)
        self.width_rect = 100
        self.height_rect = 50
        self.width_card = 80
        self.center_x = int((width_w - self.width_rect) / 2)
        self.dist = 50
        self.can_click = False
        self.load_it = 0

        self.y = height_w - self.dist - self.height_rect;
        self.x_start = int((width_w - 5 * self.width_rect - 4 * self.dist)/2)
        self.x_hit = self.x_start
        self.x_stand = self.x_start + self.dist + self.width_rect
        self.x_double = self.x_start + 2*(self.dist + self.width_rect)
        self.x_split = self.x_start + 3*(self.dist + self.width_rect)
        self.x_insure = self.x_start + 4*(self.dist + self.width_rect)

        self.button_back = pygame.Rect(self.dist, self.dist, self.width_rect+50, self.height_rect)
        self.button_hit = pygame.Rect(self.x_hit, self.y, self.width_rect, self.height_rect)
        self.button_stand = pygame.Rect(self.x_stand, self.y, self.width_rect, self.height_rect)
        self.button_double = pygame.Rect(self.x_double, self.y, self.width_rect, self.height_rect)
        self.button_split = pygame.Rect(self.x_split, self.y, self.width_rect, self.height_rect)
        self.button_time = pygame.Rect(950-self.dist-self.width_rect, self.dist, self.width_rect+50, self.height_rect)
        self.button_insure = pygame.Rect(self.x_insure, self.y, self.width_rect, self.height_rect)
        self.button_bet = pygame.Rect(self.x_double, self.y - self.dist - self.height_rect, self.width_rect, self.height_rect)
        self.button_player = pygame.Rect(self.x_double, self.y - self.dist - 2*self.height_rect, self.width_rect, self.height_rect)
#        self.cards = Cards(self.num_decks)
        self.it_x = 0
        self.it_y = 0
        self.odslon = False
        self.in_split = False
        self.game = Game()
#        self.deck = Deck()
        self.game.first_round()
        self.game.first_turn()
        print(self.game)
        self.current_player = 0
        self.split_bust = [-1,-1,-1,-1,-1,-1,-1,-1]



    def draw(self, window):
        if self.can_click:
            self.basic_col = (29, 59, 207)
        else:
            self.basic_col = (192, 192, 192)
        hit_col = self.basic_col
        stand_col = self.basic_col
        #print(self.current_player)
        if len(self.game.pllst[self.current_player].hands_nt) == 0:
            double_col = self.grey
            split_col = self.grey
            insure_col = self.grey
        else:
            if self.game.pllst[self.current_player].hands_nt[0].can_DD(): double_col = self.basic_col
            else: double_col = self.grey
            if self.game.pllst[self.current_player].hands_nt[0].can_split():
                split_col = self.basic_col
            else: split_col = self.grey
            #print(can_insure(self.game.dealer))                     ##############################
            if self.game.pllst[self.current_player].hands_nt[0].can_insure(self.game.dealer):
                insure_col = self.basic_col          #do zmiany
            else:
                insure_col = self.grey

        if self.load_it > 1:
            pygame.draw.rect(window, hit_col, self.button_back)
            text_back = self.font.render("Undo move", True, self.font_color)
            window.blit(text_back, center_text(text_back, self.button_back))

        pygame.draw.rect(window, hit_col, self.button_hit)
        pygame.draw.rect(window, stand_col, self.button_stand)
        pygame.draw.rect(window, double_col, self.button_double)
        pygame.draw.rect(window, split_col, self.button_split)
        pygame.draw.rect(window, insure_col, self.button_insure)
        pygame.draw.rect(window, self.bet_col, self.button_bet)

        text_hit = self.font.render("Hit", True, self.font_color)
        text_stand = self.font.render("Stand", True, self.font_color)
        text_double = self.font.render("Double", True, self.font_color)
        text_split = self.font.render("Split", True, self.font_color)
        text_insure = self.font.render("Insure", True, self.font_color)
        text_bet = self.font.render(str(self.bet) + "$", True, self.font_color)
        text_player = self.font.render(self.game.pllst[self.current_player].name, True, self.font_color)

        if self.time_left <= 0:
            text_time = self.font.render("0 s left", True, self.font_color)
        else:
            text_time = self.font.render(f"{self.time_left:.2f} s left", True, self.font_color)

        if self.hotseat:
            pygame.draw.rect(window, self.time_col, self.button_time)
            window.blit(text_time, center_text(text_time, self.button_time))
        window.blit(text_hit, center_text(text_hit, self.button_hit))
        window.blit(text_stand, center_text(text_stand, self.button_stand))
        window.blit(text_double, center_text(text_double, self.button_double))
        window.blit(text_split, center_text(text_split, self.button_split))
        window.blit(text_insure, center_text(text_insure, self.button_insure))
        window.blit(text_bet, center_text(text_bet, self.button_bet))
        window.blit(text_player, center_text(text_player, self.button_player))
        #print("d")
        #pygame.display.flip()
        #self.update_cards(window)#false

    def check_all_buttons(self, pos, window):
        
        if self.can_click:
            self.basic_col = (29, 59, 207)
            print(self.load_it)
            if self.load_it > 1 and self.click(self.button_back, pos[0], pos[1]):
                print("undo")
                return "undo"



            elif self.click(self.button_hit, pos[0], pos[1]):
                print("Hit")
                # if self.cards.in_split:
                #     self.cards.hit_split()
                # else:
                self.game.pllst[self.current_player].hit(self.game.pllst[self.current_player].hands_nt[0], self.game.draw)
                    #busted = self.cards.hit()
                    #if busted:
                        #self.update_cards(window)
                        #self.cards.odslon = True
                        #print('test')
                        #menu_kon = Menu_kon(0, 1, window)
                        #return ("end_busted", menu_kon)
                return "hit"
                
            elif self.click(self.button_stand, pos[0], pos[1]):
                print("Stand")
                self.game.pllst[self.current_player].stand(self.game.pllst[self.current_player].hands_nt[0])
                #else:
                #krupier = self.cards.krupier()
                #self.cards.odslon = True
                #self.update_cards(window) ####################
                #menu_kon = Menu_kon(krupier[0], krupier[1], window)
                #return ("end", )#menu_kon)
            elif self.game.pllst[self.current_player].hands_nt[0].can_split() and self.click(self.button_split, pos[0], pos[1]):
                print("Split")
                self.game.pllst[self.current_player].split(self.game.pllst[self.current_player].hands_nt[0])
                print(self.game)
            elif self.game.pllst[self.current_player].hands_nt[0].can_DD() and self.click(self.button_double, pos[0], pos[1]):
                print("Double")
                self.game.pllst[self.current_player].DD(self.game.pllst[self.current_player].hands_nt[0],  self.game.draw)
            elif self.game.pllst[self.current_player].hands_nt[0].can_insure(self.game.dealer) and self.click(self.button_insure, pos[0], pos[1]):
                print("insure")
                self.game.pllst[self.current_player].insure(self.game.pllst[self.current_player].hands_nt[0])
            else:
                return "nothing_clicked"
        else:
            return "nothing_clicked"
            self.basic_col = (192, 192,192)
        #self.update_cards(window)
        return ("", "")


    def click(self, button, x, y):
        if button.x < x < button.x + button.w and button.y < y < button.y + button.h:
            return True

    def update_cards(self, window, it):
        self.game.pllst[self.current_player].choice_processing_functions()
        self.can_click = False
        x_0 = 0
        split = len(self.game.pllst[self.current_player].hands_nt) + len(
            self.game.pllst[self.current_player].hands_busted) + len(
            self.game.pllst[self.current_player].hands_stand) == 2
        if split and len(self.game.pllst[self.current_player].hands_nt) == 1:
            self.split_bust[self.current_player] = self.game.pllst[self.current_player].hands_busted
        #print(self.game.pllst[self.current_player].hands_nt[0].cards)
        if split:
            if len(self.game.pllst[self.current_player].hands_nt) == 0:
                if self.split_bust[self.current_player]:
                    talia = self.game.pllst[self.current_player].hands_busted[0].cards
                else:
                    talia = self.game.pllst[self.current_player].hands_stand[0].cards
            elif len(self.game.pllst[self.current_player].hands_nt) == 1:
                if self.split_bust[self.current_player]:
                    talia = self.game.pllst[self.current_player].hands_busted[0].cards
                else:
                    talia = self.game.pllst[self.current_player].hands_stand[0].cards
            else:
                talia = self.game.pllst[self.current_player].hands_nt[0].cards
        elif len(self.game.pllst[self.current_player].hands_busted) == 1:
            talia = self.game.pllst[self.current_player].hands_busted[0].cards
        elif len(self.game.pllst[self.current_player].hands_nt) == 1:
            talia = self.game.pllst[self.current_player].hands_nt[0].cards
        else:
            talia = self.game.pllst[self.current_player].hands_stand[0].cards
        while x_0 < len(talia) and x_0 <it:
            x = talia[x_0]
            #print(x)
            if split and len(self.game.pllst[self.current_player].hands_nt) == 1:
                nazwa_pliku = "Karty/Czarnobiale/" +x[0] + "-" + x[2] + "_g.png"
            else:nazwa_pliku = "Karty/" +x[0] + "-" + x[2] + ".png"
            #nazwa_pliku = x[0] + "_" + x[2] + ".png"
            #print(nazwa_pliku)
            img = pygame.image.load(nazwa_pliku)
            if split:
                x_start = 665
                window.blit(img,
                            (int(600 + (((x_0 + 1) * 2) - 1) * 300 / (len(talia) * 2) - 0.5 * self.width_card),
                             270))
            else:
                x_start = 425
                window.blit(img,
                            (int(200 + (((x_0 + 1) * 2) - 1) * 600 / (len(talia) * 2) - 0.5 * self.width_card),
                             270))

            #window.blit(img, (x_start + (x_0 * 80), 350 ))
            if self.it_x == x_0:
                #pygame.time.wait(1000)
                self.it_x += 1
            #pygame.display.update(0, self.y/2, width_w, self.y/2)
            x_0 += 1

        s_0 = 0

        if len(self.game.pllst[self.current_player].hands_nt) == 2:
            cards_split = self.game.pllst[self.current_player].hands_nt[1].cards
        elif split:
            if len(self.game.pllst[self.current_player].hands_nt) == 1:
                cards_split = self.game.pllst[self.current_player].hands_nt[0].cards
            elif len(self.game.pllst[self.current_player].hands_busted) == 2:
                cards_split = self.game.pllst[self.current_player].hands_busted[1].cards
            elif len(self.game.pllst[self.current_player].hands_stand) == 2:
                cards_split = self.game.pllst[self.current_player].hands_stand[1].cards
            elif self.split_bust[self.current_player]:
                cards_split = self.game.pllst[self.current_player].hands_stand[1].cards
        else:
            cards_split = []


        while s_0 < len(cards_split) and s_0 + x_0 < it:    ##################
            x = cards_split[s_0]
            # print(it)
            if len(self.game.pllst[self.current_player].hands_nt) == 2:
                nazwa_pliku = "Karty/Czarnobiale/" +x[0] + "-" + x[2] + "_g.png"
            else:
                nazwa_pliku = "Karty/" +x[0] + "-" + x[2] + ".png"
            # print(nazwa_pliku)
            img = pygame.image.load(nazwa_pliku)

            window.blit(img,
                        (int(100 + (((s_0 + 1) * 2) - 1) * 300 / (len(cards_split) * 2) - 0.5 * self.width_card), 270))
            #window.blit(img, (170 + (s_0 * 80), 350))
            # if self.it_x == x_0:
            # pygame.time.wait(1000)
            #   self.it_x += 1
            # pygame.display.update(0, self.y/2, width_w, self.y/2)
            s_0 += 1

            #print(x)
        #print("")
        #pygame.time.wait(1000)
        y_0 = 0
        len_dealer = len(self.game.dealer.hand.cards)
        while y_0 < len_dealer and s_0 + y_0 + x_0 <it:
            y = self.game.dealer.hand.cards[y_0]
            nazwa_pliku = "Karty/" + y[0] + "-" + y[2] + ".png"
            #print(nazwa_pliku)
            if not self.odslon and len(self.game.dealer.hand.cards) == 2 and y_0 == 1:
                window.blit(pygame.image.load("Karty/tyl.png"), (int(100 + (((y_0+1)*2)-1)*800/(len_dealer*2)-0.5*self.width_card), 50))
                #window.blit(pygame.image.load("tyl.png"), (425 + (y_0 * 80), 100))
            else:
                #window.blit(pygame.image.load(nazwa_pliku), (425 + (y_0 * 80), 100))
                window.blit(pygame.image.load(nazwa_pliku), (int(100 +(((y_0+1)*2)-1) * 800 / (len_dealer * 2) - 0.5 * self.width_card), 50))
            if self.it_y == y_0:
                #pygame.time.wait(1000)
                #print("xd")
                self.it_y += 1
            #pygame.display.update(0, 0, width_w, self.y/2)
            y_0 += 1
        #print(self.cards.talia_krupiera)



        if y_0 == len(self.game.dealer.hand.cards):
            self.can_click = True