rem @@@@@@@@@
visible:
snd1 ; snd2 ; fnt1 ; fnt2 ;  mx ; my ; column ; row ; score ; test 
card = 0 ; mb = 0 ; CardHit = 0 ; mb2 = 0 ;  ColorHit = 0 ; RankHit = 0 ; SuitHit = 0 ; TopCard = 0 ; page = 1 ; phase = 1 ; ready = 1
ColumnHit = 0 ; RowHit = 0 ; noc = 0 ; StackHit = 0 ; test = 20
OldCard = 0 ; FloatStackReady = 0
cards?[60]
stack[20][50]
FloatStack[20][50]
column1?[50]
column2?[50]
column3?[50]
column4?[50]
column5?[50]
column6?[50]
column7?[50]
CardHitA[10]
ColorHitA[10]
RankHitA[10]
SuitHitA[10]
RowHitA[10]
ColumnHitA[10]
TempColumn?[50]
deck1?[60]
deck2?[60]
section?[11]
NumberOfCards[] = [ 0,1,6,7,8,9,10,11,0,0,0,0 ]
StackTop[] = [ 0,0,13,26,39 ]
StackImage[] = [ 0,73,74,75,76 ]
set redraw off
exitgame = 0
proc LoadFiles
proc  SetupSoundandFonts
proc  SetupSections
proc MakeCards
set window 0,0,1300,750

do
   wait 10
   proc Menu
   proc DealCards
   do
     wait 100
     set color 50,250,80
     cls
     set color 255,255,255
     proc InputLogic
     proc PrintText
     proc DisplayCards
     redraw
   until  keydown(27)=1
   exitgame = 1
until exitgame = 1

end
rem ********************************* END OF PROGRAM ***************************************
procedure LoadFiles()
 for a = 1 to 52
  load image a,"Data/Card.bmp"
  set image a
  set image colorkey a , true
 next
  set image primary
  load image 53,"Data/Heart1.png"
  load image 54,"Data/Heart3.png"
  load image 55,"Data/Diamond1.png"
  load image 56,"Data/Diamond4.png"
  load image 57,"Data/Club1.png"
  load image 58,"Data/Club3.png"
  load image 59,"Data/Spades20.bmp"
  load image 60,"Data/Spade3.png"
  load image 61,"Data/Jack1.png"
  load image 62,"Data/Jack2.png"
  load image 63,"Data/Jack3.png"
  load image 64,"Data/Jack4.png"
  load image 65,"Data/Queen1.png"
  load image 66,"Data/Queen2.png"
  load image 67,"Data/Queen3.png"
  load image 68,"Data/Queen4.png"
  load image 69,"Data/King1.png"
  load image 70,"Data/King2.png"
  load image 71,"Data/King3.png"
  load image 72,"Data/King4.png"
 rem load image 62,"Data/Card.bmp"
 for a = 53 to 60
      set image a
      set image colorkey a , true
 next
 for a = 73 to 76
  load image a,"Data/Card.bmp"
  set image a
  set image colorkey a , true
 next
  load image 77,"Data/button4.bmp"
  set image primary

endproc

procedure ShowCard( cardnumber , a)
 rem 0= Hide  1 = Show 2 = Show Back
 cards[cardnumber].show = a

endproc

procedure MakeCards()
 rank = 1 ; suit = 1 ; x = 50 ; y = 10
 for a = 1 to 52
   cards[a].card = a
   cards[a].rank = rank
   cards[a].suit = suit
   cards[a].x = x
   cards[a].y = y
   cards[a].show = 1
   cnt = cnt + 1
   x = x + 130
   rank = rank + 1
   if rank > 13 
      rank = 1
      suit = suit + 1
   endif
   if x > 900
     x = 50
     y = y + 30
   endif
 next
 proc PaintCards
 proc InitColumns
 proc ShuffleDeck1
 proc ShuffleDeck2

endproc

procedure InitColumns()
  y=10
  for a = 1 to 49
     column1[a].card = 0 ; column1[a].x = 50  ; column1[a].y = y
     column2[a].card = 0 ; column2[a].x = 180 ; column2[a].y = y
     column3[a].card = 0 ; column3[a].x = 310 ; column3[a].y = y
     column4[a].card = 0 ; column4[a].x = 440 ; column4[a].y = y
     column5[a].card = 0 ; column5[a].x = 570 ; column5[a].y = y
     column6[a].card = 0 ; column6[a].x = 700 ; column6[a].y = y
     column7[a].card = 0 ; column7[a].x = 830 ; column7[a].y = y
     y = y + 30
  next
 
