Games Roll the dice - 6 dice, 6 colors - lets roll...

PaulMeuris

Active Member
Licensed User
In the Google Play store you can find some apps that let you roll dice.
Most of them have advertising or in-app purchases. So really not good for children to use.
With this app you can choose how many dice you want to use (from 1 to 6).
Each player can choose his/her own color (6 colors: blue, green, red, white, yellow and orange).
Each time you change the number of dice or the color the dice are rolled (random length of the roll from 5 to 20 tries).
The mixed color setting assigns a random color (from the 6) to each die. Each time you choose this setting the colors change.
Where do you find this app? Via this link: Roll_The_Dice
Happy coding!
 

PaulMeuris

Active Member
Licensed User
EDIT: it's not really needed but you could clear the result label when the roll starts.
It gives some extra feedback to the user that a roll is in progress.
B4X:
Private Sub btnroll_Click
    Private tries As Int = Rnd(5,21)
    btnroll.Enabled = False
    lblresult.Text = ""
Happy coding!
 

PaulMeuris

Active Member
Licensed User
If you want to use this app on a tablet you could do with some screen adjustments.
In the subroutine Class_Globals add the following declaration:
B4X:
Private dicesize As Int
In the subroutine B4XPage_Created below the B4XPages.SetTitle:
B4X:
    ' screen adjustments
    Dim screensize As Double = GetDeviceLayoutValues.ApproximateScreenSize
    Dim devwidth As Int = GetDeviceLayoutValues.Width/2
    Dim devheight As Int = (GetDeviceLayoutValues.height/2) - 40dip
    If screensize > 8 Then
        Dim devwidth As Int = GetDeviceLayoutValues.Width
        Dim devheight As Int = GetDeviceLayoutValues.height - 80dip
        dicesize = DipToCurrent(devwidth/4)
        pnlmain.Height = DipToCurrent(devheight/2.5)
        pnlsettings.SetLayout(10dip,pnlmain.Height + 10dip,devwidth-20dip,pnlsettings.Height)
        lblresult.SetLayout(DipToCurrent(devwidth/3)-50dip,pnlmain.Height+pnlsettings.Height+20dip,400dip,60dip)
        btnroll.SetLayout(DipToCurrent(devwidth/3),pnlmain.Height+pnlsettings.Height+100dip,300dip,300dip)
    Else
        dicesize = DipToCurrent(devwidth/4)
    End If
    Log("devwidth: " & devwidth)
    Log("devheight: " & devheight)
    Log("dicesize: " & dicesize)
    '
The variable dicesize replaces the 80dip values:
B4X:
    DiceRect.Initialize(5dip,5dip,dicesize,dicesize)

Private Sub show_panels(numpnls As Int, rolls() As Int)
    pnlmain.RemoveAllViews
    Private left As Int = 20dip
    Private top As Int  = 15dip
    For i = 1 To numpnls
        Private pnl As Panel
        pnl.Initialize("pnl")
        pnlmain.AddView(pnl,left,top,dicesize,dicesize)
        show_roll(pnl,rolls(i-1))
        If i Mod 3 = 0 Then
            left = 20dip
            top = top + dicesize + 10dip
        Else
            left = left + dicesize + 10dip
        End If
    Next
End Sub
I have tested the adjustments on a Samsung Galaxy Tab E, 9.6 inch, Android 4.4.4
Note: you can adjust the dividers when needed.
Happy coding!
 

PaulMeuris

Active Member
Licensed User
If you like to have a "dicepad" on your laptop then the B4J version is something for you.
You can download this B4J version via this link: Roll_The_Dice_B4J
The window size from the "dicepad" is width 325 and height 450.
With the menu item Project / Build Standalone Package you can make an *.exe file of the project.
Happy coding!
 
Top