Use CherryPy add a web interface to a Python script

The newDealer Function

At the end of each hand, the deal rotates to the next player (lines 212-226). To do this, the program starts by initializing a flag nextDealer to False. Then, the program loops over all of the players and checks to see if the current iteration of the loop is the dealer. If so, the program unsets the dealer flag and sets the nextDealer flag that was initialized. The continue jumps to the next iteration of the loop.

On the next pass, the first if block will be skipped because their dealer flag will not be set (they were not the last dealer). However, nextDealer is set, so this player should become the next dealer. The program sets their dealer flag and clears the nextDealer flag. Because the next dealer has been assigned, the program breaks out of the loop.

The final lines in the newDealer function handle the special case of running off the end of the player list. Consider the situation that the last player was the previous dealer. In that case, nextDealer would get set, but the loop would have no other players to loop through. The code checks for that and, if that is the case, it runs the loop again, sets the first player's dealer flag, and breaks out of the loop.

Deal and Flop

The deal function (lines 229-232) performs the initial deal (two cards) to each player by setting up the loop and dealing. The flop function (lines 234-247) is the initial deal of three cards onto the table. After the function handles delivering the cards, it draws them on the screen. Note that the three table cards come from the same source (deck) as the deal function above.

In the next couple of lines, screenX and screenY are the initial draw coordinates of cards on the screen. Then, the screen is filled with the green background color to clear it, and a loop over the self.tableCards list calls drawCard with screenX and screenY as a tuple, with crd.suit and crd.value as its arguments. This will draw the associated card graphic on the screen. screenX then increments by 210 so that the next draw will take place one card width+10 pixels away (Figure 5, lower half). The drawPlayerStatus() function is called to redraw the player information since the screen was cleared. Then, the display flips so everything is visible (Figure 5, upper half).

Figure 5: The display with the virtual poker table. The text in the upper half is drawn by drawPlayerStatus(), and the cards are drawn by calling gfx.drawCard.

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