home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / sol-games / maze.scm < prev    next >
Encoding:
Text File  |  2006-08-22  |  3.9 KB  |  157 lines

  1. ; AisleRiot - maze.scm
  2. ; Copyright (C) 2000 Matthew Wilcox <willy@linuxcare.com>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define card '())
  20.  
  21. (define (add-line)
  22.   (add-normal-slot '())
  23.   (add-normal-slot '())
  24.   (add-normal-slot '())
  25.   (add-normal-slot '())
  26.   (add-normal-slot '())
  27.   (add-normal-slot '())
  28.   (add-normal-slot '())
  29.   (add-normal-slot '())
  30.   (add-normal-slot '())
  31. )
  32.  
  33. (define (new-game)
  34.   (initialize-playing-area)
  35.   (set-ace-low)
  36.   (make-standard-deck)
  37.   (shuffle-deck)
  38.  
  39.   (add-normal-slot DECK)
  40.   (add-normal-slot '())
  41.   (add-normal-slot '())
  42.   (add-normal-slot '())
  43.   (add-normal-slot '())
  44.   (add-normal-slot '())
  45.   (add-normal-slot '())
  46.   (add-normal-slot '())
  47.   (add-normal-slot '())
  48.   (add-carriage-return-slot)
  49.  
  50.   (add-line)
  51.   (add-carriage-return-slot)
  52.   (add-line)
  53.   (add-carriage-return-slot)
  54.   (add-line)
  55.   (add-carriage-return-slot)
  56.   (add-line)
  57.   (add-carriage-return-slot)
  58.   (add-line)
  59.  
  60.   (deal-cards-face-up 0 '(1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 18 19
  61.                 20 21 22 23 24 25 26 27 28 29 30 31 32 33 
  62.                 34 35 36 37 38 39 40 41 42 43 44 45 46 47 
  63.                 48 49 50 51 52 53))
  64.  
  65.   (make-visible-top-card 0)
  66.   (eliminate-kings 53)
  67.  
  68.   (calculate-score)
  69.  
  70.   (list 9 6))
  71.  
  72. (define (eliminate-kings slot)
  73.   (and (not (empty-slot? slot))
  74.        (= (get-value (get-top-card slot)) king)
  75.        (remove-card slot))
  76.   (and (> slot 0)
  77.        (eliminate-kings (- slot 1))))
  78.  
  79. (define (button-pressed slot-id card-list)
  80.   #t)
  81.  
  82. (define (suit-next? first second)
  83.   (and (= (get-suit first)
  84.       (get-suit second))
  85.        (= (+ 1 (get-value first))
  86.       (get-value second))))
  87.  
  88. (define (card-next? lower higher)
  89.   (or (and (= ace (get-value higher))
  90.        (= queen (get-value lower)))
  91.       (suit-next? lower higher)))
  92.  
  93. (define (button-released start-slot card-list end-slot)
  94.   (set! card (car card-list))
  95.   (and (empty-slot? end-slot)
  96.        (or (if (= end-slot 0)
  97.            (= ace (get-value card))
  98.            (and (not (empty-slot? (- end-slot 1)))
  99.             (card-next? (get-top-card (1- end-slot)) card)))
  100.        (if (= end-slot 53)
  101.            (= queen (get-value card))
  102.            (and (not (empty-slot? (1+ end-slot)))
  103.             (card-next? card (get-top-card (1+ end-slot))))))
  104.        (add-card! end-slot (car card-list))))
  105.  
  106. (define (button-clicked slot-id)
  107.   #f)
  108.  
  109. (define (button-double-clicked slot-id)
  110.   #f)
  111.  
  112. (define (get-full-card slot)
  113.   (if (empty-slot? slot)
  114.       (get-full-card (1+ slot))
  115.       (get-top-card slot)))
  116.  
  117. (define (calculate-score)
  118.   (set! card (get-full-card 0))
  119.   (if (= (get-value card) ace)
  120.       (set-score! 1)
  121.       (set-score! 0))
  122.   (calculate-score-helper 1 card)
  123.   (= (get-score) 48) ; 48 cards in the pack
  124. )
  125.  
  126. (define (calculate-score-helper slot prev)
  127.   (or (= slot 54)
  128.       (and (empty-slot? slot)
  129.        (calculate-score-helper (1+ slot) prev))
  130.       (and (set! card (get-top-card slot))
  131.        (card-next? prev card)
  132.        (add-to-score! 1)
  133.        #f)
  134.       (calculate-score-helper (1+ slot) card)))
  135.  
  136. (define (game-won)
  137.   (calculate-score))
  138.  
  139. (define (game-over)
  140.   (not (game-won)))
  141.  
  142. (define (get-hint)
  143.   (list 0 (_"Aim to place the suits in the order which fits the current layout most naturally.")))
  144.  
  145. (define (get-options) 
  146.   #f)
  147.  
  148. (define (apply-options options) 
  149.   #f)
  150.  
  151. (define (timeout) 
  152.   #f)
  153.  
  154. (set-lambda new-game button-pressed button-released button-clicked
  155. button-double-clicked game-over game-won get-hint get-options
  156. apply-options timeout)
  157.