Here I would like to present you another game of my BASIC type-in games series with listings that fit on three A4 pages.
This time I did an interpretation of the well-known dice game "Yahtzee". I tried again to create a product as round as possible with only the core elements necessary but still appealing to play. I put emphasis on improving the code to make my first-attempt algorithms simpler, something I learned form my BASIC 10Liner contest contributions worth practicing. Maybe you find the one or the other interesting trick in the code.
Yahtzee2020.pdf
My Yahtzee version is designed for 1-4 players
Additional features:
- - dice can be set to either black or multicolored ("Pip Color")
- Animated dice increase the tension
- Realistic random numbers within the rolling dice animation. For example after a 6 there can not follow another 6, but also not a 1.
- Dice rattle-in-a-leather-cup sound
- Fast, direct input via keyboard
- The 5 dice can be held and/or released with keys 1-5
- Keys A-M assign the points on the dice to a free category.
PS: Please don't upload or share the .prg file of the game. Exploring the listing is half the fun.
Edit: For better understanding here is an overview of the variables used in the listing:
Code: Select all
a = Temporary variable used in various occasions
b$ = Blank line of 5 spaces "{space*5}" + next line element r$
b = Tab position for current player column only used in function "score category"
c$ = Screen color codes to show the dice's pip color either in color or black
c = Flag 0 or 1 to toggle the dice's pip color
d$ = String with 22 "down" screen control elements to set cursor position
d = Temporary variable to further evaluate current key press Ascii value
dc$ = Screen code for empty dice cube with white background
dc$() = Screen code for dice faces (1-6)
f = Number of dice to be rolled, starting with 5, less if some were locked
g = Game state and jump value for "on g goto" (0=continue, 1=next round, 2=game over)
i = Temporary variable mostly used in for/next loops
j = Temporary variable mostly used in for/next loops
k$ = Temporary variable to get key press (getk$)
k = Ascii value of k$
l$ = Screen code for middle part of empty dice cube background + next line element r$
l = Index/line number where score table element needs to be updated after scoring
l() = flag if dice is locked(1) or not(0)
n$ = String variation of n with leading blanks
n = Score value
p$ = Score table as printed on screen (faster than dynamically building the table on screen each time)
p = Current player (0-3)
r$ = Screen code to go to the next line of 5er block from cursor position "{down}{left*5}".
r = Round counter (game ends after 13 rounds)
s = Value of SID base address (54272)
t$ = String combo "playerround " to either show "space=next player" or "space=next round"
t = Dice Roll counter within a turn (max 3 rolls are allowed)
v = Value of VIC base address (53248)
w = Helper variable used to temporarily store a value from a w(i) element
w() = Used in the dice roll animation to calulate rolling distance to bottom as per dice
x = Temporary helper variable used in functions "score category" and "dice roll animation"
x() = Current face value of dice 1-5
y = Temporary helper variable used in function "score category" to check for a full house
z = Number (0-3) of selected players 1-4