Game of CRAPS in BASIC

Talk about your programs in progress. Discuss how to implement features, etc.
Forum rules
This section is for testing Commander X16 programs and programs related to the CX16 for other platforms (compilers, data conversion tools, etc.)

Feel free to post works in progress, test builds, prototypes, and tech demos.

Finished works go in the Downloads category. Don't forget to add a hashtag (#) and the version number your program was meant to run on. (ie: #R41).
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Game of CRAPS in BASIC

Post by ahenry3068 »

FOR EMULATOR R42
Ok.. This is kind of what I came here for.
Got the game kind of looking like I imagine.

Only about 2/3rds of the game logic done... Win or lose the bet on the first roll only.
Next logic is to make the POINT. (Google Rules of CRAPS if not familiar).
THIS IS MY NEXT IMPLEMENTATION.

My Music Knowledge sucks. Sound effects are place holders only at the moment.
I need to have a sound collaborator or really do a lot of playing with the sound commands and a bit
of music study.

Right now Dice are only displayed as numbers.. After I have the full Game Logic implemented I'm going to
draw a facsimile of actual DICE on Screen with PETSCII Characters.


Cut and Paste the following Code into the R42 emulator





10 REM THIS IS THE CRAPS PROGRAM
20 DIM DI(2): REM THESE ARE THE TEMPORARY DICE VALUES
21 DIM MSG$(18): REM GAME MESSAGES.
22 GOSUB 6000 : REM SET MESSAGES TO BLANK STRING
24 DI(1) = RND(-TI)
25 FMINIT: REM INITIALIZE THE FM CHIP
40 PT = 500: REM THIS IS THE USERS POT OF MONEY
45 GOSUB 5000:GOSUB 7500:REM BORDER SUB THEN SHOW THE POT

50 MSG$(2) = "LETS PLAY A GAME OF CRAPS !"
60 MSG$(5) = "PRESS ANY KEY TO START THE GAME"
70 GOSUB 7000: REM SHOW THE MESSAGES
80 GOSUB 8000: REM WAIT FOR KEYPRESS

100 REM GAME LOGIC STARTS HERE
310 GOSUB 2000: REM GET THE BET
315 GOSUB 6000: REM BLANK THE MESSAGES
316 GOSUB 7000: REM CLEAR MESSAGE AREA
320 MSG$(2) = "YOUR BET IS $"+STR$(B)+".00"
330 MSG$(4) = "PRESS ANY KEY TO ROLL YOUR POINT"
335 GOSUB 7000: REM SHOW MESSAGES
340 GOSUB 8000: REM WAIT FOR KEYPRESS
350 GOSUB 3000: REM LOAD THE DICE
360 GOSUB 4000: REM SHOW THE DICE
365 P = R: REM POINT TO MAKE R IS THE VALUE OF THE DICE ROLL
370 IF P = 7 OR P = 11 THEN PT = PT + B
371 GOSUB 7500
375 IF P = 7 OR P = 11 THEN GOSUB 7500
376 COLOR 1, 0
377 LOCATE 18, 5
380 IF P = 7 OR P = 11 THEN PRINT "YOU WON THE ROLL !!";
385 IF P = 7 OR P = 11 THEN FMPLAY 6,"TADATADA"
390 IF P = 2 OR P = 3 OR P = 12 THEN PRINT "YOU CRAPPED OUT !!! ";
400 IF P = 2 OR P = 3 OR P = 12 THEN PT = PT - B
405 GOSUB 7500
410 IF P = 2 OR P = 3 OR P = 12 THEN FMPLAY 5,"<BBBGGGCC"
420 IF PT = 0 THEN GOTO 1000

700 GOSUB 7500
705 LOCATE 20, 5:COLOR 1, 0
710 PRINT "*** PRESS ANY KEY TO ROLL ***";
720 GOSUB 8000:GOSUB 6000:GOSUB 5330
730 IF PT > 0 THEN GOTO 100

1000 SCREEN 0:COLOR 1,0:CLS:PRINT
1010 IF PT = 0 OR PT < 0 THEN PRINT "YOU LOST IT ALL !!!"
1110 PRINT "HOPE YOU ENJOYED PLAYING CRAPS !!"
1130 END

1999 REM INPUT THE BET
2000 B$ = ""
2001 GOSUB 7500
2003 COLOR 1,0:LOCATE 56, 5
2004 INPUT "ENTER YOUR BET : "; B$
2005 B = INT(VAL(B$))
2010 LOCATE 57, 5
2020 IF B = 0 OR B < 0 THEN PRINT "MUST ENTER A POSITIVE BET !!, TRY AGAIN !!";
2060 IF B > PT THEN PRINT "YOU CAN'T BET MORE THAN YOU HAVE !!, TRY AGAIN !!";
2080 IF B > PT OR B = 0 THEN GOTO 2000
2085 IF B < 0 THEN GOTO 2000
2090 LOCATE 56, 5:PRINT " ";
2100 LOCATE 57, 5:PRINT " ";
2110 RETURN

