Differences between revisions 4 and 5
Revision 4 as of 2008-12-26 15:42:50
Size: 4304
Editor: anonymous
Comment:
Revision 5 as of 2008-12-26 15:51:38
Size: 5298
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 67: Line 67:
Card Table creates the form and picture control onto which the cards are drawn.

{{{
∇ CardTable
                                                
⍝Create a form to hold the picture control
⎕wself←'fm' ⎕wi 'Create' 'Form'
⎕wi 'scale' 5
⎕wi 'color' (40 157 47) ¯1
⎕wi 'style' 16
⎕wi 'size' 400 600
⎕wi 'caption' 'Card Table'
⎕wi 'visible' 0
                                                
⍝Create a picture control to hold the card table
⎕wself←'fm.pic' ⎕wi 'New' 'Picture'
⎕wi 'scale' 5
⎕wi 'where' 0 0 400 600
⎕wi 'imagesize' 400 600
⎕wi 'border' 0
 ∇
}}}

Playing Cards - Under Construction

Having read the SolitaireGame article by StephenTaylor I thought I would set out a series of functions which use the creation of playing cards to demonstrate APL's ability to use data stored in third party resources, native files and the workspace and to manipulate the data using boolean patterns. APL is particularly good at exploiting data patterns.

The functions are written in APL+WIN but they should be readily convertible into any GUI enabled interpreter as they only use a simple form and a picture control for the graphics and ⎕wcall for making low level windows calls.

The main function Solitaire creates a graphical card table complete with the initial deal. See Stephen's article for the logic underpinning the SolitaireGame itself. The functions that follow implement the data handling involved and can be used to create any card game. More importantly they demonstrate some of APL's data handling capabilities. I have deliberately written the functions in what I call "long hand APL" so that they are easy to read and understand.

 ∇  Solitaire;i;j;cbk;n;bkg;ep;c                               
                                                           
⍝Display Card Table                                        
CardTable                                                  
'fm' ⎕wi 'caption' 'Solitaire'                             
                                                           
⍝Get the card back bitmap                                  
cbk←MakeCardDLL 62                                         
                                                           
⍝Get the empty pile bitmap                                 
ep←MakeCardDLL 53                                          
                                                           
⍝Select 8 cards at random                                  
c←10?52                                                    
                                                           
⍝Display discard piles                                     
:for i :in ⍳4                                              
    bkg←(∼∆bkg)×⎕wi 'Get' 7 (180+86×i) 96 71               
    ⎕wi 'Put' (bkg+∆bkg×(1↑,bkg)×∼ep=0) 7 (180+86×i)       
:endfor                                                    
                                                           
⍝Display draw pile                                         
:for i :in ⍳3                                              
    bkg←(∼∆bkg)×⎕wi 'Get' (5+2×i) (5+2×i) 96 71            
    ⎕wi 'Put' (bkg+cbk) (5+2×i) (5+2×i)                    
:endfor                                                    
                                                           
⍝Display first three cards drawn                           
:for i :in ⍳3                                              
    bkg←(∼∆bkg)×⎕wi 'Get' (7+2×i) (80+15×i) 96 71          
    ⎕wi 'Put' (bkg+MakeCardDLL c[i]) (7+2×i) (80+15×i)     
:endfor                                                    
                                                           
⍝Display the seven initial deal piles                      
:for i :in ⍳7                                              
                                                           
⍝Face down cards                                           
    :for j :in ⍳i-1                                        
        bkg←(∼∆bkg)×⎕wi 'Get'(130+3×j) (7+86×i-1) 96 71    
        ⎕wi 'Put' (bkg+cbk) (130+3×j) (7+86×i-1)           
    :endfor                                                
                                                           
⍝Face up cards                                             
    bkg←(∼∆bkg)×⎕wi 'Get' (130+3×i) (7+86×i-1) 96 71       
    ⎕wi 'Put' (bkg+MakeCardDLL c[i+3]) (130+3×i) (7+86×i-1)
:endfor                                                    
                                                           
'fm' ⎕wi 'visible' 1                           
                                                                

This is what you get:

solitaire.jpg

Card Table creates the form and picture control onto which the cards are drawn.

∇ CardTable                                       
                                                
⍝Create a form to hold the picture control      
⎕wself←'fm' ⎕wi 'Create' 'Form'                 
⎕wi 'scale' 5                                   
⎕wi 'color' (40 157 47) ¯1                      
⎕wi 'style' 16                                  
⎕wi 'size' 400 600                              
⎕wi 'caption' 'Card Table'                      
⎕wi 'visible' 0                                 
                                                
⍝Create a picture control to hold the card table
⎕wself←'fm.pic' ⎕wi 'New' 'Picture'             
⎕wi 'scale' 5                                   
⎕wi 'where' 0 0 400 600                         
⎕wi 'imagesize' 400 600                         
⎕wi 'border' 0                                  

Author: GrahamSteer

PlayingCards (last edited 2012-02-18 15:11:38 by KaiJaeger)