' Three dice games for the picaxe 08M. ' "Standard Dice"- Musical dice"-"Rolling dice" ' Three dice games board. ' ----------------------------------------------------------------------------------- ' power --- The led display cycles - pressing the button selects the associated game. ' on one led for game one / two leds for game two / three leds for game three ' ' game --- On a dice face of seven leds - a randomly chosen number will be shown, ' one The displayed number will change after each press of the push button. ' game --- Same as game 1 except a short tune will play each time a "six" is thrown. ' two To prevent short games - the tune will not play during the first 4 rolls. ' To stop long games - the game will end and tune will play after 12 rolls. ' game --- Same as game 2 except the tune is changed and the dice will "auto-roll" ' three stopping when a "six" is thrown - You press the push button to continue. ' also --- In all games a "beep" sound can be heard when the push button is pressed ' note and playing any sound (tune or beep) will flash two of the display leds. ' To increase battery life - the display will blank after a tune is played. '------------------------------------------------------------------------------------- game_one:'---------- "Standard dice" - (one led) press button ------ low 0: low 1: low 2: low 4 for b3 = 1 to 100 let pins = 1: b4 = 1: pause 10 if input3 = 1 then start_beep next b3 'goto game_two game_two:'---------- "Musical dice" - (two leds) press button ------ for b3 = 1 to 100 let pins = 4: b4 = 2: pause 10 if input3 = 1 then start_beep next b3 'goto game_three game_three:'-------- "Rolling dice" - (three leds) press button ------ for b3 = 1 to 100 let pins = 5: b4 = 3: pause 10 if input3 = 1 then start_beep next b3 goto game_one start_beep:'---------- add a push button beep then start the game ------ b2 = 0 sound 2,(120,25) 'goto start_game start_game:'-------- alternate ways of starting depending on the game ------ random w0: pause 10 if b4 > 1 and b2 > 12 then play_tune if b4 = 3 and b1 > 12 then auto_roll if input3 = 1 then push_button goto start_game auto_roll:'------- auto-roll in game three - pause one second between rolls ------ pause 1000 goto roll_dice push_button:'------- beep when the push button is released - then roll the dice ------ pause 10 if b4 = 4 then: b4 = 3: endif if input3 <> 0 then push_button sound 2,(120,25) 'goto roll_dice roll_dice:'--------- one chance to play a tune or five to show a new dice number ------ b2 = b2 + 1 if b1 > 210 then dice_one if b1 > 168 then dice_two if b1 > 126 then dice_three if b1 > 84 then dice_four if b1 > 42 then dice_five 'if b1 <= 42 then play_tune play_tune:'--------- check if the tune can be played otherwise show dice six ------ let pins = 22 if b4 = 1 or b2 <= 4 then dice_six if b4 = 2 then tune_batman if b4 = 3 then tune_pgunn tune_batman:'---------- Batman - played during game two "Musical dice"------ tune 0,5,($6A,$6A,$69,$69,$6A,$6A,$6B,$6B,$6A,$6A,$69,$69,$6A,$6A,$2B,$6C,$2B) let pins = 0: b2 = 0 goto start_game tune_pgunn:'-------- Peter Gunn - played during game three "Rolling dice"------ tune 0,8,($66,$64,$67,$64,$69,$67,$64,$64,$66,$64,$67,$64,$69,$67,$A4,$21,$EC) let pins = 0: b2 = 0: b4 = 4 goto start_game dice_one:'---------- show the current dice number on the led display ------ let pins = 1 goto start_game dice_two: let pins = 16 goto start_game ' How the led display relates to the picaxe outputs dice_three: let pins = 17 ' display number = outputs goto start_game ' ------------------------------------------------------ ' 4 1 one = 0 dice_four: ' two = 4 let pins = 18 ' 2 0 2 three = 4 + 0 goto start_game ' four = 4 + 1 ' 1 4 five = 4 + 1 + 0 dice_five: ' six = 4 + 1 + 2 let pins = 19 ' ------------------------------------------------------ goto start_game dice_six: let pins = 22 goto start_game ' "Three dice games" '----------------------------------------------------------------------------- ' b1 = random number b1 = nnn between 0 and 255 ' b2 = roll counter b2 <= 4 dont play tune / b2 > 12 play the tune ' b3 = game loop b3 = 100 loop 100 times ' b4 = game type b4 = 1 game 1 select / b4 = 3 game 3 auto-roll ' b4 = 2 game 2 select / b4 = 4 game 3 push button '----------------------------------------------------------------------------- ' tunes suitable for these games '----------------------------------------------------------------------------- ' Tunes came from the picaxe web site but were shortend to suit this program. ' With two tunes loaded the picaxe reports only three bytes of spare memory . ' There are many other tunes on the web site if you want to choose your own. '----------------------------------------------------------------------------- 'Batman 'tune 0,5,($6A,$6A,$69,$69,$6A,$6A,$6B,$6B,$6A,$6A,$69,$69,$6A,$6A,$2B,$6C,$2B) 'Peter Gunn 'tune 0,8,($66,$64,$67,$64,$69,$67,$64,$64,$66,$64,$67,$64,$69,$67,$A4,$21,$EC) 'Looney Tunes Theme 'tune 0,5,($44,$42,$40,$42,$44,$43,$44,$40,$42,$42,$42,$C2,$42,$40,$6B,$40,$42) 'Star Wars 'tune 0,5,($65,$65,$EA,$C5,$43,$40,$8A,$C5,$43,$42,$40,$8A,$C5,$42,$43,$80) 'Muppets 'tune 0,5,($2C,$24,$24,$27,$25,$64,$25,$40,$60,$62,$24,$64,$64,$6C,$64,$27) 'Who Let The Dogs Out 'tune 0,6,($2C,$6C,$62,$6C,$60,$64,$6C,$64,$62,$60,$60,$67,$60,$67,$60,$2C,$6C) 'Black Adder 'tune 0,4,($62,$6C,$67,$6C,$6B,$6C,$01,$69,$6C,$40,$6C,$6B,$6C,$69,$6C,$67,$6C) 'George Of The Jungle 'tune 0,3,($4C,$25,$25,$4C,$25,$29,$4C,$00,$4C,$25,$4C,$25,$4C,$27,$27,$4C,$29) 'Adams Family Theme 'tune 0,5,($05,$49,$05,$40,$2B,$07,$45,$04,$47,$04,$64,$29,$05,$40,$05,$49,$05) 'Indiana Jones 'tune 0,3,($6C,$65,$67,$6C,$C0,$6C,$22,$6C,$64,$A5,$2C,$27,$6C,$69,$6B,$6C,$C5)