Back to Browse

How to create a Rolling die using python pygame library

2.0K views
May 21, 2020
11:47

This PyGame program simulates the roll of a die (or dice if you prefer). It’s a fairly simple, straightforward thing to do, though it may be worth noting that the spots display is oh-so-slightly clever. Some spots appear in more than one number, e.g. the middle spot is in all the odd numbers, hence the test if n % 2 == 1: serves to display the middle spot for 3 numbers. By the time we get down to n==6 we only have 2 more spots to display. It’s an example of DRY 🙂 Of course, this isn’t the simplest possible program that could simulate the roll of a dice; this is: However, this is a bit dull, hence we spruce it up with a graphical interface, and just to add a bit more realism, we let the dice ‘roll’ a little while. It displays a dozen faces with a small delay between each, and stops on the last. Without the delay you won’t see the faces before the last. #python #pygame #games #dice#gambling#youtuber#youtubers#youtubechannel #youtubevideo#gaming #subscribe #hiphop #explorepage #youtubechannel #twitch #facebook #memes #instagood #gamer #rap #fortnite #soundcloud #viral #art

Download

0 formats

No download links available.

How to create a Rolling die using python pygame library | NatokHD