Skip to content

Commit

Permalink
Lay some groundwork for UNO! calling (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgw committed Jul 27, 2015
1 parent a1e0a43 commit d4e24de
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions unobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ def __init__(self, trigger):
self.deadPlayers = {}
self.playerOrder = [self.owner]
self.currentPlayer = 0
self.previousPlayer = None
self.topCard = None
self.way = 1
self.drawn = NO
self.unoCalled = NO
self.deck = []
self.startTime = None

Expand Down Expand Up @@ -221,6 +223,16 @@ def play(self, bot, trigger):
return WIN
self.show_on_turn(bot)

def call_uno(self, bot, trigger):
caller = trigger.nick
with lock:
if len(self.players[caller]) != 1:
z = [self.get_card(), self.get_card()]
self.players[caller].extend(z)
bot.notice(STRINGS['DRAWN_CARD'] % self.render_cards(z, UnoBot.get_card_theme(bot, caller)), caller)
else:
self.unoCalled = caller

def draw(self, bot, trigger):
if not self.deck:
return
Expand Down Expand Up @@ -401,6 +413,7 @@ def create_deck():

def inc_player(self):
with lock:
self.previousPlayer = self.currentPlayer
self.currentPlayer += self.way
if self.currentPlayer == len(self.players):
self.currentPlayer = 0
Expand Down Expand Up @@ -512,6 +525,11 @@ def play(self, bot, trigger):
bot.say(STRINGS['WIN'] % (winner, game_duration))
self.game_ended(bot, trigger, winner)

def call_uno(self, bot, trigger):
if trigger.sender not in self.games:
return
self.games[trigger.sender].call_uno(bot, trigger)

def draw(self, bot, trigger):
if trigger.sender not in self.games:
return
Expand Down Expand Up @@ -733,6 +751,13 @@ def unoplay(bot, trigger):
unobot.play(bot, trigger)


@module.rule('^uno!?$')
@module.priority('high')
@module.require_chanmsg
def unocalled(bot, trigger):
unobot.call_uno(bot, trigger)


@module.commands('draw')
@module.priority('high')
@module.require_chanmsg
Expand Down

0 comments on commit d4e24de

Please sign in to comment.