Author Topic: David H. Ahl BULLSEYE (Dart Game) Revisited :-)  (Read 8508 times)

0 Members and 1 Guest are viewing this topic.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« on: November 08, 2021, 06:02:57 pm »
Got rid of some of the spaghetti code..
Mod it, enjoy it. have fun. Im working on a fantasy game that has an inn/bar I might include this as part of the games available there
the utils is for the pause,
you might have to make a inkey$ or look on the forum somewhere, I think my uttils.bi is here. if not I'll post it

original code
https://www.atariarchives.org/basicgames/showpage.php?page=34

Code: QB64: [Select]
  1.  
  2.  
  3. Type tPlayer
  4.     score As Long
  5.  
  6.  
  7.  
  8. Dim As Integer i, j, k ' loop vars
  9.  
  10. Dim score As Integer
  11. Dim Shared calcThrow As Double
  12. Dim Shared oppScore As Integer
  13. Dim Shared throw(3, 5) As Double '      3 types of throws 5 results
  14. Dim Shared player As tPlayer
  15.  
  16.  
  17. THROW_DATA:
  18. Data .65,.55,.5,.5
  19. Data .99,.77,.43,.01
  20. Data .95,.75,.45,.05
  21.  
  22.  
  23. initDartGame
  24.     For i = 1 To 2
  25.  
  26.         Cls
  27.         Print "Player Score    : "; player.score
  28.         Print "Opponent Score  : "; oppScore
  29.         Print
  30.  
  31.  
  32.         '// PLAYER TURN
  33.         If i = 1 Then
  34.             Print "Throw Type", "Description", , "Probable Score"
  35.             Print 1, "Fast Overarm", , "Bullseye or Complete Miss!"
  36.             Print 2, "Controlled Overarm", , "10, 20 or 30pts"
  37.             Print 3, "Frustration Throw", , "Anything! LOL"
  38.  
  39.             Print
  40.  
  41.             Input "Throw Type: "; throwId
  42.  
  43.         Else
  44.             j = r(3)
  45.             Select Case j
  46.                 Case 1: Print "Opponent does an Fast overarm!"
  47.                 Case 2: Print "Opponent tries a controlled overarm"
  48.                 Case 3: Print "Opponent just tosses the dart"
  49.             End Select
  50.         End If
  51.  
  52.         If i = 2 Then throwId = j
  53.  
  54.         Select Case throwId
  55.  
  56.             Case 1 TO 3
  57.                 calcThrow = Rnd(1)
  58.                 miss = 1
  59.                 If miss And calcThrow >= throw(throwId, 1) Then Print "BULLSEYE!!!  40 points": score = 40: miss = 0
  60.                 If miss And calcThrow >= throw(throwId, 2) Then Print "30 point zone": score = 30: miss = 0
  61.                 If miss And calcThrow >= throw(throwId, 3) Then Print "20 point zone": score = 20: miss = 0
  62.                 If miss And calcThrow >= throw(throwId, 4) Then Print "Whew 10 point zone": score = 10: miss = 0
  63.                 If miss Then Print "OOPS!! Wallshot!!! Zero Points!!!"
  64.  
  65.             Case Else
  66.                 Print "Wild throw - score 0"
  67.  
  68.         End Select
  69.  
  70.         Print
  71.         P_AUSE
  72.         If i = 1 Then player.score = player.score + score
  73.         If i = 2 Then oppScore = oppScore + score
  74.  
  75.     Next
  76.  
  77. Loop While player.score < 200 And oppScore < 200
  78.  
  79. If player.score >= 200 Then
  80.     Print "We have a winner"
  81.     Print "Aww too bad. house wins!!"
  82.  
  83.  
  84.  
  85. '$include: 'utils.bi'
  86.  
  87. Sub P_AUSE
  88.     'PAUSE (y, cntr As Integer, DARK As String, MED As String, LIGHT As String, HILITE As String)
  89.     PAUSE 24, 1, "8", "7", "!", "0"
  90.     Color 7
  91.  
  92.  
  93. Sub initDartGame
  94.     Dim i As Integer
  95.  
  96.     Restore THROW_DATA
  97.     For i = 1 To 3
  98.         Read throw(i, 1): Read throw(i, 2): Read throw(i, 3): Read throw(i, 4)
  99.     Next
  100.     player.score = 0
  101.  
  102.  
  103. '// shorthand numbergen
  104.     r = Int(Rnd * num) + 1


