Domino stones

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Domino stones

Post by Henko »

' this function generates a set of 28 domino stones
' each stone is a sprite with a name "i,j", i and j being
' the 2 number of eyes on the stone

Maybe someone likes to program a game with the domino stones

Code: Select all

graphics ! graphics clear 1,1,1
draw color 0,0,0
option angle degrees ! get screen size sx,sy

dominoset()

for i=0 to 6
  for j=i to 6
    sprite i&j show
    sprite i&j at 100*j, 130*i scale 0.7
    next j
  next i
pause 3
do graphics clear 1,1,1
  i=rnd(7) ! j=i+floor(rnd(7-i)) ! sc=.4+rnd(1) ! a=rnd(360)
  sprite i&j at rnd(sx),rnd(sy) scale sc angle a
  sprite i&j stamp ! pause .2
  until forever
end

' this function generates a set of 28 domino stones
' each stone is a sprite with a name "i,j", i and j being
' the 2 number of eyes on the stone
'
def dominoset()
ob=option_base() ! option base 1
dim .xy(7,2)
for i=1 to 7 ! read .xy(i,1) ! read .xy(i,2) ! next i
data 21,21, 21,45, 21,69, 45,45, 69,21, 69,45, 69,69
for i=0 to 6 ! for j=i to 6
  sprite i&j begin 90,173
  fill color .867, .766, .645
  fill rect 0,0 to 90,173
  draw size 8 ! draw rect 0,0 to 90,173
  draw size 2 ! draw line 8,86 to 82,86
  d_c(i,0) ! d_c(j,83)
  sprite i&j end
  next j ! next i
option base ob
end def

def d_c(k,dy)
fill color 0,0,0
if k=0 then return
if k=1 then
  fill circle .xy(4,1),.xy(4,2)+dy size 8
  return
  end if
if k=2 then
  fill circle .xy(1,1),.xy(1,2)+dy size 8
  fill circle .xy(7,1),.xy(7,2)+dy size 8
  return
  end if
if k=3 then
  fill circle .xy(1,1),.xy(1,2)+dy size 8
  fill circle .xy(4,1),.xy(4,2)+dy size 8
  fill circle .xy(7,1),.xy(7,2)+dy size 8
  return
  end if
if k=4 then
  fill circle .xy(1,1),.xy(1,2)+dy size 8
  fill circle .xy(3,1),.xy(3,2)+dy size 8
  fill circle .xy(5,1),.xy(5,2)+dy size 8
  fill circle .xy(7,1),.xy(7,2)+dy size 8
  return
  end if
if k=5 then
  for i=1 to 7 ! if i=2 or i=6 then continue
    fill circle .xy(i,1),.xy(i,2)+dy size 8
    next i ! return
  end if
if k=6 then
  for i=1 to 7 ! if i=4 then continue
    fill circle .xy(i,1),.xy(i,2)+dy size 8
    next i
  end if
end def
IMG_1511.PNG
IMG_1511.PNG (350.76 KiB) Viewed 2413 times

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Domino stones

Post by Mr. Kibernetik »

Nice looking stones

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Domino stones

Post by Henko »

Could not resist to compact the code somewhat at the cost of readability.

Code: Select all

graphics ! graphics clear 1,1,1 ! draw color 0,0,0
option angle degrees ! get screen size sx,sy

       dominoset()

for i=0 to 6 ! for j=i to 6
  sprite i&j at 100*j, 130*i scale 0.7 ! sprite i&j show
  next j ! next i
end

' this function generates a set of 28 domino stones
' each stone is a sprite with a name "ij", i and j being
' the 2 number of eyes on the stone
'
def dominoset()
ob=option_base() ! option base 1
dim .xy(7,2)
for i=1 to 7 ! read .xy(i,1) ! read .xy(i,2) ! next i
data 21,21, 21,45, 21,69, 45,45, 69,21, 69,45, 69,69
for i=0 to 6 ! for j=i to 6
  sprite i&j begin 90,173
  fill color .867, .766, .645 ! fill rect 0,0 to 90,173
  draw size 8 ! draw rect 0,0 to 90,173
  draw size 2 ! draw line 8,86 to 82,86
  d_c(i,0) ! d_c(j,83)
  sprite i&j end
  next j ! next i
option base ob
end def

def d_c(k,dy)
fill color 0,0,0
if odd(k) then fc(4,dy)
if k>1 and k<7 then ! fc(1,dy) ! fc(7,dy) ! end if
if k>3 and k<7 then ! fc(3,dy) ! fc(5,dy) ! end if
if k=6 then ! fc(2,dy) ! fc(6,dy) ! end if
end def
def fc(c,dy) ! fill circle .xy(c,1),.xy(c,2)+dy size 8 ! end def

Post Reply