Index: bunco.py ================================================================== --- bunco.py +++ bunco.py @@ -4,10 +4,12 @@ teammate_lookup = { 0: 2, 1: 3, 2: 0, 3: 1 } fuzzydie_holder = 'x' +table_move_callback = None + def TurnInProgress(): return -1 def roll_dice(): dice = [] @@ -14,12 +16,13 @@ for _ in range(3): dice.append(random.randint(1,6)) return dice class Player: - def __init__(self, name, dex, math, speed): + def __init__(self, name, phone, dex, math, speed): self.name = name + self.smsnumber = phone self.dex = dex self.math_comprehension = math self.roll_speed = speed self.max_streak = 0 self.round_bunco_counts = [0] @@ -271,11 +274,11 @@ players = [] with open(filename) as tsvfile: tsvreader = csv.reader(tsvfile) for line in tsvreader: - players.append(Player(line[0],0,0,0)) + players.append(Player(line[0],line[1],0,0,0)) return players class Game: cur_tick = 1 @@ -351,19 +354,28 @@ def prep_next_round(self): # losers from head table move to next table headtable_losers = self.tables[0].losers() log_table_move(headtable_losers, "lost", self.tables[0], self.tables[1]) + if callable(table_move_callback): + for player in headtable_losers: + table_move_callback(player, "lost", self.tables[0], self.tables[1]) round_winners = self.tables[1].swap_for_winners(headtable_losers) # winners from other tables move to next table for n in range(2, len(self.tables)): log_table_move(round_winners, "won", self.tables[n-1], self.tables[n]) + if callable(table_move_callback): + for player in round_winners: + table_move_callback(player, "won", self.tables[n-1], self.tables[n]) round_winners = self.tables[n].swap_for_winners(round_winners) # last set of winners moves to head table log_table_move(round_winners, "won", self.tables[-1], self.tables[0]) + if callable(table_move_callback): + for player in round_winners: + table_move_callback(player, "won", self.tables[-1], self.tables[0]) self.tables[0].swap_for_losers(round_winners) for table in self.tables: table.prep_new_round() Index: bunco_app.py ================================================================== --- bunco_app.py +++ bunco_app.py @@ -1,19 +1,33 @@ import bunco import xlsxwriter +import creds # local from blessings import Terminal +from twilio.rest import Client t = Terminal() g = bunco.Game("players.csv") +enable_sms = False +last_status = 'Off to a great start!' + def plural(str,n,suffix="s"): return str + suffix if n > 1 else str def print_center(before, string, after): col = int((t.width - len(string)) / 2) - 1 print(f"{t.move_x(col)}{before}{string}{after}") +def status(text): + global last_status + row = 6 + (len(g.tables) * 5) + print(t.move(row, 0), end='') + print(t.clear_eol, end='') + print_center(f"{t.bold_green}",f"[ {text} ]", t.normal) + print(t.clear_eos) + last_status = text + def display_dashboard(): print(t.clear,t.move(0,0)) print_center(t.bold_red,"B U N C O S I M U L A T O R", t.normal) print(f"{t.red}{'-'*t.width}{t.normal}\n") @@ -31,22 +45,32 @@ print(f"{t.move_x(3)}{t.cyan}{player}{t.normal}",end='') for n in range(g.current_round()): print(t.move_x(18+(4*n)),end='') print(str(player.round_scores[n]).rjust(4),end='') print('') - -g.play_one_round() -display_dashboard() + status(last_status) def do1(): - g.prep_next_round() g.play_one_round() + if enable_sms: + status("Sending results by SMS to players…") + for player in g.players: + sms(player.smsnumber, summary_text(player)) + display_dashboard() + status("Prepping for next round…") + g.prep_next_round() + status("Ready for another round!") def summary(n): return summary_text(g.players[n]) +def sms(number, message): + if enable_sms and number: + cli = Client(creds.SID, creds.token) + cli.messages.create(to=number, from_=creds.sender, body=message) + def summary_text(player): for table in g.tables: if player in table.players: curtable = table break @@ -69,10 +93,17 @@ f"You made {player.round_roll_counts[g.current_round()-1]} rolls,", f"adding {player.personal_roll_scores[g.current_round()-1]} pts{buncos}", f"to your team score of {player.round_scores[g.current_round()-1]},", f"{winloss} {foe_names}’s score of {sitch['opponent_score']}."] return " ".join(ts) + +def sms_table_move(player, wonlost, table_from, table_to): + if player.smsnumber: + message = f"Having {wonlost} the last round, you move from {table_from} to {table_to}." + sms(player.smsnumber, message) + +bunco.table_move_callback = sms_table_move def excel_sheet(title): wb = xlsxwriter.Workbook('bunco.xlsx') ws = wb.add_worksheet('Overview') style = {}