utils.bi

Code: QB64: [Select]
  1. Sub number_format (num As Double, flt As Integer)
  2.     Dim number As String '                                              stores whole number(w/o dec) minus "."
  3.     Dim convert As String '                                             stores the orginal number in string format
  4.     Dim I As Integer '                                                  i=loop counter delimeter counter
  5.     Dim tpl As String '                                                 .. using template
  6.  
  7.     convert = Str$(num) '                                               convert it all to a strig
  8.     If Right$(convert, 1) <> "." Then convert = convert + "." '         weird fix for lower numbers
  9.     number = Left$(convert, InStr(convert, ".") - 1) '                  store the integer
  10.     number = RTrim$(LTrim$(number)) '                                   trim it up
  11.  
  12.     tpl = "" '                                                          create a template string for USING
  13.  
  14.     For I = 1 To Len(number): tpl = tpl + "#": Next '                   add a hash per digit per integer digit
  15.     tpl = tpl + "," '                                                   set the comma tag
  16.     If flt > 0 Then '                                                   is the decimal count set?
  17.         tpl = tpl + "." '                                               add the decimal tag
  18.         For I = 1 To flt: tpl = tpl + "#": Next '                       how many places (as per dec)
  19.     End If
  20.     '    PRINT "tpl for "; num
  21.     '    PRINT tpl
  22.     Print Using tpl; num; '                                              now PRINT USING should look cleaner
  23.  
  24.  
  25.  
  26. '// MANY GRID GAME DIST CALCULATOR
  27. Function DIST (x1 As Integer, y1 As Integer, z1 As Integer, x2 As Integer, y2 As Integer, z2 As Integer)
  28.     '3D Distance Calc Pathag Theorym
  29.     DIST = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2)
  30.  
  31.  
  32.  
  33.  
  34. '// DETERMINE IF STRING IS A INTEGER/DOUBLE OR NOT
  35. Function IS_NUMBER (NUM As String) ' returns 1 if string is an integer, 0 if not
  36.     If LTrim$(RTrim$(Str$(Val(NUM$)))) = LTrim$(RTrim$(NUM$)) Then
  37.         IS_NUMBER = 1
  38.     Else
  39.         IS_NUMBER = 0
  40.     End If
  41.  
  42.  
  43. Function GET_OPTION$ (OPTION_STR As String)
  44.     '@option_str = list of characters (can be separated by comma) as only option to seelect from
  45.  
  46.     Dim OPT As String
  47.     OPTION_STR = " " + OPTION_STR 'The space in the INSTR instruction and the > 1 are there as otherwise the loop would exit on the first pass.
  48.     Do
  49.         OPT = UCase$(InKey$)
  50.     Loop Until InStr(UCase$(OPTION_STR), OPT) > 1 And OPT <> ","
  51.     GET_OPTION = OPT
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. '//==========================================================================================================================
  59. '// --- THESE ARE LEGACY FUNCTIONS USE AT OWN DISCRECTION
  60. '//==========================================================================================================================
  61.  
  62. '// DEC(X) -1 TO X
  63. '// INC(X) +1 TO X
  64. '// DISTANCE: DISTANCE BETWEEN 2 X,Y COORDS
  65. '// yesNo (default AS STRING)
  66.  
  67.  
  68. Function TODAYS_DATE$
  69.     Dim month As String, day As String, year As String, moon As String
  70.     Dim m, d, y As Integer
  71.  
  72.  
  73.     month$ = Left$(Date$, 2): m = Val(month$)
  74.     day$ = Mid$(Date$, 4, 2): d = Val(day$)
  75.     day$ = Str$(d) ' eliminate any leading zeros
  76.     year$ = Right$(Date$, 4): y = Val(year$)
  77.     Select Case m
  78.         Case 1: moon$ = "January"
  79.         Case 2: moon$ = "February"
  80.         Case 3: moon$ = "March"
  81.         Case 4: moon$ = "April"
  82.         Case 5: moon$ = "May"
  83.         Case 6: moon$ = "June"
  84.         Case 7: moon$ = "July"
  85.         Case 8: moon$ = "August"
  86.         Case 9: moon$ = "September"
  87.         Case 10: moon$ = "October"
  88.         Case 11: moon$ = "November"
  89.         Case 12: moon$ = "December"
  90.     End Select
  91.     TODAYS_DATE = WeekDay$(m, d, y) + ", " + moon$ + day$ + ", " + year$ + Space$(10)
  92.  
  93.  
  94. Function WeekDay$ (M, D, Y)
  95.     Dim C, Y As Integer
  96.     Dim S1, S2, S3 As Integer
  97.     Dim WKDAY As Integer
  98.     Dim Day As String
  99.  
  100.  
  101.     If M < 3 Then M = M + 12: Y = Y - 1 'add 12 to Jan - Feb month, -1 year
  102.     C = Y \ 100: Y = Y Mod 100 'split century and year number
  103.     S1 = (C \ 4) - (2 * C) - 1 'century leap
  104.     S2 = (5 * Y) \ 4 '4 year leap
  105.     S3 = 26 * (M + 1) \ 10 'days in months
  106.     WKDAY = (S1 + S2 + S3 + D) Mod 7 'weekday total remainder
  107.     If WKDAY < 0 Then WKDAY = WKDAY + 7 'Adjust negative results to 0 to 6
  108.     Select Case WKDAY
  109.         Case 0: Day$ = "Sunday"
  110.         Case 1: Day$ = "Monday"
  111.         Case 2: Day$ = "Tuesday"
  112.         Case 3: Day$ = "Wednesday"
  113.         Case 4: Day$ = "Thursday"
  114.         Case 5: Day$ = "Friday"
  115.         Case 6: Day$ = "Saturday"
  116.     End Select
  117.     WeekDay$ = Day$
  118.  
  119.  
  120.     '============================================================================
  121.     '--- PASCAL FUNCTION: DECREASES X BY 1)
  122.     '============================================================================
  123.     X = X - 1
  124.     DEC = X
  125.  
  126.     '============================================================================
  127.     '--- PASCAL FUNCTION: INCREASE X BY 1)
  128.     '============================================================================
  129.     X = X + 1
  130.     INC = X
  131.  
  132.  
  133. Function DISTANCE (X1, Y1, X2, Y2 As Integer)
  134.     '============================================================================
  135.     '--- DIST BETWEEN 2 POINTS
  136.     '============================================================================
  137.     DISTANCE = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2)
  138.  
  139.  
  140. Function yesNo (default As String)
  141.     '// @default = when ENTER is pressed what will be the default answer
  142.  
  143.     Dim ans As String
  144.  
  145.     Do
  146.         ans = InKey$
  147.         ans = LCase$(ans)
  148.     Loop Until ans = "y" Or ans = "n" Or ans = Chr$(13) Or ans = ""
  149.  
  150.     If ans = Chr$(13) Or ans = "" Then ans = default
  151.  
  152.     If ans = "y" Then
  153.         yesNo = 1
  154.     Else
  155.         yesNo = 0
  156.     End If
  157.  
  158.  
  159. Function COUNT_TAGS (TEXT As String)
  160.     '//
  161.     '// RETURNS THE NUMBER OF LORD TAGS IN A STRING
  162.     '//
  163.     Dim I As Integer
  164.     If Len(TEXT) = 0 Then COUNT_TAGS = 0
  165.     Dim COUNT As Integer
  166.     Dim LENGTH As Integer
  167.     LENGTH = Len(TEXT)
  168.     COUNT = 0
  169.  
  170.     For I = 1 To LENGTH
  171.         If Mid$(TEXT, I, 1) = "`" Then COUNT = COUNT + 1
  172.  
  173.     Next
  174.     COUNT_TAGS = COUNT
  175.  
  176.  
  177.  
  178.  
  179. Sub CENTER (text As String, row As Integer)
  180.     '//
  181.     '// CENTER TEXT AS A SPECIFIED ROW
  182.     '//
  183.     Dim textLen, col As Integer
  184.     Dim TAGS As Integer
  185.  
  186.     If InStr(text, "`") >= 1 Then ' There is a tag
  187.  
  188.         TAGS = COUNT_TAGS(text) * 2
  189.         textLen = Int((Len(text) - TAGS) / 2)
  190.     Else
  191.         textLen = Int(Len(text) / 2)
  192.  
  193.     End If
  194.  
  195.     col = 40 - textLen
  196.     Locate row, col
  197.     If TAGS > 0 Then
  198.         LWRITE text
  199.     Else
  200.         Print text
  201.     End If
  202.  
  203.  
  204.  
  205. Sub LWRITE (TXT As String)
  206.     Dim i As Integer
  207.     '======================================================
  208.     '--- THIS IS A POPULAR COLOR ROUTINE BASED ON THE
  209.     '--- SETH ABLE L.O.R.D. BBS GAME COLOR FORMATTING
  210.     '=====================================================
  211.     Color 7 ' DEFAULT COLOR
  212.     For i = 1 To Len(TXT$)
  213.         ' CHECK FOR A COLOR CHANGE
  214.         If Mid$(TXT$, i, 1) = "`" Then
  215.             i = i + 1
  216.             Select Case Mid$(TXT, i, 1)
  217.                 Case "0": Color 10
  218.                 Case "1": Color 1
  219.                 Case "2": Color 2
  220.                 Case "3": Color 3
  221.                 Case "4": Color 4
  222.                 Case "5": Color 5
  223.                 Case "6": Color 6
  224.                 Case "7": Color 7
  225.                 Case "8": Color 8
  226.                 Case "9": Color 9
  227.                 Case "!": Color 11
  228.                 Case "@": Color 12
  229.                 Case "#": Color 13
  230.                 Case "$": Color 14
  231.                 Case "%": Color 15
  232.                 Case "n": Print '           new line
  233.                 Case "t": Print , ; '       TAB
  234.             End Select
  235.             i = i + 1
  236.  
  237.         End If
  238.         Print Mid$(TXT$, i, 1);
  239.     Next
  240.     Print ;
  241.  
  242. Sub LWRITELN (TXT As String)
  243.     LWRITE (TXT$)
  244.     Print
  245.  
  246. Sub EXPLODE (HAYSTACK As String, NEEDLE As String, EXPLODED_ARY() As String)
  247.     '//
  248.     '// speical thanks to SPRIGGYSPRIG for his inspiration to make this sub.
  249.     '// https://www.qb64.org/forum/index.php?topic=3721.0
  250.     '// USAGE
  251.     '//     EXPLODE DELIMITED STRING, DELIMETER, ARRAY TO RETURN
  252.     '//    EXAMPLE:  EXPLODE CONSOLE.Extentions, CHR$(32), SPLIT_EXT()
  253.     '//
  254.  
  255.     Dim CNT As Integer
  256.     Dim i As Integer
  257.     HAYSTACK = _Trim$(HAYSTACK)
  258.  
  259.     CNT = 1
  260.     For i = 1 To Len(HAYSTACK)
  261.         If Mid$(HAYSTACK, i, 1) <> NEEDLE Then
  262.             EXPLODED_ARY(CNT) = EXPLODED_ARY(CNT) + Mid$(HAYSTACK, i, 1)
  263.         Else
  264.             CNT = CNT + 1
  265.         End If
  266.     Next
  267.  
  268.  
  269. 'Sub EXPLODE (SplitMeString As String, delim As String, loadMeArray() As String)
  270. '        Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  271. '        curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  272. '        dpos = InStr(curpos, SplitMeString, delim)
  273. '        Do Until dpos = 0
  274. '                loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  275. '                arrpos = arrpos + 1
  276. '                If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  277. '                curpos = dpos + LD
  278. '                dpos = InStr(curpos, SplitMeString, delim)
  279. '        Loop
  280. '        loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  281. '        ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  282. 'End Sub
  283.  
  284.  
  285.  
  286.  
  287. Sub HEADER (TXT As String, Y As Integer)
  288.     CENTER "`8 --`2------------=`0=`%[ " + TXT + " `%]=`0= `2------------`8-- ", Y
  289.     Print
  290.  
  291. Sub HR '                                        HR
  292.     LWRITELN ("`8 -  --`3------------------=`!=`%*`!=`3------------------`8--  - ")
  293.  
  294. Sub PAUSE (y, cntr As Integer, DARK As String, MED As String, LIGHT As String, HILITE As String)
  295.     'y              = y coord to place it
  296.     'dark           = dark color
  297.     'med            = medium color
  298.     'light          = light color
  299.     'center pause?  = 1(yes), 0(mo)
  300.  
  301.     Dim SPIN(10) As String '    spiner tiles
  302.     Dim k As String '           dummy string to check for user input
  303.     Dim x As Integer '          spin array counter
  304.  
  305.     SPIN(1) = "*": SPIN(2) = "/": SPIN(3) = "-"
  306.     SPIN(4) = "\": SPIN(5) = "|": SPIN(6) = "/"
  307.     SPIN(7) = "-": SPIN(8) = "\": SPIN(9) = "|"
  308.  
  309.     x = 2
  310.     Do
  311.         '// IF NOT CENTERED
  312.         If cntr = 0 Then
  313.             Locate 24, 1
  314.             LWRITE "`" + DARK + "--`" + MED + "------------=`" + LIGHT + "=`" + HILITE + "[ " + SPIN(x) + " `" + HILITE + "]=`" + LIGHT + "= `" + MED + "------------`" + DARK + "-- "
  315.         Else
  316.  
  317.  
  318.             CENTER "`" + DARK + "--`" + MED + "------------=`" + LIGHT + "=`" + HILITE + "[ " + SPIN(x) + " `" + HILITE + "]=`" + LIGHT + "= `" + MED + "------------`" + DARK + "-- ", y
  319.         End If
  320.  
  321.         '// ANIMATE SPINNER
  322.         x = x + 1: If x > 9 Then x = 2
  323.         k = InKey$
  324.         _Delay (.10)
  325.     Loop Until k > ""
  326.  
  327.  

