Exemple #1
0
    def save_players(self):
        old_players = f.read_players()
        new_players = self.players

        for plr in new_players:
            for update_me in old_players:
                if plr.name == update_me.name:
                    update_me.balance = plr.balance
                    update_me.stats = plr.stats
                    break

        f.save_players(old_players)
Exemple #2
0
    def save_players(self):
        old_players = f.read_players()
        new_players = self.players

        for plr in new_players:
            for update_me in old_players:
                if plr.name == update_me.name:
                    update_me.balance = plr.balance
                    update_me.stats = plr.stats
                    break

        f.save_players(old_players)
Exemple #3
0
def get_players_for_game(players):
    # Prepare for the same code reading _experience_ as in ui.py, except now
    # with confusing Qt GUI stuff. 

    a = ""
    if not players:
        # players = [] # Was redundant because not players already makes sure that players == []
      
        # Create player dialog
        while a == "":
            a, ok = QInputDialog.getText(None, "New Player", "Enter name for new player: ")
            if not ok: sys.exit()

        #Append created player and return
        players.append(player.Player(a))
        fops.save_players(players)

        print 
        return players
    else: 
        print "Players were found, should be a list here."
        # available_string = "Available players: " + ''.join(' ', players)
        plrs_string = ""
        for plr in players:
            plrs_string += plr.name + ', '


        while a == "":
            # Y U NOT WORK FOR ME ?!?!?
            # dlg = QInputDialog()
            # dlg.setCancelButtonText("Create New Player")
            # dlg.setOkButtonText("adsfddsadfsds")
            # dlg.setOption(QInputDialog.NoButtons)
            # dlg.repaint()
            # dlg.setTextValue(players[0].name)
            # dlg.NoButtons
            # a, choose = dlg.getText(None, "Choose player", plrs_string + "\n\n Enter player name: ")

            # This is why we can't have nice things ^

            # Dialog for getting a player name.

            duplicate_player = False # Unused for now. 
            name = ""
            while name == "":
                choose, name = get_player_name_dialog(plrs_string)

            if not choose:
                try: 
                    for plr in players:
                        if plr.name == name:
                            duplicate_player = True
                            raise Exception("Duplicate Player Exception")
                            
                except Exception: # yeahhh serious business error handling. 
                    print "Duplicate players will not be created."
                    sys.exit()    # Originally i was planning to implement 
                                  # Nice errors for cards running out and 
                # Create player   # too small bets and whatnot. 
                new_plr = player.Player(name)
                players.append(new_plr)
                fops.save_players(players)
                selected = [new_plr]
                return selected

            else:
                # Choose player
                player_found = False
                for plr in players:
                    if plr.name == name:
                        new_plr = plr
                        player_found = True
                        break
                try:
                    if not player_found: raise Exception("Player not found.")
                except Exception:
                    print "Player not found. Exiting."
                    sys.exit()

                        # Only 1 player in gui version for now
                selected = [new_plr]
                return selected

        return players
Exemple #4
0
def get_players_for_game(players):
    selected = []
    n = 0
    action = ''

    print Texts.please_select_players
    print "Available players: "
#    pdb.set_trace()
    print_player_list(players)


    # caution: bad code incoming: hard to read nesting & too long method
    # there has to be a better way to do this

    while (len(selected) < 4 and action != 'n'):
        name = str(raw_input(Texts.player_name_prompt))

        action = ''
        plr_selected = False
        plr_created = False
        aux_plr = p.Player(name)


        if players == []: #copypasta code incoming
            print Texts.player_not_found

            action = str(raw_input(Texts.create_new_player_prompt))

        #    pdb.set_trace()

            if action == 'y':
                new_plr = p.Player(name)
                players.append(new_plr)
                fops.save_players(players)
                selected.append(new_plr)
                print "Player", new_plr, "created and selected."
                plr_selected = plr_created = True
                action = ''

            elif action == 'n':
                break


        for plr in players:
            if plr_selected: break

            # Check if we already added it
            for sel_plr in selected:
                if aux_plr == sel_plr:
                    print Texts.player_already_selected
                    plr_selected = True
                    break
                    # Maybe propose removal here.

            if plr_selected: break

            # Check if we can find it
            for plr in players:
                if aux_plr == plr:
                    selected.append(plr)
                    print "Player", plr, "selected."
                    plr_selected = True
                    break
            
            if plr_selected: break      

            # If couldn't find, maybe create new player.
            if not plr_selected:
                print Texts.player_not_found

                action = str(raw_input(Texts.create_new_player_prompt))

     #           pdb.set_trace()

                if action == 'y':
                    new_plr = p.Player(name)
                    players.append(new_plr)
                    fops.save_players(players)
                    selected.append(new_plr)
                    print "Player", new_plr, "created and selected."
                    plr_selected = True
               #    plr_created = True
               #    Not used anywhere
                    action = ''

                elif action == 'n':
                    break

            if plr_selected: break

        while (action != 'y' and action != 'n'):
            action = str(raw_input(Texts.more_players_prompt))


    return selected
Exemple #5
0
def get_players_for_game(players):
    selected = []
    n = 0
    action = ''

    print Texts.please_select_players
    print "Available players: "
    #    pdb.set_trace()
    print_player_list(players)

    # caution: bad code incoming: hard to read nesting & too long method
    # there has to be a better way to do this

    while (len(selected) < 4 and action != 'n'):
        name = str(raw_input(Texts.player_name_prompt))

        action = ''
        plr_selected = False
        plr_created = False
        aux_plr = p.Player(name)

        if players == []:  #copypasta code incoming
            print Texts.player_not_found

            action = str(raw_input(Texts.create_new_player_prompt))

            #    pdb.set_trace()

            if action == 'y':
                new_plr = p.Player(name)
                players.append(new_plr)
                fops.save_players(players)
                selected.append(new_plr)
                print "Player", new_plr, "created and selected."
                plr_selected = plr_created = True
                action = ''

            elif action == 'n':
                break

        for plr in players:
            if plr_selected: break

            # Check if we already added it
            for sel_plr in selected:
                if aux_plr == sel_plr:
                    print Texts.player_already_selected
                    plr_selected = True
                    break
                    # Maybe propose removal here.

            if plr_selected: break

            # Check if we can find it
            for plr in players:
                if aux_plr == plr:
                    selected.append(plr)
                    print "Player", plr, "selected."
                    plr_selected = True
                    break

            if plr_selected: break

            # If couldn't find, maybe create new player.
            if not plr_selected:
                print Texts.player_not_found

                action = str(raw_input(Texts.create_new_player_prompt))

                #           pdb.set_trace()

                if action == 'y':
                    new_plr = p.Player(name)
                    players.append(new_plr)
                    fops.save_players(players)
                    selected.append(new_plr)
                    print "Player", new_plr, "created and selected."
                    plr_selected = True
                    #    plr_created = True
                    #    Not used anywhere
                    action = ''

                elif action == 'n':
                    break

            if plr_selected: break

        while (action != 'y' and action != 'n'):
            action = str(raw_input(Texts.more_players_prompt))

    return selected