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

  1. ; AisleRiot - neighbor.scm
  2. ; Copyright (C) 1998, 2003 Rosanna Yuen <rwsy@mit.edu>
  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.   (make-standard-deck)
  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-normal-slot '()) 
  32.   (add-carriage-return-slot)
  33.   (add-blank-slot)
  34.   (add-blank-slot)
  35.   (add-normal-slot '()) 
  36.   (add-normal-slot '()) 
  37.   (add-normal-slot '()) 
  38.   (add-normal-slot '()) 
  39.   (add-normal-slot '()) 
  40.   (add-carriage-return-slot)
  41.   (add-blank-slot)
  42.   (add-blank-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.   (add-blank-slot)
  50.   (add-blank-slot)
  51.   (add-normal-slot '()) 
  52.   (add-normal-slot '()) 
  53.   (add-normal-slot '()) 
  54.   (add-normal-slot '()) 
  55.   (add-normal-slot '()) 
  56.   (add-carriage-return-slot)
  57.   (add-blank-slot)
  58.   (add-blank-slot)
  59.   (add-normal-slot '()) 
  60.   (add-normal-slot '()) 
  61.   (add-normal-slot '()) 
  62.   (add-normal-slot '()) 
  63.   (add-normal-slot '()) 
  64.   (deal-cards-face-up 0 '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  65.                 19 20 21 22 23 24 25))
  66.  
  67.   (give-status-message)
  68.  
  69.   (list 7 5))
  70.  
  71. (define (give-status-message)
  72.   (set-statusbar-message (get-stock-no-string)))
  73.  
  74. (define (get-stock-no-string)
  75.   (string-append (_"Stock left:") " " 
  76.          (number->string (length (get-cards 0)))))
  77.  
  78. (define (button-pressed slot-id card-list)
  79.   (and (not (= slot-id 0))
  80.        (not (empty-slot? slot-id))
  81.        (not (= (get-value (get-top-card slot-id)) king))))
  82.  
  83. (define (fill-it-up slot-id spaces)
  84.   (cond ((> (+ slot-id spaces) 25)
  85.      (begin
  86.        (if (not (empty-slot? 0))
  87.            (deal-cards-face-up 0 (cons slot-id '()))
  88.            #t)
  89.        (if (< slot-id 25)
  90.            (fill-it-up (+ slot-id 1) spaces)
  91.            #t)))
  92.     ((not (empty-slot? (+ slot-id spaces)))
  93.      (begin
  94.        (deal-cards-face-up (+ slot-id spaces) (cons slot-id '()))
  95.        (if (< slot-id 25)
  96.            (fill-it-up (+ slot-id 1) spaces)
  97.            #t)))
  98.     (#t
  99.      (fill-it-up slot-id (+ 1 spaces)))))
  100.  
  101. (define (droppable? start-slot card-list end-slot)
  102.   (let ((dx (- (modulo (- start-slot 1) 5)
  103.                (modulo (- end-slot 1) 5)))
  104.         (dy (- (quotient (- start-slot 1) 5)
  105.                (quotient (- end-slot 1) 5))))
  106.        (and (not (= start-slot end-slot))
  107.             (not (= end-slot 0))
  108.             (not (empty-slot? end-slot))
  109.             (= 13 (+ (get-value (car card-list))
  110.                      (get-value (get-top-card end-slot))))
  111.             (member dx '(-1 0 1))
  112.             (member dy '(-1 0 1)))))
  113.  
  114. (define (button-released start-slot card-list end-slot)
  115.   (and (droppable? start-slot card-list end-slot)
  116.        (add-to-score! +2)
  117.        (remove-card end-slot)
  118.        (fill-it-up (min start-slot end-slot) 1)))
  119.      
  120. (define (button-clicked slot-id)  
  121.   (if (and (not (empty-slot? slot-id))
  122.        (= (get-value (get-top-card slot-id)) king))
  123.       (begin
  124.     (add-to-score! +1)
  125.     (remove-card slot-id)
  126.     (fill-it-up slot-id 1))
  127.       #f))
  128.  
  129. (define (button-double-clicked slot)
  130.   #f)     
  131.  
  132. (define (game-won)
  133.   (empty-slot? 1))
  134.  
  135. (define (game-over)
  136.   (give-status-message)
  137.   (and (not (game-won))
  138.        (get-hint)))
  139.  
  140. (define (king-check slot-id)
  141.   (cond ((= king (get-value (get-top-card slot-id)))
  142.      (list 2 (get-name (get-top-card slot-id)) (_"itself")))
  143.     ((and (< slot-id 25)
  144.           (not (empty-slot? (+ 1 slot-id))))
  145.      (king-check (+ 1 slot-id)))
  146.     (#t #f)))
  147.  
  148. (define (horizontal-check slot-id)
  149.   (cond ((and (not (= 0 (modulo slot-id 5)))
  150.           (= 13 (+ (get-value (get-top-card slot-id))
  151.                (get-value (get-top-card (+ 1 slot-id))))))
  152.      (list 1 (get-name (get-top-card slot-id))
  153.            (get-name (get-top-card (+ 1 slot-id)))))
  154.     ((and (< slot-id 24)
  155.           (not (empty-slot? (+ 2 slot-id))))
  156.      (horizontal-check (+ 1 slot-id)))
  157.     (#t #f)))
  158.  
  159. (define (vertical-check slot-id)
  160.   (cond ((= 13 (+ (get-value (get-top-card slot-id))
  161.           (get-value (get-top-card (+ 5 slot-id)))))
  162.      (list 1 (get-name (get-top-card slot-id))
  163.            (get-name (get-top-card (+ 5 slot-id)))))
  164.     ((and (< slot-id 19)
  165.           (not (empty-slot? (+ 6 slot-id))))
  166.      (vertical-check (+ 1 slot-id)))
  167.     (#t #f)))           
  168.  
  169. (define (backslash-check slot-id)
  170.   (cond ((and (not (= 0 (modulo slot-id 5)))
  171.           (= 13 (+ (get-value (get-top-card slot-id))
  172.                (get-value (get-top-card (+ 6 slot-id))))))
  173.      (list 1 (get-name (get-top-card slot-id))
  174.            (get-name (get-top-card (+ 6 slot-id)))))
  175.     ((and (not (empty-slot? (+ 7 slot-id)))
  176.           (< slot-id 18))
  177.      (backslash-check (+ 1 slot-id)))
  178.     (#t #f)))
  179.  
  180. (define (slash-check slot-id)
  181.   (cond ((and (not (= 1 (modulo slot-id 5)))
  182.           (= 13 (+ (get-value (get-top-card slot-id))
  183.                (get-value (get-top-card (+ 4 slot-id))))))
  184.      (list 1 (get-name (get-top-card slot-id))
  185.            (get-name (get-top-card (+ 4 slot-id)))))
  186.     ((and (< slot-id 19)
  187.           (not (empty-slot? (+ 5 slot-id))))
  188.      (slash-check (+ 1 slot-id)))
  189.     (#t #f)))
  190.  
  191. (define (get-hint)
  192.   (or (king-check 1)
  193.       (and (not (empty-slot? 2))
  194.        (horizontal-check 1))
  195.       (and (not (empty-slot? 6))
  196.        (vertical-check 1))
  197.       (and (not (empty-slot? 7))
  198.        (backslash-check 1))
  199.       (and (not (empty-slot? 6))
  200.        (slash-check 2))))
  201.  
  202. (define (get-options) #f)
  203.  
  204. (define (apply-options options) #f)
  205.  
  206. (define (timeout) #f)
  207.  
  208. (set-features droppable-feature)
  209.  
  210. (set-lambda new-game button-pressed button-released button-clicked button-double-clicked game-over game-won get-hint get-options apply-options timeout droppable?)
  211.