def onEntry(self): global currentPlayer p = [clients[k] for k in clients] currentPlayer = p[self.currPlayer] name = str(currentPlayer + " is up! ") broadcast(bytes(name, "utf8")) victory = make(InnerMachine(name, self.currPlayer, self.currSuit), cheatTurnSpec).run()
def playBartok(client, args): global bartokGame # if bartokGame is None and len(clients) >= 4 and len(clients) <= 9: broadcast( bytes( "\n%s has decided to start a game of Bartok!\n\n" % clients[client], "utf8")) broadcast( bytes("There are %d players playing!\n" % len(clients), "utf8")) time.sleep(.5) broadcast( bytes( "To play cards on your turn, write {play} followed by the card.\n", "utf8")) broadcast( bytes( "For example, write \"{play} H4\" to play the 4 of Hearts.\n", "utf8")) broadcast( bytes( "In order to play a card, the card must match either the rank or the suite of the displayed card.\n", "utf8")) broadcast( bytes( "If you cannot play a card, you must draw. To draw the card, write {draw}\n", "utf8")) broadcast( bytes( "To see your hand, write {hand}. To see the number of cards in each players hand, write {status}. For help, write {help}.\n", "utf8")) time.sleep(.5) unplayedDeck.fillDeck() unplayedDeck.shuffle() for p in clients: #Init players players[clients[p]] = Player(clients[p]) players[clients[p]].draw(5) # players[clients[p]].hand.cards.append(Card("S", "5")) playedDeck.addToDeck(unplayedDeck.draw()) # playedDeck.addToDeck(Card("S", "7")) for p in clients: if clients[p] != currentPlayer: showHand(p, []) bartokGame = make(OuterMachine("Welcome to the game!", len(clients)), bartokSpec) elif len(clients) < 4: client.send(bytes("Not enough players to start!\n", "utf8")) elif len(clients > 9): client.send(bytes("Too many players to start!\n", "utf8")) else: client.send(bytes("A game of bartok is currently occurring!\n", "utf8"))
def onEntry(self): global skipNextTurn global currentPlayer global nextPlayer p = [clients[k] for k in clients] currentPlayer = p[self.currPlayer] nextPlayer = p[self.currPlayer + 1 if self.currPlayer < self.model.numPlayers - 1 else 0] broadcast( bytes("\n<---------------------------------------->\n", "utf8")) if skipNextTurn: skipNextTurn = False broadcastToOthers( bytes(currentPlayer + " drew two cards and skips a turn!\n", "utf8"), currentPlayer, bytes("You draw two cards and skip a turn!\n", "utf8")) else: name = str(currentPlayer + " is up!\n") broadcastToOthers(bytes(name, "utf8"), currentPlayer, bytes("It's your turn!\n", "utf8")) make(InnerMachine(name, self.currPlayer, self.currSuit), bartokTurnSpec).run()
def playCheat(client, args): global cheatGame if cheatGame is None and len(clients) >= 3: broadcast( bytes( "%s has decided to start a game of cheat!\n" % clients[client], "utf8")) broadcast( bytes("There are %d players playing!\n" % len(clients), "utf8")) time.sleep(.5) broadcast( bytes( "To play cards on your turn, write {play} followed by the cards.\n", "utf8")) broadcast( bytes( "For example, write \"{play} H4 S4\" to play the 4 of Hearts and the 4 of Spades.\n", "utf8")) broadcast( bytes( "If you think a player played cards that aren't of the current rank, announce {cheat}\n", "utf8")) broadcast( bytes( "If they were lying, they have to pick up all the played cards... but if the weren't... you do!\n", "utf8")) broadcast( bytes("To see your hand, write {hand}. For help, write {help}.\n", "utf8")) time.sleep(.5) unplayedDeck.fillDeck() unplayedDeck.shuffle() for p in clients: #Init players players[clients[p]] = Player(clients[p]) while not unplayedDeck.isEmpty(): for p in players: if not unplayedDeck.isEmpty(): players[p].draw() for p in clients: showHand(p, []) cheatGame = make(OuterMachine("Welcome to the game!", len(clients)), cheatSpec) elif len(clients) < 3: client.send(bytes("Not enough players to start!", "utf8")) else: client.send(bytes("A game of cheat is currently occurring!", "utf8"))
def runGame(self): self.playing = True make(OuterMachine("Welcome to the game!", len(self.players), self), self.gameSpec).run()
def runTurn(self): self.currentPlayer = next(self.nextPlayer) return make( InnerMachine(self.currentPlayer.name + "\'s turn.", self.currentPlayer, self), self.turnSpec).run()