home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / fortunes.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  4.8 KB  |  171 lines

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