|
Post by bplus on May 20, 2023 11:50:51 GMT -5
_Title "Playing for Charity: 100 dice" ' b+ 2023-05-20 ' A game that no one loses! Randomize Timer Dim As Long roll, Charity, me, r For roll = 1 To 100 r = Int(Rnd * 6) + 1 Print " Roll number:"; roll; "is"; r If r < 5 Then Charity = Charity + r Else me = me + r Print: Print " I get 5's and 6's:"; me Print " Charity gets 1, 2, 3, 4's:"; Charity Print: Print " zzz... press any to continue" Print Sleep Next Print: Print " Treat "; If me > Charity Then Print "yourself"; Else Print "Others"; Print " specially well today."
|
|
|
Post by bplus on May 20, 2023 13:57:43 GMT -5
Well this IS Friends Of Basic, so the really Friendly thing to do is comment my code as much as I can to help Beginners get started with QB64.
So here is the same output result much more fully commented:
' The following not in original code but a very good habit to get into, it will save you ' from your typos. 3P = Proper Programming Practice :) Option _Explicit ' This forces you to Dim (or ReDim) your variables before you use them. ' !!! EXCEPTION !!! should you do something like DEFINT A-Z or DEFLNG A-Z then everything ' is automatically. :O
' If the following is in the first lines of your program and you go to save it, QB64 IDE ' will suggest your _Title string for your .bas file name when starting from File > New. _Title "Playing for Charity: 100 dice" ' b+ 2023-05-20 < 3P author and date with _Title. ' A game that no one loses! < 3P a quick summary or comments. I usually list versions here.
Randomize Timer ' this is here so I don't play the same game over on each run.
' Dim As Long roll, Charity, me, r < 3P originally I had this, but really strong 3P is ' declaring all your variables first 2nd part of Option _Explicit team. Dim As Long roll ' this tracks the For loop index eg roll number Dim As Long r ' this is for random to be used to store the dice roll value. Dim As Long Charity ' variable to store running total points for Charity Dim As Long me ' variable to store running total points for me. ' I am using Long because I want Integers and Long is easier to type and doesn't take more ' time than Integer Type. So I get a range of over 32,000 with 0 cost.
For roll = 1 To 100 ' the main loop does 100 rolls
r = Int(Rnd * 6) + 1 ' Rnd = 0 to .9999 Multiply by 6 and have 0 to 5.9999 ' Take Int(0 to 5.99999) get 0,1,2,3,4,5 ' Add 1 for 1 to 6 ' ' Print something; < with semi colon ending keeps the print head right where it stops. ' Print something, < with comma tabs the print head right to set column widths ' Print something < nothing after literals or variables moves print head to next line. ' Print will automatically start on next line if can't finish print job on current one. ' Print: < finishes last print line or starts new one by inserting blank line. Print " Roll number:"; roll; "is"; r ' this first line reporting roll number and roll.
If r < 5 Then Charity = Charity + r Else me = me + r ' this decides if me or Charity ' gets the rolled points
' This reports the running scores and tells Sleep is activated so we have to press a key ' to continue game. Print: Print " I get 5's and 6's:"; me Print " Charity gets 1, 2, 3, 4's:"; Charity Print: Print " zzz... press any to continue" Print Sleep Next ' end of 100 rolls loop onto summary result.
Print: Print " Treat "; If me > Charity Then Print "yourself"; Else Print "Others"; Print " specially well today." ' the End < 3P if you had GoSubs after this End put an End statement here.
|
|
|
Post by charliejv on May 21, 2023 8:53:44 GMT -5
_Title "Playing for Charity: 100 dice" ' b+ 2023-05-20 ' A game that no one loses! Randomize Timer Dim As Long roll, Charity, me, r For roll = 1 To 100 r = Int(Rnd * 6) + 1 Print " Roll number:"; roll; "is"; r If r < 5 Then Charity = Charity + r Else me = me + r Print: Print " I get 5's and 6's:"; me Print " Charity gets 1, 2, 3, 4's:"; Charity Print: Print " zzz... press any to continue" Print Sleep Next Print: Print " Treat "; If me > Charity Then Print "yourself"; Else Print "Others"; Print " specially well today." I'm really enjoying this for some odd reason.
|
|
|
Post by bplus on May 21, 2023 12:33:36 GMT -5
Good! Hey Charlie I am following your Font/Custom Character work, most interesting thing going on at forums at moment. I am extremely tempted to drag out and finish my 8x16 Custom Char Editor and even more tempted to drag out my old TileMaker stuff from which my current avatar comes, tiled 4xs and scaled up a bit.
|
|
|
Post by charliejv on May 21, 2023 23:05:32 GMT -5
I'm kind of cheating, building a character editor in TiddlyWiki script. Can you blame me? Took me all of 30 minutes !
|
|
|
Post by bplus on May 22, 2023 9:36:53 GMT -5
Oh! Just saw something at JB and have idea for hugely simpler process for Char Editor, stay tuned...
Update: Eh, changed my mind, sorry.
|
|