2999 REM LOAD THE DICE
3000 FOR I = 1 TO 2
3010 DI(I) = INT(RND(1)* 6) + 1
3020 NEXT I
3025 R = DI(1)+DI(2)
3030 RETURN

3999 REM DISPLAY THE ROLL. JUST PRINT UNTIL GAME LOGIC IS DONE
4000 GOSUB 7000: REM CLEAR THE SCREEN AREA
4005 LOCATE 14, 5:PRINT "DICE 1: ";DI(1),"DICE 2: ";DI(2);
4010 LOCATE 16, 5:PRINT "YOU ROLLED: ";R;
4020 LOCATE 17, 5
4030 IF R=12 THEN PRINT "** BOXCARS !! **";
4035 IF R=11 THEN PRINT "** A NATURAL !! **";
4040 IF R=7 THEN PRINT "** LUCKY SEVEN !! **";
4045 IF R=2 THEN PRINT "** SNAKE EYES !! **";
4060 FMPLAY 5,"GAG"
4080 RETURN

4990 REM THIS SUB DISPLAYS THE BORDER.
5000 SCREEN 0
5009 REM RED BORDER
5010 COLOR 2, 0 :CLS: REM RED FOREGROUND WHITE BACKGROUND
5020 FOR I = 1 TO 80:PRINT "*";:NEXT
5030 FOR I = 2 TO 52
5040 LOCATE I, 1: PRINT "*";
5050 LOCATE I, 80: PRINT "*";

5060 NEXT
5080 LOCATE 53, 1
5090 FOR I = 1 TO 80:PRINT "*";:NEXT

5149 REM NEXT COLOR IS WHITE (RED WHITE & BLUE)
5150 COLOR 1,0
5151 LOCATE 2,2
5155 FOR I = 1 TO 78:PRINT "*";:NEXT
5160 FOR I = 3 TO 51
5170 LOCATE I, 2: PRINT "*";
5180 LOCATE I, 79: PRINT "*";
5190 NEXT
5200 LOCATE 52, 2
5210 FOR I = 1 TO 78: PRINT "*"; :NEXT

5219 REM NEXT COLOR IS BLUE
5250 COLOR 6, 0
5260 LOCATE 3,3
5270 FOR I = 1 TO 76:PRINT "*";:NEXT I
5280 FOR I = 4 TO 50
5290 LOCATE I, 3: PRINT "*";
5300 LOCATE I, 78: PRINT "*";
5310 NEXT I
5320 LOCATE 51,3
5325 FOR I = 1 TO 76:PRINT "*"; :NEXT I
5330 FOR I = 4 TO 49 : REM CLEAR THE INNER AREA.
5346 LOCATE I, 4
5350 FOR C = 4 TO 77
5355 PRINT " ";
5360 NEXT C
5370 NEXT I
5380 RETURN

5999 REM TURN GAME MESSAGE STRINGS TO BLANK
6000 FOR I = 1 TO 18
6010 MSG$(I) = " "
6020 NEXT I
6030 RETURN

6999 SHOW MESSAGES
7000 COLOR 1, 0
7005 FOR I = 4 TO 21
7010 LOCATE I, 5
7015 M=INT(I-3)
7020 PRINT MSG$(M);
7030 NEXT I
7040 RETURN

7499 REM UPDATE POT
7500 COLOR 7,0: LOCATE 49, 6
7510 PRINT "MONEY IN THE POT: ";
7511 COLOR 5,0:PRINT "$";STR$(PT);".00";
7520 RETURN

8000 GET I$: IF I$<>"" THEN GOTO 8000 : REM FLUSH KEYBOARD BUFFER
8010 GET I$:IF I$="" THEN GOTO 8010 :REM PAUSE FOR INPUT
8020 RETURN
Last edited by ahenry3068 on Sun Apr 30, 2023 9:48 pm, edited 1 time in total.
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

OK, Just notice that pasting my code into this forum it reduced all of my strings of spaces to "".
I don't think this will effect game logic but it might make some of the display a little Wonkey.


Anyone know why this happened ?
Ed Minchau
Posts: 503
Joined: Sat Jul 11, 2020 3:30 pm

Re: GAME OF CRAPS IN BASIC

Post by Ed Minchau »

Code: Select all

Try putting your code inside code tags
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

I haven't done any of this in about 20 years..... lol.
Yah, thats on me.... Im an authentic graybeard.
I'm kinda literate, assume "like an html tag" ???