endproc

procedure ShuffleDeck1()
   for a = 1 to 52
      deck1[a].card = a
      deck1[a].topcard = 1   
   next
endproc

procedure ShuffleDeck2()
   for a = 1 to 52
      deck2[a].card = a
      deck2[a].topcard = 1
   next
endproc

rem This deals cards from the deck object to the column objects
procedure DealCards()
          b = 1
          column1[1].card = deck1[1].card 
 for a = 2 to 52
     if a > 1  and a < 8 then  column2[b].card = deck1[a].card
     if a > 7  and a < 15 then column3[b].card = deck1[a].card
     if a > 14 and a < 23 then column4[b].card = deck1[a].card
     if a > 22 and a < 32 then column5[b].card = deck1[a].card
     if a > 31 and a < 42 then column6[b].card = deck1[a].card
     if a > 41 and a < 53 then column7[b].card = deck1[a].card
     b = b + 1
     if a = 7 or a = 14 or a = 22 or a =31 or a = 41 then b = 1
  next

endproc


procedure PaintCards()
 
  proc PaintRank
  proc PaintSuit
  proc PaintCenter
  proc PaintFaceCards
  proc PaintStacks
  set image primary
  set color 255,255,255
endproc

procedure PaintSuit()
 set color 255,255,255
 for a = 1 to 52
  suit = cards[a].suit
  set image a
  if suit = 1 
     draw image 53,4,22
     draw image 53,100,110
  endif
  if suit = 2 
     draw image 55,4,22
     draw image 55,98,108
  endif

  if suit = 3 
     draw image 57,4,22
     draw image 57,98,110
  endif
  if suit = 4 
     draw image 59,6,22
     draw image 59,100,108
  endif

 next
endproc

procedure PaintRank()
 set color 0,0,0
 for a = 1 to 52
  rank = cards[a].rank
  suit = cards[a].suit
  if rank <> 10 and rank <> 11   
    set image a
    if suit<3 then  set color 220,0,0
    proc Print 7,2,rank
    proc Print 102,124,rank
  endif
 set color 0,0,0
  if rank = 10 
    set image a
    if suit<3 then  set color 255,0,0
    proc Print 4,2,rank
    proc Print 93,124,rank
  endif
  if rank = 11   
    set image a
    if suit<3 then  set color 220,0,0
    proc Print 7,2,rank
    proc Print 105,124,rank
  endif

 next


endproc

procedure PaintCenter()
     pic = 54
   for a = 1 to 52
     rank = cards[a].rank
     suit = cards[a].suit
     if suit = 1 then pic = 54
     if suit = 2 then pic = 56
     if suit = 3 then pic = 58
     if suit = 4 then pic = 60
     set image a
    if rank = 1 then proc PaintAce suit,pic
    if rank = 2 then proc Paint2 suit,pic
    if rank = 3 then proc Paint3 suit,pic
    if rank = 4 then proc Paint4 suit,pic
    if rank = 5 then proc Paint5 suit,pic
    if rank = 6 then proc Paint6 suit,pic
    if rank = 7 then proc Paint7 suit,pic
    if rank = 8 then proc Paint8 suit,pic
    if rank = 9 then proc Paint9 suit,pic
    if rank = 10 then proc Paint10 suit,pic
   next
   
endproc

procedure PaintAce(suit,pic)
      if suit< 3 then set color 220,0,0
      if suit> 2 then set color 0,0,0
      draw image pic,50,50
      set color 255,255,255

endproc
procedure PaintStacks()

      set image 73
      draw image 54,50,60
      set image 74
      draw image 56,50,60
      set image 75
      draw image 58,50,60
      set image 76
      draw image 60,50,60
     
endproc

procedure Paint2(suit,pic)
   b = 0
   if suit< 4 then b = -2

   draw image pic,46+b,20
   draw image pic,46+b,80

endproc

procedure Paint3(suit,pic)
   b = 0
   if suit< 4 then b = -2
   draw image pic,46 + b,14
   draw image pic,46 + b,56
   draw image pic,46 + b,98

endproc