« Last Edit: November 08, 2021, 06:08:40 pm by xra7en »
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #1 on: November 09, 2021, 07:40:04 am »
I still have the original book... So cool...
Logic is the beginning of wisdom.

Offline xra7en

  • Seasoned Forum Regular
  • Posts: 284
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #2 on: November 09, 2021, 02:15:15 pm »
keep in they're worth about $600+ LOL I know I got rid of all mine a long time ago (dumb i know LOL)
I did, however, buy all the Tim hartnell "Creating adventure games on your computer" LOL super rare

But I use these to practice a computer language, by converting the spaghetti code LOL!!
I just like re-writing old DOS book games into modern QB64 code - weird hobby, I know!

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #3 on: November 09, 2021, 06:18:03 pm »
Ah. The dreaded line numbers and the 'gotos' that jump all around the program... Conversion for me was a nightmare... lol

My copy of "The Book" is not in very good condition... "Dog ears"; Pen doodles and notes... I basically (no pun intended) collect PDF's of Basic books. Hartnell is a favourite. I have tried scanning the pages and using OCR to convert to a text file was too labourious. Spent so much time correcting scan errors I coud have keyed in the listing... Gotta love those old programs...
Logic is the beginning of wisdom.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #4 on: November 09, 2021, 07:25:40 pm »
So a wall shot for the computer is worth 30 points!?
cause that's what just happened, computer had 40points(2- 20 hits) then had a wall shot when I pressed space its points went to 70!
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #5 on: November 09, 2021, 09:11:55 pm »
Yeah the game had some rough edges, so I gave it a shot:
Code: QB64: [Select]
  1. _Title "BULLSEYE!" 'b+ 2021-11-09
  2.  
  3. Dim tt_X_p(1 To 3, 1 To 4) ' Throw Type X Probability
  4. tt_X_p(1, 1) = .65: tt_X_p(1, 2) = .55: tt_X_p(1, 3) = .5: tt_X_p(1, 4) = .5 ' sum = 2.2
  5. '              35           10                  5                   0     50
  6. tt_X_p(2, 1) = .99: tt_X_p(2, 2) = .77: tt_X_p(2, 3) = .43: tt_X_p(2, 4) = .01 ' sum = 2.2
  7. '               1           27                 34                  42      1
  8. tt_X_p(3, 1) = .95: tt_X_p(3, 2) = .75: tt_X_p(3, 3) = .45: tt_X_p(3, 4) = .05 ' sum =  2.2
  9. '               5           20                 30                  40      5
  10. '       bulls 40pts        30pts             20pts                10pts     nada!
  11.  
  12.     Cls
  13.     Print: Print
  14.     cp "*** Bulls Eye! ***"
  15.     Print
  16.     cp "AI's Score is " + ts$(Scores(0))
  17.     cp "Your Score is " + ts$(Scores(1))
  18.     Print
  19.     cp "Throw Type:      Description:          Probable Score:      "
  20.     cp "      1          Fast Overarm     Bullseye or Complete Miss!"
  21.     cp "      2       Controlled Overarm       10, 20 or 30 pts     "
  22.     cp "      3        Frustration Throw        Anything! LOL       "
  23.     If turn Then
  24.         Print
  25.         cp "Human, press Throw Type number 1, 2 or 3"
  26.         t = 0
  27.         While t <> 1 And t <> 2 And t <> 3
  28.             k$ = InKey$
  29.             t = Val(k$)
  30.         Wend
  31.         cp ts$(t)
  32.     Else
  33.         t = Int(Rnd * 3) + 1
  34.         Print
  35.         cp "AI is choosing Throw Type: " + ts$(t)
  36.     End If
  37.     luck = Rnd: score = 0
  38.     If luck >= tt_X_p(t, 1) Then cp "BULLSEYE!!!  40 points": score = 40: GoTo 1
  39.     If luck >= tt_X_p(t, 2) Then cp "Hit 30 point zone": score = 30: GoTo 1
  40.     If luck >= tt_X_p(t, 3) Then cp "Hit 20 point zone": score = 20: GoTo 1
  41.     If luck >= tt_X_p(t, 4) Then cp "Whew, Hit 10 point zone": score = 10: GoTo 1
  42.     cp "OOPS!! Wallshot!!! Zero Points!!!"
  43.    1 Scores(turn) = Scores(turn) + score
  44.     Print: Print
  45.     cp "OK    press any... zzz"
  46.     Sleep
  47.     If turn Then 'both players shot their round
  48.         If Scores(0) > Scores(1) And Scores(0) >= 200 Then winner$ = "AI"
  49.         If Scores(1) > Scores(0) And Scores(1) >= 200 Then winner$ = "Human"
  50.         If Scores(0) = Scores(1) And Scores(0) >= 200 Then winner$ = "Tie"
  51.     End If
  52.     turn = (turn + 1) Mod 2
  53. Loop Until winner$ <> ""
  54. cp "AI's Score is " + ts$(Scores(0))
  55. cp "Your Score is " + ts$(Scores(1))
  56. cp "Game goes to " + winner$ + "."
  57.  
  58. Sub cp (s$)
  59.     Print Spc((80 - Len(s$)) / 2); s$
  60.  
  61. Function ts$ (num)
  62.     ts$ = _Trim$(Str$(num))
  63.  