If I'm correct what tags. ???
TomXP411
Posts: 1781
Joined: Tue May 19, 2020 8:49 pm

Re: GAME OF CRAPS IN BASIC

Post by TomXP411 »

ahenry3068 wrote: Sat Apr 08, 2023 11:55 pm OK, Just notice that pasting my code into this forum it reduced all of my strings of spaces to "".
I don't think this will effect game logic but it might make some of the display a little Wonkey.


Anyone know why this happened ?
There are different buttons on the toolbar you can use for posting code...

Code: Select all

The </> button is the "Code" tag.
The C64 button makes things look like this.
And the X16 button makes things look like this. 
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

Many thanks.
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

OK THIS ONE HAS THE PROPER SPACE FILLED STRINGS INTACT: ..... Yay.
IT WILL LOOK MUCH BETTER WHEN RAN....

I would so like someone who has a musical Ear to step in and help me with sound effects.
INTRO (Maybe)
ROLLING THE DICE
WON A BET
LOST A BET
LOST IT ALL
BROKE THE BANK




Code: Select all

10 REM THIS IS THE CRAPS PROGRAM
20 DIM DI(2): REM THESE ARE THE TEMPORARY DICE VALUES
21 DIM MSG$(18):  REM GAME MESSAGES.
22 GOSUB 6000 :  REM SET MESSAGES TO BLANK STRING
24 DI(1) = RND(-TI)
25 FMINIT: REM INITIALIZE THE FM CHIP 
40 PT = 500:  REM THIS IS THE USERS POT OF MONEY
45 GOSUB 5000:GOSUB 7500:REM BORDER SUB THEN SHOW THE POT

50 MSG$(2) = "LETS PLAY A GAME OF CRAPS !"
60 MSG$(5) = "PRESS ANY KEY TO START THE GAME"
70 GOSUB 7000: REM SHOW THE MESSAGES
80 GOSUB 8000: REM WAIT FOR KEYPRESS

100 REM GAME LOGIC STARTS HERE
310 GOSUB 2000: REM GET THE BET
315 GOSUB 6000: REM BLANK THE MESSAGES
316 GOSUB 7000: REM CLEAR MESSAGE AREA
320 MSG$(2) = "YOUR BET IS $"+STR$(B)+".00"
330 MSG$(4) = "PRESS ANY KEY TO ROLL YOUR POINT"
335 GOSUB 7000: REM SHOW MESSAGES
340 GOSUB 8000: REM WAIT FOR KEYPRESS
350 GOSUB 3000: REM LOAD THE DICE
360 GOSUB 4000: REM SHOW THE DICE
365 P = R:  REM POINT TO MAKE R IS THE VALUE OF THE DICE ROLL
370 IF P = 7 OR P = 11 THEN PT = PT + B
371 GOSUB 7500
375 IF P = 7 OR P = 11 THEN GOSUB 7500  
376 COLOR 1, 0
377 LOCATE 18, 5
380 IF P = 7 OR P = 11 THEN PRINT "YOU WON THE ROLL !!";
385 IF P = 7 OR P = 11 THEN FMPLAY 6,"TADATADA"
390 IF P = 2 OR P = 3 OR P = 12 THEN PRINT "YOU CRAPPED OUT !!! ";
400 IF P = 2 OR P = 3 OR P = 12 THEN PT = PT - B 
405 GOSUB 7500
410 IF P = 2 OR P = 3 OR P = 12 THEN FMPLAY 5,"<BBBGGGCC"
420 IF PT = 0 THEN GOTO 1000

700 GOSUB 7500
705 LOCATE 20, 5:COLOR 1, 0
710 PRINT "*** PRESS ANY KEY TO ROLL ***";
720 GOSUB 8000:GOSUB 6000:GOSUB 5330
730 IF PT > 0 THEN GOTO 100
 
1000 SCREEN 0:COLOR 1,0:CLS:PRINT
1010 IF PT = 0 OR PT < 0 THEN PRINT "YOU LOST IT ALL !!!"
1110 PRINT "HOPE YOU ENJOYED PLAYING CRAPS !!"
1130 END

1999 REM INPUT THE BET
2000 B$ = ""
2001 GOSUB 7500
2003 COLOR 1,0:LOCATE 56, 5
2004 INPUT "ENTER YOUR BET : "; B$
2005 B = INT(VAL(B$))
2010 LOCATE 57, 5
2020 IF B = 0 OR B < 0 THEN PRINT "MUST ENTER A POSITIVE BET !!, TRY AGAIN !!";
2060 IF B > PT THEN PRINT "YOU CAN'T BET MORE THAN YOU HAVE !!, TRY AGAIN !!";
2080 IF B > PT OR B = 0 THEN GOTO 2000
2085 IF B < 0 THEN GOTO 2000
2090 LOCATE 56, 5:PRINT "                                                  ";
2100 LOCATE 57, 5:PRINT "                                                  ";
2110 RETURN

