Here is my entry. I really wanted to work on it some more to clean everything up, but time is hard to come by of late. It is a little different than Yahtzee (on purpose), but it generally follows the same rules. I have in here a basic framework for where a computer player could be added later on.
randomize timer()
sync on : sync rate 60
set display mode 800,600,32
backdrop off : hide mouse
dim dice(5) : dim okay(6) : dim colr(8)
dim p1(5,20) : dim change(5) : dim num_spins(4)
dim name$(4) : dim cats_full(4) : dim score(4)
for i = 1 to 20 : for x = 1 to 5 : p1(x,i) = 0 : next x : next i
for i = 1 to 4 : num_spins(i) = 0 : cats_full(i) = 0 : next i
turn = 1
SW = screen width() : SH = screen height()
white = rgb(255,255,255) : colr(1) = white
red = rgb(225,0,0) : colr(2) = red
blue = rgb(0,35,182) : colr(3) = blue
green = rgb(0,150,30) : colr(4) = green
purple = rgb(255,0,255) : colr(5) = purple
grey = rgb(128,128,128) : colr(6) = grey
brown = rgb(128,64,0) : colr(7) = brown
pink = rgb(255,128,128) : colr(8) = pink
gosub TITLE_SCREEN
gosub MAKE_IMGS
show mouse
if NumPlayers > 1
` player versus the other humans
repeat
cf = 0
for turn = 1 to NumPLayers
if cats_full(turn) = 0
gosub BEGIN
else
inc cf,1
endif
next turn
until cf = NumPlayers
gosub DeclareWinner
else
` player versus the computer
repeat
cf = 0
if cats_full(1) = 0
turn = 1 : gosub BEGIN
else
cf = 1
endif
if cats_full(2) = 0
gosub CPU_TURN
else
inc cf,1
endif
until cf = 2
gosub DeclareWinner
` end of game totals and comparison
endif
for i = 1 to 6
if sprite exist(i) = 1 then delete sprite i
if image exist(i) = 1 then delete image i
next i
end
BEGIN:
` setup screen
cls green
ink blue,0
box 0,420,SW - 1,SH - 1
ink white,0
cat_selected = 0
while cat_selected = 0
center text SW * .5,0,name$(turn)
if num_spins(turn) = 0 then gosub ROLL_DICE : gosub DP_ROLL
if num_spins(turn) > 0 and num_spins(turn) < 3 then gosub RE_ROLL_DICE : gosub DP_ROLL
s = SW - 150 : gosub PRINT_STATUS
ink white,0
if NumPlayers > 1 or turn = 1
if num_spins(turn) < 2
text 10,SH - 160, "Left Click on the die you want to change or click on the category you want."
text 10,SH - 140, "Right click to spin."
else
text 10,SH - 160,"Select category by left clicking on it."
endif
sync
else
` computer's turn
text 10,SH - 60,"Computer is deciding what to do."
sync
wait 1000
endif
num_spins(turn) = num_spins(turn) + 1
if num_spins(turn) < 3
for i = 1 to 5 : change(i) = 0 : next i
do
mc = mouseclick() : mx = mousex() : my = mousey()
` ink green,0
` box 0,0,50,50
ink white,0
` text 0,0,"mx: " + str$(mx)
` text 0,20,"my: " + str$(my)
if mc = 1
if my >= 19 and my <= 81 and mx < 390
for i = 1 to 5
if mx >= (((i - 1) * 70) + 50) and mx <= (((i - 1) * 70) + 110)
if change(i) = 0
change(i) = 1 : ink rgb(180,0,130),0
else
change(i) = 0 : ink rgb(0,150,30),0
endif
x = (((i - 1) * 70) + 44) : y = 16
line x,y,x + 68,y
line x + 68,y,x + 68,y + 68
line x,y,x,y + 68
line x,y + 68,x + 68,y + 68
endif
next i
endif
if mc = 1 and mx >= (SW - 150)
cat = ((my - 13) / 20) + 1 : dne = 0
time# = timer() + 800
if p1(turn,cat) > 0
if cat = 15 and p1(turn,cat) > 0
` got more than one Iyahtzou
p1(turn,cat) = p1(turn,cat) + 100
else
time# = timer() + 1250
repeat
text 100,100,"You already picked that!!" + str$(cat)
sync
dne = 1
until timer() > time#
ink green,0
box 90,90,310,140
ink white,0
endif
else
` repeat
` text 100,100,"picked cat #" + str$(cat)
` sync
` until timer() > time#
p1(turn,cat) = p1(5,cat) : if p1(5,cat) = 0 then p1(turn,cat) = -1
cat_selected = cat
endif
s = SW - 150 : gosub PRINT_STATUS
sync
wait 100
if dne = 0 then exit
endif
while mc = 1
mc = mouseclick()
sync
endwhile
endif
if mc = 2 then exit
sync
loop
else
` user can only place it in a category
mc = mouseclick() : mx = mousex() : my = mousey()
if mc = 1 and mx >= (SW - 150)
cat = ((my - 13) / 20) + 1 : dne = 0
time# = timer() + 800
if p1(turn,cat) > 0
if cat = 15 and p1(turn,cat) > 0
` got more than one Iyahtzou
p1(turn,cat) = p1(turn,cat) + 100
else
time# = timer() + 1250
repeat
text 100,100,"You already picked that!!" + str$(cat)
sync
dne = 1
until timer() > time#
ink green,0
box 90,90,310,140
ink white,0
endif
else
` repeat
` text 100,100,"picked cat #" + str$(cat)
` sync
` until timer() > time#
p1(turn,cat) = p1(5,cat) : if p1(5,cat) = 0 then p1(turn,cat) = -1
cat_selected = cat
endif
s = SW - 150 : gosub PRINT_STATUS
sync
wait 100
if dne = 0 then exit
endif
endif
endwhile
num_spins(turn) = 0
catCount = 0
for t = 1 to 16
if p1(turn,t) <> 0 then inc catCount
next t
if catCount = 13 then cats_full(turn) = 1
return
PRINT_STATUS:
` enter with 's' equals where to draw the lines
ink white,0
line s,10,s + 149,10 : line s,10,s,SH - 200 : line s,SH - 200,s + 149,SH - 200 : line s + 149,10,s + 149,SH - 200
for j = 32 to 372 step 20
line s,j,s + 149,j
next j
set text size 11
s = s + 5 : k = 15
if p1(turn,1) = 0
ink blue,0
text s + 120,k,str$(okay(1)) : p1(5,1) = okay(1)
else
ink red,0
a$ = str$(p1(turn,1)) : if a$ = "-1" then a$ = "0"
text s + 120,k,a$
endif
text s,k,"Onesies:"
if p1(turn,2) = 0
ink blue,0
text s + 120,k + 20,str$(okay(2)*2) : p1(5,2) = okay(2) * 2
else
ink red,0
a$ = str$(p1(turn,2)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 20,a$
endif
text s,k + 20, "Twosies:"
if p1(turn,3) = 0
ink blue,0
text s + 120,k + 40,str$(okay(3)*3) : p1(5,3) = okay(3) * 3
else
ink red,0
a$ = str$(p1(turn,3)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 40,a$
endif
text s,k + 40, "Trays:"
if p1(turn,4) = 0
ink blue,0
text s + 120,k + 60, str$(okay(4)*4) : p1(5,4) = okay(4) * 4
else
ink red,0
a$ = str$(p1(turn,4)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 60,a$
endif
text s,k + 60, "Quads: "
if p1(turn,5) = 0
ink blue,0
text s + 120,k + 80,str$(okay(5)*5) : p1(5,5) = okay(5) * 5
else
ink red,0
a$ = str$(p1(turn,5)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 80,a$
endif
text s,k + 80, "Quints: "
if p1(turn,6) = 0
ink blue,0
text s + 120,k + 100,str$(okay(6)*6) : p1(5,6) = okay(6) * 6
else
ink red,0
a$ = str$(p1(turn,6)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 100,a$
endif
text s,k + 100, "Sixes: "
` get sub-total for the top
ink purple,0
scoar = 0
for g = 1 to 6
if p1(turn,g) <> -1 then scoar = scoar + p1(turn,g)
next g
text s,k + 120,"Sub-Total:"
text s + 120,k + 120,str$(scoar)
text s,k + 140,"Bonus"
ba = 0 : if scoar >= 63 then ba = 35
text s + 120,k + 140,str$(ba)
text s,k + 160,"Total Top:"
text s + 120,k + 160,str$(scoar + ba)
chance = okay(1) + okay(2) * 2 + okay(3) * 3 + okay(4) * 4 + okay(5) * 5 + okay(6) * 6
bscoar = 0
if p1(turn,10) = 0
ink blue,0
if three_of_a_kind = 1
text s + 120,k + 180,str$(chance) : p1(5,10) = chance
else
text s + 120,k + 180,str$(three_of_a_kind) : p1(5,10) = three_of_a_kind
endif
else
ink red,0
a$ = str$(p1(turn,10)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 180,a$
if p1(turn,10) <> -1 then bscoar = bscoar + p1(turn,10)
endif
text s,k + 180,"Three of a kind:"
if p1(turn,11) = 0
ink blue,0
if four_of_a_kind = 1
text s + 120,k + 200,str$(chance) : p1(5,11) = chance
else
text s + 120,k + 200,str$( four_of_a_kind) : p1(5,11) = four_of_a_kind
endif
else
ink red,0
a$ = str$(p1(turn,11)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 200,a$
if p1(turn,11) <> -1 then bscoar = bscoar + p1(turn,11)
endif
text s,k + 200,"Four of a kind:"
if p1(turn,12) = 0
ink blue,0
if full_house = 1
text s + 120,k + 220,"25" : p1(5,12) = 25
else
text s + 120,k + 220,str$(full_house) : p1(5,12) = full_house
endif
else
ink red,0
a$ = str$(p1(turn,12)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 220,a$
if p1(turn,12) <> -1 then bscoar = bscoar + p1(turn,12)
endif
text s,k + 220,"Full House:"
if p1(turn,13) = 0
ink blue,0
if small_strait = 1
text s + 120,k + 240,"30" : p1(5,13) = 30
else
text s + 120,k + 240,str$(small_strait) : p1(5,13) = small_strait
endif
else
ink red,0
a$ = str$(p1(turn,13)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 240,a$
if p1(turn,13) <> -1 then bscoar = bscoar + p1(turn,13)
endif
text s,k + 240,"small straight:"
if p1(turn,14) = 0
ink blue,0
if large_strait = 1
text s + 120,k + 260,"40" : p1(5,14) = 40
else
text s + 120,k + 260,str$(large_strait) : p1(5,14) = large_strait
endif
else
ink red,0
a$ = str$(p1(turn,14)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 260,a$
if p1(turn,14) <> -1 then bscoar = bscoar + p1(turn,14)
endif
text s,k + 260,"large straight:"
if p1(turn,15) = 0
ink blue,0
if iyahtzee = 1
text s,k + 280,"50" : p1(5,15) = 50
else
text s + 120,k + 280,str$(iyahtzee) : p1(5,15) = iyahtzee
endif
else
ink red,0
a$ = str$(p1(turn,15)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 280,a$
if p1(turn,15) <> -1 then bscoar = bscoar + p1(turn,15)
endif
text s,k + 280,"iyahtzou:"
if p1(turn,16) = 0
ink blue,0
text s + 120,k + 300,str$(chance) : p1(5,16) = chance
else
ink red,0
a$ = str$(p1(turn,16)) : if a$ = "-1" then a$ = "0"
text s + 120,k + 300,a$
if p1(turn,16) <> -1 then bscoar = bscoar + p1(turn,16)
endif
text s,k + 300,"Chance:"
ink purple,0
text s,k + 320,"Sub-Total:"
text s + 120,k + 320,str$(bscoar)
text s,k + 340,"Grand Total:"
text s + 120,k + 340,str$(scoar + bscoar)
score(turn) = scoar + bscoar
sync
return
DP_ROLL:
`cls rgb(0,150,30)
`ink rgb(255,255,255),0
`ink rgb(0,35,182),0
`box 0,420,639,479
for i=1 to 5
if num_spins(turn) > 0 and change(i) = 0 then paste image dice(i),((i-1)*70)+50,20
next i
for i=1 to 5
if num_spins(turn) = 0 or change(i) = 1
for spin = 1 to (rnd(17) + 5)
paste image rnd(5) + 1,((i - 1) * 70) + 50,20
` print dice(i)
sync
` wait 5
next spin
wait 5
endif
paste image dice(i),((i - 1) * 70) + 50,20
next i
sync
return
MAKE_IMGS:
create bitmap 1,60,60
restore IMG_DATA
for img = 1 to 6
cls
ink blue,0
box 0,0,60,60
ink white,0
box 2,2,58,58
read NumberOfDots
ink red,0
for NOD = 1 to NumberOfDots
read x,y
box x,y,x + 6,y + 2
box x + 1,y - 1,x + 5,y + 3
box x + 2,y -2,x + 4,y + 4
next NOD
get image img,0,0,60,60
next img
set current bitmap 0
delete bitmap 1
sync
return
IMG_DATA:
rem one NumberOfDots,x1,y1,x2,y2 per dot
data 1,28,28
rem two
data 2,28,14,28,42
rem three
data 3,28,14,28,28,28,42
rem four
data 4,14,14,42,14,14,42,42,42
rem five
data 5,14,14,42,14,28,28,14,42,42,42
rem six
data 6,14,14,14,28,14,42,42,14,42,28,42,42
RE_ROLL_DICE:
cls green
ink blue,0
box 0,420,SW - 1,SH - 1
for i = 1 to 5
if change(i) > 0 then dice(i) = rnd(5) + 1
next i
gosub EVAL_ROLL
return
ROLL_DICE:
for i = 1 to 5
dice(i) = rnd(5) + 1
next i
gosub EVAL_ROLL
return
EVAL_ROLL:
` determine what player has got
` init vars
iyahtzee=0 : large_strait=0 : small_strait=0 : full_house=0
four_of_a_kind=0 : three_of_a_kind=0: sixes=0 : fives=0 : fours=0: threes=0
twos=0 : onesies=0
rem store data
for i=1 to 6 : okay(i)=0 : next i
for t=1 to 6
for i=1 to 5
if dice(i)=t then okay(t)=okay(t)+1
next i
next t
rem iyahtzee
t=dice(1):ct=0
for i=1 to 6
if okay(i)=5 then ct=i
next i
if ct>0 then iyahtzee=1
rem small & large strait
ct=0
for i=1 to 5
if okay(i)=0 then ct=-1
next i
if ct=0 then large_strait=1 : small_strait=1
ct=0
for i=2 to 6
if okay(i)=0 then ct=-1
next i
if ct=0 then large_strait=1 : small_strait=1
ct=0
for i=1 to 4
if okay(i)=0 then ct=-1
next i
if ct=0 then small_strait=1
ct=0
for i=2 to 5
if okay(i)=0 then ct=-1
next i
if ct=0 then small_strait=1
ct=0
for i=3 to 6
if okay(i)=0 then ct=-1
next i
if ct=0 then small_strait=1
rem full house
nbr1=0 : nbr2=0
for t=1 to 6
if okay(t)>=3 then nbr1=t
if okay(t)>=2 and t<>nbr1 then nbr2=t
next t
if nbr1>0 and nbr2>0 then full_house=1
rem four of a kind
ct=0 : dt=0
for i=1 to 6
if okay(i)>=4 then ct=1
if okay(i)>=3 then dt=1
next i
if ct=1 then four_of_a_kind=1 : three_of_a_kind=1
if dt=1 then three_of_a_kind=1
return
TITLE_SCREEN:
cls : okay = 0 : counter = 0 : CTimer# = timer() + 80
repeat
if timer() > CTimer# then inc counter : CTimer# = timer() + 80 : if counter > 5 then counter = 1
ink colr(counter),0
box 0,0,SW,SH
ink colr(counter + 1),0
box 4,4,SW - 4,SH - 4
ink colr(counter + 2),0
box 8,8,SW - 8,SH - 8
ink colr(counter + 3),0
box 12,12,SW - 12,SH - 12
ink rgb(0,0,0),0
box 16,16,SW - 16,SH - 16
s = SW * .5 : h = SH * .4 : a$ = "Iyahtzou"
set text size 50
ink blue,0 : center text s + 6, h - 6,a$
ink purple,0 : center text s + 8, h - 8,a$
ink white,0 : center text s + 10, h - 10,a$
ink red,0 : center text s + 12, h - 12,a$
set text size 14
h = SH * .55 : a$ = "by LBFN"
ink red,0 : center text s + 1, h - 1,a$
ink blue,0 : center text s + 2, h - 2,a$
ink green,0 : center text s + 3, h - 3,a$
ink purple,0 : center text s + 4, h - 4,a$
ink colr(counter),0
ttd$ = "Press 2, 3 or 4 to select # of players"
tw = text width(ttd$) * .5
center text (SW * .5),SH * .8 ,ttd$
scan = scancode()
if scan >= 2 and scan <= 5 then NumPlayers = scan - 1 : okay = 1
sync
until okay = 1
cls
` wait until the user is not pressing a key
repeat
sync
until scancode() = 0
ink white,0
for n = 1 to NumPlayers
name$(n)=""
set cursor 100,100 + n * 20
input "Enter the name for player " + str$(n) + " : ";name$
Name$(n) = name$
next n
`if NumPLayers = 1 then name$(2) = "Computah"
return
CPU_TURN:
cls
text 100,100,"It's the computah's turn."
sync
wait 1000
end
return
DeclareWinner:
` display everyone's scores
cls green
ink blue,0
box 0,420,SW - 1,SH - 1
for turn = 1 to NumPlayers
s = ((turn - 1) * 180) + 5
ink yellow,0
set text size 11
text s + 20,380,name$(turn)
gosub PRINT_STATUS
next turn
` calculate the scores
winner = 0
if score(1) > score(2) and score(1) > score(3) and score(1) > score(4) then winner = 1
if score(2) > score(1) and score(2) > score(3) and score(2) > score(4) then winner = 2
if NumPLayers >= 3
if score(3) > score(1) and score(3) > score(2) and score(3) > score(4) then winner = 3
endif
if NumPLayers = 4
if score(4) > score(1) and score(4) > score(2) and score(4) > score(3) then winner = 4
endif
repeat
mc = mouseclick()
sync
until mc = 0
ink white,0
if winner = 0
` wait until the user lets go of the mouse button
repeat
center text SW * .5,SH - 150,"It's a tie!!!"
center text SW * .5,SH - 130,"Click mouse to quit."
sync
until mouseclick() > 0
else
repeat
mc = mouseclick()
center text SW * .5,SH- 150,name$(winner) + " is the winner!"
center text SW * .5,SH -130,"Click mouse to quit."
sync
until mc > 0
endif
return