I do like the little gizmo thing going on in xra7en's bottom line.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #6 on: November 09, 2021, 11:00:07 pm »
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #7 on: November 09, 2021, 11:06:39 pm »
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol

Actually that's what got me started, imagining some simple graphics.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #8 on: November 10, 2021, 01:08:57 am »
Some graphics help
Code: QB64: [Select]
  1. _Title "BULLSEYE! v2" 'b+ 2021-11-09
  2. Const Xmax = 640, Ymax = 400
  3. Dim tt_X_p(1 To 3, 1 To 4) ' Throw Type X Probability
  4. tt_X_p(1, 1) = .65: tt_X_p(1, 2) = .55: tt_X_p(1, 3) = .5: tt_X_p(1, 4) = .5 ' sum = 2.2
  5. '              35           10                  5                   0     50
  6. tt_X_p(2, 1) = .99: tt_X_p(2, 2) = .77: tt_X_p(2, 3) = .43: tt_X_p(2, 4) = .01 ' sum = 2.2
  7. '               1           27                 34                  42      1
  8. tt_X_p(3, 1) = .95: tt_X_p(3, 2) = .75: tt_X_p(3, 3) = .45: tt_X_p(3, 4) = .05 ' sum =  2.2
  9. '               5           20                 30                  40      5
  10. '       bulls 40pts        30pts             20pts                10pts     nada!
  11. Dim Shared aix(1 To 100), aiy(1 To 100), hx(1 To 100), hy(1 To 100), rounds, turn
  12. Screen _NewImage(Xmax, Ymax, 12)
  13. _ScreenMove 200, 100
  14. rounds = 1
  15.     Cls
  16.     drawTargets
  17.     Print: Print
  18.     cp "*** Bulls Eye! ***"
  19.     Print
  20.     cp "AI's Score is " + ts$(Scores(0))
  21.     cp "Your Score is " + ts$(Scores(1))
  22.     Print
  23.     cp "Throw Type:      Description:          Probable Score:      "
  24.     cp "      1          Fast Overarm     Bullseye or Complete Miss!"
  25.     cp "      2       Controlled Overarm       10, 20 or 30 pts     "
  26.     cp "      3        Frustration Throw        Anything! LOL       "
  27.     If turn Then
  28.         Print
  29.         cp "Human, press Throw Type number 1, 2 or 3"
  30.         t = 0
  31.         While t <> 1 And t <> 2 And t <> 3
  32.             k$ = InKey$
  33.             t = Val(k$)
  34.         Wend
  35.         cp ts$(t)
  36.     Else
  37.         t = Int(Rnd * 3) + 1
  38.         Print
  39.         cp "AI is choosing Throw Type: " + ts$(t)
  40.     End If
  41.     luck = Rnd: score = 0
  42.     If luck >= tt_X_p(t, 1) Then cp "BULLSEYE!!!  40 points": score = 40: GoTo 1
  43.     If luck >= tt_X_p(t, 2) Then cp "Hit 30 point zone": score = 30: GoTo 1
  44.     If luck >= tt_X_p(t, 3) Then cp "Hit 20 point zone": score = 20: GoTo 1
  45.     If luck >= tt_X_p(t, 4) Then cp "Whew, Hit 10 point zone": score = 10: GoTo 1
  46.     cp "OOPS!! Wallshot!!! Zero Points!!!"
  47.    1 Scores(turn) = Scores(turn) + score
  48.     updateTarget score
  49.     Print: Print
  50.     cp "OK    press any... zzz"
  51.     Sleep
  52.     If turn Then 'both players shot their round
  53.         If Scores(0) > Scores(1) And Scores(0) >= 200 Then winner$ = "AI"
  54.         If Scores(1) > Scores(0) And Scores(1) >= 200 Then winner$ = "Human"
  55.         If Scores(0) = Scores(1) And Scores(0) >= 200 Then winner$ = "Tie"
  56.         rounds = rounds + 1
  57.     End If
  58.     turn = (turn + 1) Mod 2
  59. Loop Until winner$ <> ""
  60. cp "AI's Score is " + ts$(Scores(0))
  61. cp "Your Score is " + ts$(Scores(1))
  62. cp "Game goes to " + winner$ + "."
  63.  
  64. Sub cp (s$)
  65.     Locate , (80 - Len(s$)) / 2: Print s$
  66.  
  67. Function ts$ (num)
  68.     ts$ = _Trim$(Str$(num))
  69.  
  70. Sub drawTargets
  71.     cy = Ymax - 90
  72.     For r = 20 To 80 Step 20
  73.         Circle (90, cy), r, 15
  74.         Circle (Xmax - 90, cy), r, 15
  75.     Next
  76.     For y = Ymax - 85 To Ymax - 25 Step 20
  77.         If i Mod 2 Then c = 12 Else c = 15
  78.         Paint (90, y), c, 15
  79.         Paint (Xmax - 90, y), c, 15
  80.         i = i + 1
  81.     Next
  82.     For i = 1 To rounds
  83.         Circle (aix(i), aiy(i)), 2, 0
  84.         drawArrow aix(i), aiy(i)
  85.         Circle (hx(i), hy(i)), 2, 0
  86.         drawArrow hx(i), hy(i)
  87.     Next
  88.     If turn Then
  89.         Circle (aix(rounds + 1), aiy(rounds + 1)), 2, 0
  90.         drawArrow aix(rounds + 1), aiy(rounds + 1)
  91.     End If
  92.  
  93. Sub updateTarget (score)
  94.     If score Then
  95.         cy = Ymax - 90
  96.         dist = (40 - score) * 2 + 2 + Rnd * 16
  97.         angle = Rnd * _Pi * 2
  98.         If turn Then cx = Xmax - 90 Else cx = 90
  99.         x = cx + dist * Cos(angle)
  100.         y = cy + dist * Sin(angle)
  101.         Circle (x, y), 2, 0
  102.         drawArrow x, y
  103.         If turn Then ' save the place
  104.             hx(rounds + 1) = x: hy(rounds + 1) = y
  105.         Else
  106.             aix(rounds + 1) = x: aiy(rounds + 1) = y
  107.         End If
  108.     End If
  109.  
  110. Sub drawArrow (x, y)
  111.     Color 0
  112.     Line (x - 4, y)-(x + 4, y)
  113.     Line (x, y - 4)-(x, y + 4)
  114.     Circle (x, y), 2
  115.     Circle (x, y), 1
  116.     Color 15
  117.  

 