2999 REM LOAD THE DICE
3000 FOR I = 1 TO 2
3010  DI(I) = INT(RND(1)* 6) + 1
3020 NEXT I
3025 R = DI(1)+DI(2)
3030 RETURN

3999 REM DISPLAY THE ROLL.  JUST PRINT UNTIL GAME LOGIC IS DONE
4000 GOSUB 7000: REM CLEAR THE SCREEN AREA
4005 LOCATE 14, 5:PRINT "DICE 1: ";DI(1),"DICE 2: ";DI(2);
4010 LOCATE 16, 5:PRINT "YOU ROLLED: ";R;
4020 LOCATE 17, 5
4030 IF R=12 THEN PRINT "**   BOXCARS    !!  **";
4035 IF R=11 THEN PRINT "**  A NATURAL   !!  **";
4040 IF R=7  THEN PRINT "**  LUCKY SEVEN !!  **";
4045 IF R=2  THEN PRINT "**  SNAKE EYES  !!  **";
4060 FMPLAY 5,"GAG"
4080 RETURN

4990 REM THIS SUB DISPLAYS THE BORDER. 
5000 SCREEN 0
5009 REM RED BORDER
5010 COLOR 2, 0   :CLS:  REM RED FOREGROUND WHITE BACKGROUND
5020 FOR I = 1 TO 80:PRINT "*";:NEXT
5030 FOR I = 2 TO 52
5040     LOCATE I, 1: PRINT "*";
5050     LOCATE I, 80: PRINT "*";

5060 NEXT
5080 LOCATE 53, 1
5090 FOR I = 1 TO 80:PRINT "*";:NEXT

5149 REM NEXT COLOR IS WHITE (RED WHITE & BLUE)
5150 COLOR 1,0
5151 LOCATE 2,2
5155 FOR I = 1 TO 78:PRINT "*";:NEXT
5160 FOR I = 3 TO 51
5170     LOCATE I, 2: PRINT "*";
5180     LOCATE I, 79: PRINT "*";
5190 NEXT
5200 LOCATE 52, 2
5210 FOR I = 1 TO 78: PRINT "*"; :NEXT

5219 REM NEXT COLOR IS BLUE 
5250 COLOR 6, 0
5260 LOCATE 3,3 
5270 FOR I = 1 TO 76:PRINT "*";:NEXT I
5280 FOR I = 4 TO 50
5290     LOCATE I, 3: PRINT "*";
5300     LOCATE I, 78: PRINT "*";
5310 NEXT I
5320 LOCATE 51,3 
5325 FOR I = 1 TO 76:PRINT "*"; :NEXT I
5330 FOR I = 4 TO 49 : REM CLEAR THE INNER AREA. 
5346     LOCATE I, 4
5350     FOR C = 4 TO 77
5355         PRINT " ";
5360     NEXT C
5370 NEXT I 
5380 RETURN 

5999 REM TURN GAME MESSAGE STRINGS TO BLANK
6000 FOR I = 1 TO 18
6010    MSG$(I) = "                                          "
6020 NEXT I
6030 RETURN

6999 SHOW MESSAGES
7000 COLOR 1, 0
7005 FOR I = 4 TO 21
7010 LOCATE I, 5
7015   M=INT(I-3)
7020   PRINT MSG$(M);
7030 NEXT I
7040 RETURN

7499 REM UPDATE POT
7500 COLOR 7,0: LOCATE 49, 6
7510 PRINT "MONEY IN THE POT: ";
7511 COLOR 5,0:PRINT "$";STR$(PT);".00";
7520 RETURN

8000 GET I$: IF I$<>"" THEN GOTO 8000 : REM FLUSH KEYBOARD BUFFER
8010 GET I$:IF I$="" THEN GOTO 8010 :REM PAUSE FOR INPUT
8020 RETURN


totodilespy
Posts: 29
Joined: Sun Nov 01, 2020 7:23 pm
Location: United States

Re: GAME OF CRAPS IN BASIC

Post by totodilespy »

Simple but well made. Was fun to play, and very impressive for being done in BASIC. If i could suggest one thing, I'd maybe let the user roll again without having to enter their bet if they neither crap out or win the roll.
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

This is works in progress... I'm implementing that logic as I'm pausing to write this. :-)
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: GAME OF CRAPS IN BASIC

Post by ahenry3068 »

Wish I had a QuickBasic like compiler...lol
I haven't programmed using Line #'s since the 80's
Post Reply