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

  1. ; AisleRiot - treize.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.   (make-standard-deck)
  23.   (shuffle-deck)
  24.  
  25.   (add-normal-slot DECK)
  26.   (add-normal-slot '())
  27.   (set! HORIZPOS (- HORIZPOS (/ 2 3)))
  28.   (add-extended-slot '() right)
  29.  
  30.   (add-carriage-return-slot)
  31.  
  32.   (add-blank-slot)
  33.   (add-blank-slot)
  34.   (add-blank-slot)
  35.   (add-normal-slot '())
  36.  
  37.   (add-carriage-return-slot)
  38.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  39.   (set! HORIZPOS (+ HORIZPOS 0.5))
  40.   (add-blank-slot)
  41.   (add-blank-slot)
  42.   (add-normal-slot '())
  43.   (add-normal-slot '())
  44.  
  45.   (add-carriage-return-slot)
  46.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  47.   (add-blank-slot)
  48.   (add-blank-slot)
  49.   (add-normal-slot '())
  50.   (add-normal-slot '())
  51.   (add-normal-slot '())
  52.  
  53.   (add-carriage-return-slot)
  54.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  55.   (set! HORIZPOS (+ HORIZPOS 0.5))
  56.   (add-blank-slot)
  57.   (add-normal-slot '())
  58.   (add-normal-slot '())
  59.   (add-normal-slot '())
  60.   (add-normal-slot '())
  61.  
  62.   (add-carriage-return-slot)
  63.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  64.   (add-blank-slot)
  65.   (add-normal-slot '())
  66.   (add-normal-slot '())
  67.   (add-normal-slot '())
  68.   (add-normal-slot '())
  69.   (add-normal-slot '())
  70.  
  71.   (add-carriage-return-slot)
  72.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  73.   (set! HORIZPOS (+ HORIZPOS 0.5))
  74.   (add-normal-slot '())
  75.   (add-normal-slot '())
  76.   (add-normal-slot '())
  77.   (add-normal-slot '())
  78.   (add-normal-slot '())
  79.   (add-normal-slot '())
  80.  
  81.   (add-carriage-return-slot)
  82.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  83.   (add-normal-slot '())
  84.   (add-normal-slot '())
  85.   (add-normal-slot '())
  86.   (add-normal-slot '())
  87.   (add-normal-slot '())
  88.   (add-normal-slot '())
  89.   (add-normal-slot '())
  90.  
  91.   (deal-cards-face-up 0 ' (3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  92.                  20 21 22 23 24 25 26 27 28 29 30))
  93.  
  94.   (give-status-message)
  95.  
  96.   (list 7 4))
  97.  
  98. (define (give-status-message)
  99.   (set-statusbar-message (get-stock-no-string)))
  100.  
  101. (define (get-stock-no-string)
  102.   (string-append (_"Stock left:") " " 
  103.          (number->string (length (get-cards 0)))))
  104.  
  105. (define (button-pressed slot-id card-list)
  106.   (and (not (empty-slot? slot-id))
  107.        (not (= (get-value (car card-list)) king))
  108.        (available? slot-id 0)
  109.        (= (length card-list) 1)))
  110.  
  111. (define (available? slot-id r-slot)
  112.   (cond ((or (= slot-id 1)
  113.          (= slot-id 2))
  114.      #t)
  115.     ((= slot-id 0)
  116.      #f)
  117.     ((= slot-id 23)
  118.      (and (empty-slot? 29)
  119.           (empty-slot? 30)
  120.           (not (= r-slot 29))
  121.           (not (= r-slot 30))))
  122.     ((= slot-id 22)
  123.      (and (empty-slot? 28)
  124.           (empty-slot? 29)
  125.           (not (= r-slot 28))
  126.           (not (= r-slot 29))))
  127.     ((= slot-id 21)
  128.      (and (empty-slot? 27)
  129.           (empty-slot? 28)
  130.           (not (= r-slot 27))
  131.           (not (= r-slot 28))))
  132.     ((= slot-id 20)
  133.      (and (empty-slot? 26)
  134.           (empty-slot? 27)
  135.           (not (= r-slot 26))
  136.           (not (= r-slot 27))))
  137.     ((= slot-id 19)
  138.      (and (empty-slot? 25)
  139.           (empty-slot? 26)
  140.           (not (= r-slot 25))
  141.           (not (= r-slot 26))))
  142.     ((= slot-id 18)
  143.      (and (empty-slot? 24)
  144.           (empty-slot? 25)
  145.           (not (= r-slot 24))
  146.           (not (= r-slot 25))))
  147.     ((= slot-id 17)
  148.      (and (empty-slot? 22)
  149.           (empty-slot? 23)
  150.           (not (= r-slot 22))
  151.           (not (= r-slot 23))))
  152.     ((= slot-id 16)
  153.      (and (empty-slot? 21)
  154.           (empty-slot? 22)
  155.           (not (= r-slot 21))
  156.           (not (= r-slot 22))))
  157.     ((= slot-id 15)
  158.      (and (empty-slot? 20)
  159.           (empty-slot? 21)
  160.           (not (= r-slot 20))
  161.           (not (= r-slot 21))))
  162.     ((= slot-id 14)
  163.      (and (empty-slot? 19)
  164.           (empty-slot? 20)
  165.           (not (= r-slot 19))
  166.           (not (= r-slot 20))))
  167.     ((= slot-id 13)
  168.      (and (empty-slot? 18)
  169.           (empty-slot? 19)
  170.           (not (= r-slot 18))
  171.           (not (= r-slot 19))))
  172.     ((= slot-id 12)
  173.      (and (empty-slot? 16)
  174.           (empty-slot? 17)
  175.           (not (= r-slot 16))
  176.           (not (= r-slot 17))))
  177.     ((= slot-id 11)
  178.      (and (empty-slot? 15)
  179.           (empty-slot? 16)
  180.           (not (= r-slot 15))
  181.           (not (= r-slot 16))))
  182.     ((= slot-id 10)
  183.      (and (empty-slot? 14)
  184.           (empty-slot? 15)
  185.           (not (= r-slot 14))
  186.           (not (= r-slot 15))))
  187.     ((= slot-id 9)
  188.      (and (empty-slot? 13)
  189.           (empty-slot? 14)
  190.           (not (= r-slot 13))
  191.           (not (= r-slot 14))))
  192.     ((= slot-id 8)
  193.      (and (empty-slot? 11)
  194.           (empty-slot? 12)
  195.           (not (= r-slot 11))
  196.           (not (= r-slot 12))))
  197.     ((= slot-id 7)
  198.      (and (empty-slot? 10)
  199.           (empty-slot? 11)
  200.           (not (= r-slot 10))
  201.           (not (= r-slot 11))))
  202.     ((= slot-id 6)
  203.      (and (empty-slot? 9)
  204.           (empty-slot? 10)
  205.           (not (= r-slot 9))
  206.           (not (= r-slot 10))))
  207.     ((= slot-id 5)
  208.      (and (empty-slot? 7)
  209.           (empty-slot? 8)
  210.           (not (= r-slot 7))
  211.           (not (= r-slot 8))))
  212.     ((= slot-id 4)
  213.      (and (empty-slot? 6)
  214.           (empty-slot? 7)
  215.           (not (= r-slot 6))
  216.           (not (= r-slot 7))))
  217.     ((= slot-id 3)
  218.      (and (empty-slot? 4)
  219.           (empty-slot? 5)
  220.           (not (= r-slot 4))
  221.           (not (= r-slot 5))))))
  222.  
  223. (define (droppable? start-slot card-list end-slot)
  224.   (and (not (empty-slot? end-slot))
  225.        (available? end-slot start-slot)
  226.        (= 13 (+ (get-value (car card-list))
  227.         (get-value (get-top-card end-slot))))))
  228.  
  229. (define (button-released start-slot card-list end-slot)
  230.   (and (droppable? start-slot card-list end-slot)
  231.        (add-to-score! 2)
  232.        (remove-card end-slot)
  233.        (if (or (= start-slot 1)
  234.            (= end-slot 1))
  235.        (if (not (empty-slot? 2))
  236.            (begin
  237.          (let ((new-contents (get-cards 2)))
  238.            (let ((moving-back (car (reverse new-contents))))
  239.              (set-cards! 1 (list moving-back)))
  240.            (set-cards! 2 (reverse (cdr (reverse new-contents))))))
  241.            #t)
  242.        #t)))
  243.  
  244. (define (button-clicked slot-id)
  245.   (if (= slot-id 0)
  246.       (if (empty-slot? 1)
  247.       (and (not (empty-slot? 0))
  248.            (deal-cards-face-up 0 '(1)))
  249.       (and (not (empty-slot? 0))
  250.            (deal-cards-face-up 0 '(2))))
  251.       (and (not (empty-slot? slot-id))
  252.        (available? slot-id 0)
  253.        (= (get-value (get-top-card slot-id))
  254.           king)
  255.        (remove-card slot-id)
  256.        (if (= slot-id 1)
  257.            (if (not (empty-slot? 2))
  258.            (begin
  259.              (let ((new-contents (get-cards 2)))
  260.                (let ((moving-back (car (reverse new-contents))))
  261.              (set-cards! 1 (list moving-back)))
  262.                (set-cards! 2 (reverse (cdr (reverse new-contents))))))))
  263.        (add-to-score! 1))))
  264.  
  265. (define (button-double-clicked slot-id)
  266.   #f)
  267.  
  268. (define (game-continuable)
  269.   (give-status-message)
  270.   (and (not (game-won))
  271.        (get-hint)))
  272.  
  273. (define (game-won)
  274.   (and (empty-slot? 3)
  275.        (empty-slot? 1)
  276.        (empty-slot? 0)))
  277.  
  278. (define (check-move slot1 slot2)
  279.   (if (or (empty-slot? slot1)
  280.       (not (available? slot1 0)))
  281.       (if (< slot1 29)
  282.       (check-move (+ 1 slot1) (+ 2 slot1))
  283.       #f)
  284.       (if (= king (get-value (get-top-card slot1)))
  285.       (list 2 (get-name (get-top-card slot1)) (_"itself"))
  286.       (if (or (empty-slot? slot2)
  287.           (not (available? slot2 0))
  288.           (not (= 13 (+ (get-value (get-top-card slot1))
  289.                 (get-value (get-top-card slot2))))))
  290.           (if (< slot2 30)
  291.           (check-move slot1 (+ 1 slot2))
  292.           (if (< slot1 29)
  293.               (check-move (+ 1 slot1) (+ 2 slot1))
  294.               #f))
  295.           (list 1 
  296.             (get-name (get-top-card slot1)) 
  297.             (get-name (get-top-card slot2)))))))
  298.  
  299. (define (dealable?)
  300.   (if (not (empty-slot? 0))
  301.       (list 0 (_"Deal a card"))
  302.       #f))
  303.  
  304. (define (check-waste)
  305.   (and (not (empty-slot? 2))
  306.        (> (length (get-cards 2)) 1)
  307.        (= 13 (+ (get-value (get-top-card 2))
  308.         (get-value (cadr (get-cards 2)))))
  309.        (list 1
  310.          (get-name (get-top-card 2))
  311.          (get-name (cadr (get-cards 2))))))
  312.  
  313. (define (get-hint)
  314.   (or (check-move 1 2)  
  315.       (check-waste)
  316.       (dealable?)))
  317.  
  318. (define (get-options) 
  319.   #f)
  320.  
  321. (define (apply-options options) 
  322.   #f)
  323.  
  324. (define (timeout) 
  325.   #f)
  326.  
  327. (set-features droppable-feature)
  328.  
  329. (set-lambda new-game button-pressed button-released button-clicked
  330. button-double-clicked game-continuable game-won get-hint get-options
  331. apply-options timeout droppable?)
  332.