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

  1. ; AisleRiot - escalator.scm
  2. ; Copyright (C) 2001, 2003 Rosanna Yuen <zana@webwynk.net>
  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 covering-vector '#(
  20.    (2 . (3 . 4))
  21.    (3 . (5 . 6))
  22.    (4 . (6 . 7))
  23.    (5 . (8 . 9))
  24.    (6 . (9 . 10))
  25.    (7 . (10 . 11))
  26.    (8 . (12 . 13))
  27.    (9 . (13 . 14))
  28.    (10 . (14 . 15))
  29.    (11 . (15 . 16))
  30.    (12 . (17 . 18))
  31.    (13 . (18 . 19))
  32.    (14 . (19 . 20))
  33.    (15 . (20 . 21))
  34.    (16 . (21 . 22))
  35.    (17 . (23 . 24))
  36.    (18 . (24 . 25))
  37.    (19 . (25 . 26))
  38.    (20 . (26 . 27))
  39.    (21 . (27 . 28))
  40.    (22 . (29 . 28))))
  41.  
  42. (define (covering slot-id) (if (and (<= slot-id 22)
  43.                     (>= slot-id 2))
  44.                    (cdr (vector-ref covering-vector (- slot-id 2)))))
  45.  
  46. (define (new-game)
  47.   (initialize-playing-area)
  48.   (set-ace-low)
  49.   (make-standard-deck)
  50.   (shuffle-deck)
  51.  
  52.   (add-normal-slot DECK)
  53.   (add-normal-slot '())
  54.  
  55.   (add-blank-slot)
  56.   (add-normal-slot '())
  57.  
  58.   (add-carriage-return-slot)
  59.   (set! VERTPOS (- VERTPOS 0.5))
  60.   (set! HORIZPOS (+ HORIZPOS 0.5))
  61.   (add-blank-slot)
  62.   (add-blank-slot)
  63.   (add-normal-slot '())
  64.   (add-normal-slot '())
  65.  
  66.   (add-carriage-return-slot)
  67.   (set! VERTPOS (- VERTPOS 0.5))
  68.   (add-blank-slot)
  69.   (add-blank-slot)
  70.   (add-normal-slot '())
  71.   (add-normal-slot '())
  72.   (add-normal-slot '())
  73.  
  74.   (add-carriage-return-slot)
  75.   (set! VERTPOS (- VERTPOS 0.5))
  76.   (set! HORIZPOS (+ HORIZPOS 0.5))
  77.   (add-blank-slot)
  78.   (add-normal-slot '())
  79.   (add-normal-slot '())
  80.   (add-normal-slot '())
  81.   (add-normal-slot '())
  82.  
  83.   (add-carriage-return-slot)
  84.   (set! VERTPOS (- VERTPOS 0.5))
  85.   (add-blank-slot)
  86.   (add-normal-slot '())
  87.   (add-normal-slot '())
  88.   (add-normal-slot '())
  89.   (add-normal-slot '())
  90.   (add-normal-slot '())
  91.  
  92.   (add-carriage-return-slot)
  93.   (set! VERTPOS (- VERTPOS 0.5))
  94.   (set! HORIZPOS (+ HORIZPOS 0.5))
  95.   (add-normal-slot '())
  96.   (add-normal-slot '())
  97.   (add-normal-slot '())
  98.   (add-normal-slot '())
  99.   (add-normal-slot '())
  100.   (add-normal-slot '())
  101.  
  102.   (add-carriage-return-slot)
  103.   (set! VERTPOS (- VERTPOS 0.5))
  104.   (add-normal-slot '())
  105.   (add-normal-slot '())
  106.   (add-normal-slot '())
  107.   (add-normal-slot '())
  108.   (add-normal-slot '())
  109.   (add-normal-slot '())
  110.   (add-normal-slot '())
  111.  
  112.   (deal-cards-face-up 0 '(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  113.                 19 20 21 22 23 24 25 26 27 28 29))
  114.  
  115.   (give-status-message)
  116.  
  117.   (list 7 4))
  118.  
  119. (define (give-status-message)
  120.   (set-statusbar-message (get-stock-no-string)))
  121.  
  122. (define (get-stock-no-string)
  123.   (string-append (_"Stock left:") " "
  124.          (number->string (length (get-cards 0)))))
  125.  
  126. (define (button-pressed slot-id card-list)
  127.   (and (not (empty-slot? slot-id))
  128.        (available? slot-id)
  129.        (= (length card-list) 1)))
  130.  
  131. (define (available? slot-id)
  132.   (cond ((or (= slot-id 0)
  133.          (= slot-id 1))
  134.      #f)
  135.     ((<= slot-id 22) ; Last coverable cell
  136.      (and (empty-slot? (car (covering slot-id)))
  137.           (empty-slot? (cdr (covering slot-id)))))))
  138.  
  139. (define (droppable? start-slot card-list end-slot)
  140.   (and (= end-slot 1)
  141.        (not (empty-slot? 1))
  142.        (or (= (get-value (get-top-card 1))
  143.           (+ 1 (get-value (car card-list))))
  144.        (= (+ 1 (get-value (get-top-card 1)))
  145.           (get-value (car card-list)))
  146.        (and (= king (get-value (get-top-card 1)))
  147.         (= ace (get-value (car card-list))))
  148.        (and (= ace (get-value (get-top-card 1)))
  149.         (= king (get-value (car card-list)))))))
  150.  
  151. (define (button-released start-slot card-list end-slot)
  152.   (if (droppable? start-slot card-list end-slot)
  153.       (begin (add-to-score! 1)
  154.          (move-n-cards! start-slot end-slot card-list))
  155.       #f))
  156.  
  157. (define (play-card slot-id)
  158.   (cond ((= slot-id 0)
  159.      (if (not (empty-slot? 0))
  160.          (deal-cards-face-up 0 '(1))
  161.          #f))
  162.     ((and (not (= slot-id 1))
  163.           (not (empty-slot? slot-id))
  164.           (available? slot-id)
  165.           (not (empty-slot? 1))
  166.           (or (= (get-value (get-top-card 1))
  167.              (+ 1 (get-value (get-top-card slot-id))))
  168.           (= (+ 1 (get-value (get-top-card 1)))
  169.              (get-value (get-top-card slot-id)))
  170.           (and (= king (get-value (get-top-card 1)))
  171.                (= ace (get-value (get-top-card slot-id))))
  172.           (and (= ace (get-value (get-top-card 1)))
  173.                (= king (get-value (get-top-card slot-id))))))
  174.      (and (add-to-score! 1)
  175.           (deal-cards slot-id '(1))))
  176.     (#t #f)))
  177.  
  178. ;; Single-clicking isn't sane in click-to-move more, so we mostly ignore it 
  179. ;; in that case.
  180. (define (button-clicked slot-id)
  181.   (if (and (click-to-move?) 
  182.        (> slot-id 1))
  183.       #f
  184.       (play-card slot-id)))
  185.  
  186. (define (button-double-clicked slot-id)
  187.   (play-card slot-id))
  188.  
  189. (define (game-continuable)
  190.   (give-status-message)
  191.   (and (not (game-won))
  192.        (get-hint)))
  193.  
  194. (define (game-won)
  195.   (empty-slot? 2))
  196.  
  197. (define (playable? check-slot)
  198.   (if (or (> check-slot 29)
  199.       (empty-slot? 1))
  200.       #f
  201.       (if (and (not (empty-slot? check-slot))
  202.            (available? check-slot)
  203.            (or (= (get-value (get-top-card 1))
  204.               (+ 1 (get-value (get-top-card check-slot))))
  205.            (= (+ 1 (get-value (get-top-card 1)))
  206.               (get-value (get-top-card check-slot)))
  207.            (and (= king (get-value (get-top-card 1)))
  208.             (= ace (get-value (get-top-card check-slot))))
  209.            (and (= ace (get-value (get-top-card 1)))
  210.             (= king (get-value (get-top-card check-slot)))0)))
  211.       (list 1 
  212.         (get-name (get-top-card check-slot))
  213.         (get-name (get-top-card 1)))
  214.       (playable? (+ 1 check-slot)))))
  215.  
  216. (define (dealable?)
  217.   (and (not (empty-slot? 0))
  218.        (list 0 (_"Deal a card"))))
  219.  
  220. (define (get-hint)
  221.   (or (playable? 2)
  222.       (dealable?)))
  223.  
  224. (define (get-options) 
  225.   #f)
  226.  
  227. (define (apply-options options) 
  228.   #f)
  229.  
  230. (define (timeout) 
  231.   #f)
  232.  
  233. (set-features droppable-feature)
  234.  
  235. (set-lambda new-game button-pressed button-released button-clicked
  236. button-double-clicked game-continuable game-won get-hint get-options
  237. apply-options timeout droppable?)
  238.