Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,451 members, 7,958,354 topics. Date: Wednesday, 25 September 2024 at 12:57 PM |
Nairaland Forum / Science/Technology / Programming / A Dice Program (731 Views)
Help On Php Code For A Dice Game / Microcontroller Project: Make An Easy Electronic LED Dice. (2) (3) (4)
(1) (Reply)
A Dice Program by maekhel(m): 4:10am On Oct 10, 2014 |
This program is similar to the dice program except that we have added animation to the program. To add the animated effect, you need to include the timer control into your program. In the timer’s properties windows, set the timer enabled property to false and the interval to 10. You can change the interval to any number you want. Under the roll dice command, set the timer to enabled. You also need to create a subroutine and name it as roll. Under the roll subroutine, enter the code that display the different faces of the dice. To create the animated effect, you need to declare a global variable x and assign an initial value of 0 to it, then include the statement x=x+10 so that the value of x increase 10 units after an interval of 10 milliseconds. Finally, enter the statement under the timer subroutine . This code is to stop the timer. When you click the button roll dice, you will see that faces of the dice changes and then come to a stop. If x < 1000 Then roll Else Timer1.Enabled = False End If The Design Interface The Run Time Interface The code Dim x As Integer Sub roll( ) x = x + 10 Randomize Timer n = Int(1 + Rnd * 6) For i = 0 To 6 Shape1(i).Visible = False Next If n = 1 Then Shape1(3).Visible = True Shape2.FillColor = &HC0C0C0 End If If n = 2 Then Shape1(2).Visible = True Shape1(4).Visible = True Shape2.FillColor = &H8080FF End If If n = 3 Then Shape1(2).Visible = True Shape1(3).Visible = True Shape1(4).Visible = True Shape2.FillColor = &H80FF& End If If n = 4 Then Shape1(0).Visible = True Shape1(2).Visible = True Shape1(4).Visible = True Shape1(6).Visible = True Shape2.FillColor = &HFFFF00 End If If n = 5 Then Shape1(0).Visible = True Shape1(2).Visible = True Shape1(3).Visible = True Shape1(4).Visible = True Shape1(6).Visible = True Shape2.FillColor = &HFFFF& End If If n = 6 Then Shape1(0).Visible = True Shape1(1).Visible = True Shape1(2).Visible = True Shape1(4).Visible = True Shape1(5).Visible = True Shape1(6).Visible = True Shape2.FillColor = &HFF00FF End If End Sub Private Sub Command1_Click() Timer1.Enabled = True x = 0 End Sub Private Sub Timer1_Timer() If x < 1000 Then roll Else Timer1.Enabled = False End If End Sub source: http://tutorialslodge.com/animated-dice-project/ |
(1) (Reply)
Microsoft’s Javascript Engine Will Soon Support Mozilla’s Asm.js / Revolutionary Social Media Experience, Orbi; Twitter For Voice Notes Launches / The Best Ways (as A Programmer) For Avoiding A 100% Sedentary Life
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20 |