BullsEye v2.PNG

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #9 on: November 10, 2021, 06:59:30 am »
Cool...
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #10 on: November 10, 2021, 02:25:09 pm »
Bplus,

I have a simple dartboard program that I made with sdlbasic. Well... maybe not simple.

 
Screenshot from 2021-11-11 06-14-09.png


Multiple shades of red, black, green and white. Rather than try to create a routine for a dart(s) to collide with odd shaped segments of a 'pie' I would just use a simple getpixel(x,y) - well that was my intention. Never did get beyond creating the dartboard. If you want the listing, let me know and I will post it. If you want to just use the image be my guest. No credit necessary.

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #11 on: November 10, 2021, 06:28:36 pm »
Really nice dart board @johnno56 !!!

Instead of redrawing, we could just use the image.

PS Rotozoom might do wonders with a dart image or 2.
« Last Edit: November 10, 2021, 06:45:46 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #12 on: November 11, 2021, 01:38:33 am »
As I mentioned earlier, odd shaped collision detection, for me anyway, was difficult. I figured that getpixel() (point()) would be easier. As a result, not all the black segments are black. Each scoring segment is a slight shade lighter. Same for the greens, reds and whites. I am not certain that a screen capture will pick up the differences. eg: if point(dartx,darty) = whatever then score is whichever... if point(dartx,darty) = grey (wire) then dart bounces off board. No score. Loss of dart.

If the screen capture works then cool. If not, let me know, and I will post the listing.

I like the idea of rotozoom. Couple of thoughts to increase difficulty. Slight gravity. Player will need to aim a little higher. Add slight aiming movement (like the effect of breathing when target shooting). Add a menu of difficulty to determine extent of aiming and moving... How about that? Ideas. Better write them down! This does not happen very often... I surprise myself at times... lol
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #13 on: November 11, 2021, 01:50:36 am »
Great idea for collision detection, _putimage I don't think will blend so color should stay true, my opinion and guess, honestly don't know for sure.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
« Reply #14 on: November 11, 2021, 04:58:19 pm »
This is where I got the idea for a dartboard. https://scratch.mit.edu/projects/2261044/
This was made by kids... Checkout how the board is put together. "See Inside".
Each segment of the board is 'patched' together. The dart scores when it hits a 'shape'

If you are up to it, play the game, just to see how it works. The system of aiming and firing are interesting.

In my opinion this could be a fun project to either inspire or duplicate... In my opinion...
Logic is the beginning of wisdom.