Use CherryPy add a web interface to a Python script

The drawPlayerStatus Function

This function (lines 186-201) is similar to drawPlayers discussed earlier in the gfx class section. It starts by clearing the player information area by drawing a green box over it.

Next, it sets up a loop to run over all of the players. Each subsequent pair of lines works to render a piece of player information. The first line creates a text surface by rendering from one of the fonts set up when I initialized pygame.font and a property of the current instance of the player class. The next line checks to see whether the player has folded; if so, then the message "FOLDED" is displayed instead of the bet. Finally, the display flips so everything is visible.

The newPlayer Function

When a player joins through the web interface, the nickname they provide gets passed to the newPlayer function (lines 203-208), which is where they get set up in the actual game. The player is added to the internal players dictionary (self.players); their nickname is the key. Then, player() creates an instance of the player class, and the player's nickname is set in the newly created class. If a player is the first to join, he or she is the initial dealer. Once the player is successfully added, drawPlayers is called to display the updated player list on the game's main display.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content