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

  1. ; AisleRiot - scuffle.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 (new-game)
  20.   (initialize-playing-area)
  21.   (set-ace-low)
  22.   (set! DECK (make-deck-list-ace-low 2 2 club))
  23.   (shuffle-deck)
  24.  
  25.   (add-normal-slot DECK)
  26.   (add-blank-slot)
  27.   (add-normal-slot '())
  28.   (add-normal-slot '())
  29.   (add-normal-slot '())
  30.   (add-normal-slot '())
  31.   (add-carriage-return-slot)
  32.   (add-blank-slot)
  33.   (add-blank-slot)
  34.   (add-normal-slot '())
  35.   (add-normal-slot '())
  36.   (add-normal-slot '())
  37.   (add-normal-slot '())
  38.   
  39.   (add-card! 1 (make-visible (make-card ace club)))
  40.   (add-card! 2 (make-visible (make-card ace diamond)))
  41.   (add-card! 3 (make-visible (make-card ace heart)))
  42.   (add-card! 4 (make-visible (make-card ace spade)))
  43.  
  44.   (give-status-message)
  45.  
  46.   (list 6 2)
  47. )
  48.  
  49. (define (give-status-message)
  50.   (set-statusbar-message (string-append (get-stock-no-string)
  51.                     "   "
  52.                     (get-redeals-string))))
  53.  
  54. (define (get-redeals-string)
  55.   (string-append (_"Redeals left:") " "
  56.          (number->string (- 2 FLIP-COUNTER))))
  57.  
  58. (define (get-stock-no-string)
  59.   (string-append (_"Stock left:") " " 
  60.          (number->string (length (get-cards 0)))))
  61.  
  62. (define (button-pressed slot-id card-list)
  63.   (and (not (empty-slot? slot-id))
  64.        (> slot-id 4)))
  65.  
  66. (define (droppable? start-slot card-list end-slot)
  67.   (and (< end-slot 5)
  68.        (> end-slot 0)
  69.        (= (get-value (car card-list))
  70.           (+ 1 (get-value (get-top-card end-slot))))))
  71.  
  72.  
  73. (define (button-released start-slot card-list end-slot)
  74.   (and (droppable? start-slot card-list end-slot)
  75.        (move-n-cards! start-slot end-slot card-list)
  76.        (add-to-score! 1)))
  77.  
  78. (define (deal-cards-out slot)
  79.   (if (and (< slot 9)
  80.        (not (empty-slot? 0)))
  81.       (and (deal-cards-face-up 0 (list slot))
  82.        (deal-cards-out (+ 1 slot)))
  83.       #t))
  84.  
  85. (define (button-clicked slot-id)
  86.   (and (= slot-id 0)
  87.        (or (and (not (empty-slot? 0))
  88.         (deal-cards-out 5))
  89.        (and (< FLIP-COUNTER 2)
  90.         (set! FLIP-COUNTER (+ 1 FLIP-COUNTER))
  91.         (flip-deck 0 5)
  92.         (flip-deck 0 6)
  93.         (flip-deck 0 7)
  94.         (flip-deck 0 8)
  95.         (shuffle-deck)))))
  96.  
  97. (define (check-end-slot? slot1 slot2)
  98.   (if (and (not (empty-slot? slot1))
  99.        (= (get-value (get-top-card slot1))
  100.           (+ 1 (get-value (get-top-card slot2)))))
  101.       (begin
  102.     (deal-cards slot1 (list slot2))
  103.     (add-to-score! 1))
  104.       (if (< slot2 4)
  105.       (check-end-slot? slot1 (+ 1 slot2))
  106.       #f)))
  107.  
  108. (define (button-double-clicked slot-id)
  109.   (and (> slot-id 4)
  110.        (check-end-slot? slot-id 1)))
  111.  
  112. (define (game-continuable)
  113.   (give-status-message)
  114.   (and (not (game-won))
  115.        (get-hint)))
  116.  
  117. (define (game-won)
  118.   (and (empty-slot? 0)
  119.        (empty-slot? 5)
  120.        (empty-slot? 6)
  121.        (empty-slot? 7)
  122.        (empty-slot? 8)))
  123.  
  124. (define (movable? slot1 slot2)
  125.   (if (= slot1 9)
  126.       #f
  127.       (if (or (= slot2 5)
  128.           (empty-slot? slot1))
  129.       (movable? (+ 1 slot1) 1)
  130.       (if (= (get-value (get-top-card slot1))
  131.          (+ 1 (get-value (get-top-card slot2))))
  132.           (list 1
  133.             (get-name (get-top-card slot1)) 
  134.             (get-name (get-top-card slot2)))
  135.           (movable? slot1 (+ 1 slot2))))))
  136.  
  137. (define (dealable?)
  138.   (or (and (not (empty-slot? 0))
  139.        (list 0 (_"Deal another round")))
  140.       (and (< FLIP-COUNTER 2)
  141.        (list 0 (_"Reshuffle cards")))))
  142.  
  143. (define (get-hint)
  144.   (or (movable? 5 1)
  145.       (dealable?)))
  146.  
  147. (define (get-options) 
  148.   #f)
  149.  
  150. (define (apply-options options) 
  151.   #f)
  152.  
  153. (define (timeout) 
  154.   #f)
  155.  
  156. (set-features droppable-feature)
  157.  
  158. (set-lambda new-game button-pressed button-released button-clicked
  159. button-double-clicked game-continuable game-won get-hint get-options
  160. apply-options timeout droppable?)
  161.