procedure Paint4(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic,25,25 + a 
   draw image pic,70,25 + a
   draw image pic,25,85 + a
   draw image pic,70,85 + a

endproc

procedure Paint5(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic,25,20 + a
   draw image pic,75,20 + a
   draw image pic,50,50 + a
   draw image pic,25,85 + a
   draw image pic,75,85 + a

endproc

procedure Paint6(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic,30,14 + a
   draw image pic,30,56 + a
   draw image pic,30,98 + a
   draw image pic,65,14 + a
   draw image pic,65,56 + a
   draw image pic,65,98 + a

endproc

procedure Paint7(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic,25,15 + a  
   draw image pic,25,65 + a
   draw image pic,45,40 + a
   draw image pic,65,15 + a
   draw image pic,65,65 + a
   draw image pic,25,100 + a
   draw image pic,65,100 + a

endproc

procedure Paint8(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic, 28,5 + a
   draw image pic, 28,40 + a
   draw image pic, 28,75 + a
   draw image pic, 28,110 + a
   draw image pic, 65,5 + a
   draw image pic, 65,40 + a
   draw image pic, 65,75 + a
   draw image pic, 65,110 + a

endproc

procedure Paint9(suit,pic)
   a = 0
   if suit = 1 then a = 4

   draw image pic, 26,5 + a
   draw image pic, 26,40 + a
   draw image pic, 26,75 + a
   draw image pic, 26,110 + a
   draw image pic, 67,5 + a
   draw image pic, 67,40 + a
   draw image pic, 67,75 + a
   draw image pic, 67,110 + a
   draw image pic,46,58 + a

endproc

procedure Paint10(suit,pic)
   a = 0
   if suit = 1 then a = 4
   draw image pic, 28,5 + a
   draw image pic, 28,40 + a
   draw image pic, 28,75 + a
   draw image pic, 28,110 + a
   draw image pic, 69,5 + a
   draw image pic, 69,40 + a
   draw image pic, 69,75 + a
   draw image pic, 69,110 + a
   draw image pic,48,22 + a
   draw image pic,48,92 + a

endproc

procedure PaintFaceCards()
 for a = 1 to 52
  rank = cards[a].rank
  suit = cards[a].suit  
  set image a
  if rank = 11 and suit = 1 then    draw image 61,20,10
  if rank = 11 and suit = 2 then    draw image 62,20,10
  if rank = 11 and suit = 3 then    draw image 63,20,10
  if rank = 11 and suit = 4 then    draw image 64,20,10
  if rank = 12 and suit = 1 then    draw image 65,20,10
  if rank = 12 and suit = 2 then    draw image 66,20,10
  if rank = 12 and suit = 3 then    draw image 67,20,10
  if rank = 12 and suit = 4 then    draw image 68,20,10
  if rank = 13 and suit = 1 then    draw image 69,20,10
  if rank = 13 and suit = 2 then    draw image 70,20,10
  if rank = 13 and suit = 3 then    draw image 71,20,10
  if rank = 13 and suit = 4 then    draw image 72,20,10

 next

endproc


procedure DisplayCardsa()
  set color 255, 255, 255
 for a = 1 to 52
  b = deck1[a].card
  if cards[b].show = 1 then  draw image a,cards[b].x  , cards[b].y 
 next
  draw image 77,1180,100
endproc

procedure DisplayCards()
  set color 255, 255, 255


 for a = 1 to 40

  b = column1[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column1[a].x  , column1[a].y
  b = column2[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column2[a].x  , column2[a].y
  b = column3[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column3[a].x  , column3[a].y
  b = column4[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column4[a].x  , column4[a].y
  b = column5[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column5[a].x  , column5[a].y
  b = column6[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column6[a].x  , column6[a].y
  b = column7[a].card
  if b>0 and cards[b].show = 1 then  draw image cards[b].card,column7[a].x  , column7[a].y
 
 next
    draw image StackImage[1], 1000,10
    draw image StackImage[2], 1000,180
    draw image StackImage[3], 1000,350
    draw image StackImage[4], 1000,520
    draw image 77,1180,100

    rem  draw image 54,1050,70
    rem  draw image 56,1050,250
    rem  draw image 58,1050,420
    rem  draw image 60,1050,590


endproc

procedure SetupGame()

endproc

 procedure SetupSections()
     rem     ColorHit = GetColorHit( CardHit )
     rem     RankHit = cards[CardHit].rank 
     rem     SuitHit = cards[CardHit].suit

   for a = 1 to 10
        section[a].ColorHit = 0
        section[a].RankHit = 0
        section[a].SuitHit = 0

   next
   
 endproc

 procedure Menu()
    a = 1
    play sound 10
    set color 180,180,255
   
    set caret 100,100

    wln  "                       This program is the easy version of the card game YUKON. "
    wln
    wln  "       The reason that I am making card games, is that I am tired of the versions that I have found that are   "
    wln  "     too hard to play. I want something that I can relax with.   "
    wln  "       I made it easy by turning the cards all faceup. I intend to make harder levels in the future to make it " 
    wln  "     more playable for beter players. "
    wln
    wln  "     RULES: "
    wln  "      Click on a card or several cards to pick it up. "
    wln  "      Click on a column to place it. "
    wln  "      The first 7 columns should be played by alternate color, King being first. Groups of cards can be moved "
    wln  "     regardless of sequence. "
    wln  "      The 4 stacks on the right should be played Ace first and then built up to King. "
    wln  "      Only Kings can be played to empty columns. "
    wln  
    wln
    wln
    wln  "          Click mouse to continue. "
    wln
    wln  "          http://rb23.yolasite.com "
    wln
  
    redraw

    while a = 1
      wait 20 
      if mousebutton(0,1) then a = 2
    wend   
  
    event = 2
    set font fnt1
   randomize time()
    play sound 8
endproc 

procedure SetupSoundandFonts()
  fnt1 = 0 ; fnt2 = 1 ; snd1 = 0 ; snd2 = 1
  
  load sound 1,"Data\Powerup.wav"
  load sound 2,"Data\Powerup40.wav"
  load sound 3,"Data\Powerup41.wav"
  load sound 4,"Data\Teleport2.wav"
  load sound 5,"Data\Teleport3.wav"
  load sound 6,"Data\Teleport.wav"
  load sound 7,"Data\Pickup_Coin3.wav"
  load sound 8,"Data\Fall.wav"
  load sound 9,"Data\Cricket.wav"
  load sound 10,"Data\boink2.wav"

  create font fnt1, "Calibri", 24
  create font fnt2, "arial", 48
  set font fnt1
endproc

 procedure PrintText()
   set color 20,20,25
   if page = 1
    set caret 5,550
    write "  SCORE  " ; write ; write ; wln score
    wln
    wln "  Hit Escape to end "
    wln "  program"
   endif
  rem play sound 8
   if page = 2
    set caret 5,550
     write "  SCORE  " ; write ; write ; wln score
     write "  mx = " ; write ; write ; wln mx     
     write "  my = " ; write ; write ; wln my
     write "  column = " ; write ; write ; wln column
     write "  row = " ; write ; write ; wln row
     write "  mb2 = " ; write ; write ; wln mb2
    set caret 150,550
     write "  test = " ; write ; write ; wln test
     write "  CardHit = " ; write ; write ; wln CardHit
     write "  ColorHit = " ; write ; write ; wln ColorHit
     write "  RankHit = " ; write ; write ; wln RankHit
     write "  SuitHit = " ; write ; write ; wln SuitHit
     write "  TopCard ?  " ; write ; write ; wln TopCard
    set caret 300,550
     write "  page = " ; write ; write ; wln page
     write "  phase = " ; write ; write ; wln phase
     write "  RowHit = " ; write ; write ; wln RowHit
     write "  ColumnHit = " ; write ; write ; wln ColumnHit
     write "  OldCard = " ; write ; write ; wln OldCard
     write "  ready = " ; write ; write ; wln ready
    set caret 450,550
     write "  N# of Cards = " ; write ; write ; wln noc
     write "  StackHit = " ; write ; write ; wln StackHit
     write "  CardHit1 = " ; write ; write ; wln CardHitA[1]
     write "  CardHit2 = " ; write ; write ; wln CardHitA[2]
     write "  RankHit1 = " ; write ; write ; wln RankHitA[1]
     write "  RankHit2 = " ; write ; write ; wln RankHitA[2]
    set caret 600,550
     write "  SuitHit1 = " ; write ; write ; wln SuitHitA[1]
     write "  SuitHit2 " ; write ; write ; wln SuitHitA[2]
     write "  ColorHit1 = " ; write ; write ; wln ColorHitA[1]
     write "  ColorHit2 = " ; write ; write ; wln ColorHitA[2]
     write "   = " ; write ; write ; wln phase
     write "   = " ; write ; write ; wln phase

   endif
   
   
 endproc

 procedure TogglePage()
     play sound 2
      page = page + 1
      if page>3 then page = 1
 endproc

 procedure InputLogic()
    m = 0
    value = 0
    if phase = 1 then proc SetVariables
    mx = mousex()                    
    my = mousey()
    LegalMove = 0              
    value = inkey()
    if value = 32 then proc TogglePage
    m = mousebutton(0,1) ; rem Left Mouse button
    if m > 0 then mb = 1
    m = mousebutton(1,1) ; rem Right Mouse button
    if m > 0 then mb = 2
    if mb = 1
       score = score + 1
       column = GetColumn(mx)
       row = GetRow(my)
       CardHit = GetCardHit( column, row )
       proc Update
       if CardHit > 0  
          ColorHit = GetColorHit( CardHit )
          RankHit = cards[CardHit].rank
          if phase = 1 then RankHitA[1] = cards[CardHit].rank
          if phase = 2 then RankHitA[2] = cards[CardHit].rank
          SuitHit = cards[CardHit].suit
          if phase = 1 then SuitHitA[1] = cards[CardHit].suit
          if phase = 2 then SuitHitA[2] = cards[CardHit].suit
          if phase = 1 then ColumnHitA[1] = column
          if phase = 1 then RowHitA[1] = RowHit
          if phase = 2 then LegalMove = IsItLegal()
         
          if phase = 1 and ready = 1 then proc GameLogic1
          if phase = 2 and ready = 1 and LegalMove = 1 then proc GameLogic2
          if phase = 2 and ready = 1 and LegalMove = 0 and FloatStackReady = 0 then proc  ReturnCard CardHitA[1],ColumnHitA[1],RowHitA[1]
          if phase = 2 and ready = 1 and LegalMove = 0 and FloatStackReady = 1 then proc  ReturnStack CardHitA[1],ColumnHitA[1],RowHitA[1]

       
          if phase > 2 then phase = 1
          ready = 1
          
       endif
       if phase = 2 and noc = 0 
          row = 1
          if ready = 1 then proc GameLogic2
       
          ready = 1
       endif
       if mx>1180 and my > 100 and my<150 and mx<1230 then proc Auto
       mb2 = mb
       mb = 0  
    endif
    

 endproc

 procedure Auto()
     play sound 7
     a = 0 ; b = 0 ; card1 = 0 ; card2 = 0 ; d=0
     proc Update
   for stk = 1 to 7
     if stack [stk] [1] > 0
         for a = 1 to 40
           b = stack [stk][a]
           c = stack [stk][a+1]
           if b>0 and c =0 then card2 = stack [stk] [a]
           if b>0 and c =0 then d = a  
         next
        for cnt = 1 to 4
            card1 = StackTop[ cnt ]
            if card2 = card1 + 1 and phase = 1 
             StackTop [ cnt ]  =  card2
             StackImage[ cnt ] =  card2 
             rem OldCard = 0
             proc AutoRemoveCard card2,stk,d
            endif
        next
     endif
   next
 endproc

 procedure AutoRemoveCard( crd,col,rw )
      h = 0
      if col = 1
         column1[rw].card = 0 ; h = 1
      endif

      if col = 2
         column2[rw].card = 0; h = 1
      endif

      if col = 3
         column3[rw].card = 0; h = 1
      endif

      if col = 4
         column4[rw].card = 0; h = 1
      endif

      if col = 5
         column5[rw].card = 0 ;  h = 1
      endif

      if col = 6
         column6[rw].card = 0; h = 1
      endif

      if col = 7
         column7[rw].card = 0; h = 1
      endif

 endproc

 procedure ReturnCard( crd,col,rw )
         h=0
         
      if col = 1
         column1[rw].card = crd ; h = 1
      endif

      if col = 2
         column2[rw].card = crd; h = 1
      endif

      if col = 3
         column3[rw].card = crd; h = 1
      endif

      if col = 4
         column4[rw].card = crd; h = 1
      endif

      if col = 5
         column5[rw].card = crd ;  h = 1
      endif

      if col = 6
         column6[rw].card = crd; h = 1
      endif

      if col = 7
         column7[rw].card = crd; h = 1
      endif
      if h = 1
          phase = 1
      endif


 endproc

 procedure ReturnStack(crd,col,rw)
              b = 0 ; position = 0
         
     for a = 1 to 49
         if col = 1 then b = column1[a].card
         if col = 2 then b = column2[a].card
         if col = 3 then b = column3[a].card
         if col = 4 then b = column4[a].card
         if col = 5 then b = column5[a].card
         if col = 6 then b = column6[a].card
         if col = 7 then b = column7[a].card
         if b = 0 then position = a
         if b = 0 then break
     next
     
    cnt = 1 
    for a = position to 49
         if col = 1 then column1[a].card =  FloatStack [3][cnt] 
         if col = 2 then column2[a].card =  FloatStack [3][cnt] 
         if col = 3 then column3[a].card =  FloatStack [3][cnt] 
         if col = 4 then column4[a].card =  FloatStack [3][cnt] 
         if col = 5 then column5[a].card =  FloatStack [3][cnt] 
         if col = 6 then column6[a].card =  FloatStack [3][cnt] 
         if col = 7 then column7[a].card =  FloatStack [3][cnt] 
     cnt = cnt + 1
     next
     FloatStackReady = 0

     phase = 1


 endproc

 procedure SetVariables()
    for a = 1 to 9
      CardHitA[a] = 0
      ColorHitA[a] = 0
      RankHitA[a] = 0
      SuitHitA[a] = 0
    next
 endproc
 function IsItLegal()
  rem  CardHitA[10]
  rem ColorHitA[10]
  rem RankHitA[10]
  rem SuitHitA[10]
      
      a = 0 ; c = 0
      b = ColorHitA[1] + ColorHitA[2]
      if RankHitA[1] + 1 = RankHitA[2] then c = 1
      if b = 3 and c = 1 then a = 1
      
      if phase = 1 then a = 1
      return a
 endfunc

 procedure GameLogic1()
      rem  TempColumn?[50]

      if TopCard = 1 then proc RemoveCard CardHit,ColumnHit,RowHit
      ready = 0
      if TopCard = 0 then proc RemoveStack CardHit,ColumnHit,RowHit
      if TopCard = 0 then FloatStackReady = 1

 endproc

 procedure GameLogic2()
      if noc = 0 then RowHit = 0
      if TopCard = 1 and ColumnHit < 8 and RowHit > 0 and FloatStackReady = 0 then proc AddCard OldCard,ColumnHit,RowHit
      if TopCard = 1 and ColumnHit < 8 and RowHit > 0 and FloatStackReady = 1 then proc AddStack OldCard,ColumnHit,RowHit
      if ColumnHit = 8 then proc PushStack

      if ColumnHit < 8 then StackHit = 0
      if TopCard = 1 and ColumnHit < 8 and RowHit = 0 and RankHit = 13 and FloatStackReady = 0 then proc AddKing OldCard,ColumnHit,RowHit
      if TopCard = 1 and ColumnHit < 8 and RowHit = 0 and FloatStackReady = 1 and RankHit = 13 then proc AddStack OldCard,ColumnHit,RowHit

      if TopCard = 1 and ColumnHit < 8 and RowHit = 0 and FloatStackReady = 0 and RankHit < 13 then proc ReturnCard CardHitA[1],ColumnHitA[1],RowHitA[1]
      if TopCard = 1 and ColumnHit < 8 and RowHit = 0 and FloatStackReady = 1 and RankHit < 13 then proc ReturnStack CardHitA[1],ColumnHitA[1],RowHitA[1]


    rem  FloatStackReady = 0
       ready = 0
 endproc

 
 
 
 procedure RemoveCard( crd,col,rw)
      rem play sound 4
      h=0
      if col = 1
         column1[rw].card = 0 ; h = 1
      endif

      if col = 2
         column2[rw].card = 0; h = 1
      endif

      if col = 3
         column3[rw].card = 0; h = 1
      endif

      if col = 4
         column4[rw].card = 0; h = 1
      endif

      if col = 5
         column5[rw].card = 0 ;  h = 1
      endif

      if col = 6
         column6[rw].card = 0; h = 1
      endif

      if col = 7
         column7[rw].card = 0; h = 1
      endif
      if h = 1
         OldCard = crd
         phase = 2
      endif
 endproc

 procedure AddKing(crd,col,rw)
         h=0
      play sound 1
         rw = rw + 1
      if col = 1
         column1[rw].card = crd ; h = 1
      endif

      if col = 2
         column2[rw].card = crd; h = 1
      endif

      if col = 3
         column3[rw].card = crd; h = 1
      endif

      if col = 4
         column4[rw].card = crd; h = 1
      endif

      if col = 5
         column5[rw].card = crd ;  h = 1
      endif

      if col = 6
         column6[rw].card = crd; h = 1
      endif

      if col = 7
         column7[rw].card = crd; h = 1
      endif
     
      if h = 1
         OldCard = 0
         phase = 1
      endif
   

 endproc

 procedure AddCard(crd,col,rw)
      play sound 7
         h=0
         rw = rw + 1
      if col = 1
         column1[rw].card = crd ; h = 1
      endif

      if col = 2
         column2[rw].card = crd; h = 1
      endif

      if col = 3
         column3[rw].card = crd; h = 1
      endif

      if col = 4
         column4[rw].card = crd; h = 1
      endif

      if col = 5
         column5[rw].card = crd ;  h = 1
      endif

      if col = 6
         column6[rw].card = crd; h = 1
      endif

      if col = 7
         column7[rw].card = crd; h = 1
      endif
     
      if h = 1
         OldCard = 0
         phase = 1
      endif
      
 endproc

 procedure ClearStacks()
  rem FloatStack [20][50]
  for col = 1 to 7
     for a = 1 to 49
         if col = 1 then FloatStack [1][a] = 0
         if col = 2 then FloatStack [2][a] = 0
         if col = 3 then FloatStack [3][a] = 0
         if col = 4 then FloatStack [4][a] = 0
         if col = 5 then FloatStack [5][a] = 0
         if col = 6 then FloatStack [6][a] = 0
         if col = 7 then FloatStack [7][a] = 0
     next
  next

 endproc
 

 
 procedure RemoveStack(crd,col,rw)
  rem FloatStack [20][50]
     play sound 5
     proc ClearStacks
     for a = 1 to 49
         if col = 1 then FloatStack [1][a] = column1[a].card
         if col = 2 then FloatStack [1][a] = column2[a].card
         if col = 3 then FloatStack [1][a] = column3[a].card
         if col = 4 then FloatStack [1][a] = column4[a].card
         if col = 5 then FloatStack [1][a] = column5[a].card
         if col = 6 then FloatStack [1][a] = column6[a].card
         if col = 7 then FloatStack [1][a] = column7[a].card
     next
 
     c = 0 ; cnt = 1
     for a = 1 to 49
         b = FloatStack [1][a]
         if b = crd then c = 1
        if c = 0 and b > 0 then FloatStack [2][a] = b
        if c = 1 and b > 0 then FloatStack [3][cnt] = b
        if c = 1 then cnt = cnt + 1
     next
  
     for a = 1 to 49
         if col = 1 then column1[a].card = FloatStack [2][a] 
         if col = 2 then column2[a].card = FloatStack [2][a] 
         if col = 3 then column3[a].card = FloatStack [2][a] 
         if col = 4 then column4[a].card = FloatStack [2][a] 
         if col = 5 then column5[a].card = FloatStack [2][a] 
         if col = 6 then column6[a].card = FloatStack [2][a] 
         if col = 7 then column7[a].card = FloatStack [2][a] 
     next
     phase = 2
 endproc

 procedure AddStack(crd,col,rw)
         b = 0 ; position = 0
         play sound 7
     for a = 1 to 49
         if col = 1 then b = column1[a].card
         if col = 2 then b = column2[a].card
         if col = 3 then b = column3[a].card
         if col = 4 then b = column4[a].card
         if col = 5 then b = column5[a].card
         if col = 6 then b = column6[a].card
         if col = 7 then b = column7[a].card
         if b = 0 then position = a
         if b = 0 then break
     next
     
    cnt = 1 
    for a = position to 49
         if col = 1 then column1[a].card =  FloatStack [3][cnt] 
         if col = 2 then column2[a].card =  FloatStack [3][cnt] 
         if col = 3 then column3[a].card =  FloatStack [3][cnt] 
         if col = 4 then column4[a].card =  FloatStack [3][cnt] 
         if col = 5 then column5[a].card =  FloatStack [3][cnt] 
         if col = 6 then column6[a].card =  FloatStack [3][cnt] 
         if col = 7 then column7[a].card =  FloatStack [3][cnt] 
     cnt = cnt + 1
     next
     FloatStackReady = 0

     phase = 1
 endproc

 procedure PushStack()
     StackHit = 0
     play sound 6
   rem  StackImage[] = [ 0,73,74,75,76 ]
   rem  StackTop[5] = [ 0,0,13,26,39 ] 
     if my > 10 then StackHit = 1
     if my > 180 then StackHit = 2
     if my > 350 then StackHit = 3
     if my > 520 then StackHit = 4
     a = StackTop[ StackHit ]
     if OldCard = a+1
        StackTop [ StackHit ] = OldCard
        StackImage[ StackHit ] = OldCard
        OldCard = 0
        phase = 1
     else
       if FloatStackReady = 0 then proc  ReturnCard CardHitA[1],ColumnHitA[1],RowHitA[1]
       if FloatStackReady = 1 then proc  ReturnStack CardHitA[1],ColumnHitA[1],RowHitA[1]

        OldCard = 0
        phase = 1

     endif
 endproc

 procedure Update()
     cnt = 0 ; col = 1
  for col = 1 to 7
     for a = 1 to 49
         if col = 1 then stack [1][a] = column1[a].card
         if col = 2 then stack [2][a] = column2[a].card
         if col = 3 then stack [3][a] = column3[a].card
         if col = 4 then stack [4][a] = column4[a].card
         if col = 5 then stack [5][a] = column5[a].card
         if col = 6 then stack [6][a] = column6[a].card
         if col = 7 then stack [7][a] = column7[a].card
     next
  next
  for col = 1 to 7
     cnt = 0
     for a = 1 to 49
        if stack [col][a] > 0 then cnt = cnt + 1
        NumberOfCards[col] = cnt

     next
  next
  noc = NumberOfCards[ColumnHit]
 
 endproc

 procedure Print( x,y,n)  
 
   set caret x,y
   if n>1 and n < 11 then write str$(n)
   if n = 1 then write "A"
   if n = 11 then write "J"
   if n = 12 then write "Q"
   if n = 13 then write "K"
 
 endproc

 function GetColumn( x )
     col = 0
     if x > 50 then col = 1
     if x > 180 then col = 2
     if x > 310 then col = 3
     if x > 440 then col = 4
     if x > 570 then col = 5
     if x > 700 then col = 6
     if x > 830 then col = 7
     if x > 960 then col = 8
     return col
 endfunc

 function GetRow( y )
     rw = 0
     if y > 10 then rw = 1
     if y > 40 then rw = 2
     if y > 70 then rw = 3
     if y > 100 then rw = 4
     if y > 130 then rw = 5
     if y > 160 then rw = 6
     if y > 190 then rw = 7
     if y > 220 then rw = 8
     if y > 250 then rw = 9
     if y > 280 then rw = 10
     if y > 310 then rw = 11
     if y > 340 then rw = 12
     if y > 370 then rw = 13
     if y > 400 then rw = 14
     if y > 430 then rw = 15
     if y > 460 then rw = 16
     if y > 490 then rw = 17
     if y > 520 then rw = 18
     if y > 550 then rw = 19
     if y > 580 then rw = 20
     if y > 610 then rw = 21
     if y > 640 then rw = 22
     if y > 670 then rw = 23
     if y > 700 then rw = 24
     if y > 730 then rw = 25
     return rw
endfunc

function GetCardHit( col, rw )
     a = 0 ; rw2 = rw ; TopCard = 0
   while a<1 and rw2 > 0
     TopCard = 0
     ColumnHit = col
     RowHit = rw
    
     if col = 1 
          a = column1[rw2].card
          if column1[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif
     endif
     if col = 2 
          a = column2[rw2].card
          if column2[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif

     endif
     if col = 3 
          a = column3[rw2].card
          if column3[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif
       
     endif
     if col = 4 
          a = column4[rw2].card
          if column4[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif

     endif
     if col = 5 
          a = column5[rw2].card
          if column5[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif

     endif
     if col = 6 
          a = column6[rw2].card
          if column6[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif

     endif
     if col = 7 
          a = column7[rw2].card
          if column7[rw2+ 1].card = 0 
              TopCard = 1
              RowHit = rw2
          endif

     endif
     rw2 = rw2 -1
    wend
     if phase = 1 then CardHitA[1] = a
     if phase = 2 then CardHitA[2] = a
     return a
endfunc

function GetColorHit( b )
     a = 0
     if b > 0 then a = 1
     if b > 26 then a = 2
     if phase = 1 then ColorHitA[1] = a
     if phase = 2 then ColorHitA[2] = a

     return a
endfunc


function GetX( col, rw )
     x = 0

     return x
endfunc

function GetY( col, rw )
     y = 0

     return y
endfunc
