~ubuntu-branches/debian/jessie/aisleriot/jessie

« back to all changes in this revision

Viewing changes to games/streets-and-alleys.scm

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jeremy Bicha, Jordi Mallach
  • Date: 2012-04-22 12:49:26 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120422124926-gmr0thwstl91jt1n
Tags: 1:3.4.1-1
[ Jeremy Bicha ]
* New upstream release
* debian/control.in: (Build)-depend on guile-2.0
* debian/*.install: Cards files are now stored as zipped .svg's
* debian/patches/99_format-security.patch: Dropped, applied upstream

[ Jordi Mallach ]
* New upstream release.
* Update copyright to final version of the machine-readable 1.0 spec.
* Bump Standards Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; AisleRiot - streets_and_alleys.scm
 
2
; Copyright (C) 2001 Rosanna Yuen <zana@webwynk.net>
 
3
;
 
4
; This program 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 3 of the License, or
 
7
; (at your option) 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, see <http://www.gnu.org/licenses/>.
 
16
 
 
17
(use-modules (aisleriot interface) (aisleriot api))
 
18
 
 
19
(define (new-game)
 
20
  (initialize-playing-area)
 
21
  (set-ace-low)
 
22
  (make-standard-deck)
 
23
  (shuffle-deck)
 
24
  (add-extended-slot '() right)
 
25
  (add-blank-slot)
 
26
  (add-blank-slot)
 
27
  (add-blank-slot)
 
28
  (add-normal-slot DECK)
 
29
  (set! HORIZPOS (+ HORIZPOS 0.5))
 
30
  (add-extended-slot '() right)
 
31
  (add-carriage-return-slot)
 
32
  (add-extended-slot '() right)
 
33
  (add-blank-slot)
 
34
  (add-blank-slot)
 
35
  (add-blank-slot)
 
36
  (add-normal-slot '())
 
37
  (set! HORIZPOS (+ HORIZPOS 0.5))
 
38
  (add-extended-slot '() right)
 
39
  (add-carriage-return-slot)
 
40
  (add-extended-slot '() right)
 
41
  (add-blank-slot)
 
42
  (add-blank-slot)
 
43
  (add-blank-slot)
 
44
  (add-normal-slot '())
 
45
  (set! HORIZPOS (+ HORIZPOS 0.5))
 
46
  (add-extended-slot '() right)
 
47
  (add-carriage-return-slot)
 
48
  (add-extended-slot '() right)
 
49
  (add-blank-slot)
 
50
  (add-blank-slot)
 
51
  (add-blank-slot)
 
52
  (add-normal-slot '())
 
53
  (set! HORIZPOS (+ HORIZPOS 0.5))
 
54
  (add-extended-slot '() right)
 
55
  (deal-cards-face-up 1 '(0 2 3 5 6 8 9 11 0 2 3 5 6 8 9 11 
 
56
                          0 2 3 5 6 8 9 11 0 2 3 5 6 8 9 11 
 
57
                          0 2 3 5 6 8 9 11 0 2 3 5 6 8 9 11 0 3 6 9))
 
58
 
 
59
 
 
60
  (list 9 4))
 
61
 
 
62
(define (button-pressed slot-id card-list)
 
63
  (= (length card-list) 1))
 
64
 
 
65
(define (droppable? start-slot card-list end-slot)
 
66
  (cond ((= start-slot end-slot)
 
67
         #f)
 
68
        ((member end-slot '(1 4 7 10))
 
69
         (cond ((empty-slot? end-slot)
 
70
                (= (get-value (car card-list)) 1))
 
71
               (#t 
 
72
                (and (= (get-suit (get-top-card end-slot))
 
73
                        (get-suit (car card-list)))
 
74
                     (= (+ 1 (get-value (get-top-card end-slot)))
 
75
                        (get-value (car card-list)))))))
 
76
        ((empty-slot? end-slot)
 
77
         #t)
 
78
        ((= (get-value (get-top-card end-slot))
 
79
            (+ 1 (get-value (car card-list))))
 
80
         #t)
 
81
        (#t #f)))
 
82
        
 
83
(define (button-released start-slot card-list end-slot)
 
84
  (and (droppable? start-slot card-list end-slot)
 
85
       (move-n-cards! start-slot end-slot card-list)
 
86
       (or (not (member start-slot '(1 4 7 10)))
 
87
           (add-to-score! -1))
 
88
       (or (not (member end-slot '(1 4 7 10)))
 
89
           (add-to-score! 1))))
 
90
 
 
91
(define (button-clicked slot-id) 
 
92
  #f)
 
93
 
 
94
(define (button-double-clicked slot-id)
 
95
  (if (and (not (empty-slot? slot-id))
 
96
           (is-visible? (get-top-card slot-id))
 
97
           (not (or (= slot-id 1)
 
98
                    (= slot-id 4)
 
99
                    (= slot-id 7)
 
100
                    (= slot-id 10))))
 
101
      (cond ((= (get-value (get-top-card slot-id)) ace)
 
102
             (and (or (and (empty-slot? 1)
 
103
                           (deal-cards slot-id '(1)))
 
104
                      (and (empty-slot? 4)
 
105
                           (deal-cards slot-id '(4)))
 
106
                      (and (empty-slot? 7)
 
107
                           (deal-cards slot-id '(7)))
 
108
                      (deal-cards slot-id '(10)))
 
109
                  (add-to-score! 1)))
 
110
            ((and (not (null? (get-top-card 1)))
 
111
                  (= (get-suit (get-top-card slot-id))
 
112
                     (get-suit (get-top-card 1)))
 
113
                  (= (get-value (get-top-card slot-id))
 
114
                     (+ 1 (get-value (get-top-card 1)))))
 
115
             (deal-cards slot-id '(1))
 
116
             (add-to-score! 1))
 
117
            ((and (not (null? (get-top-card 4)))
 
118
                  (= (get-suit (get-top-card slot-id))
 
119
                     (get-suit (get-top-card 4)))
 
120
                  (= (get-value (get-top-card slot-id))
 
121
                     (+ 1 (get-value (get-top-card 4)))))
 
122
             (deal-cards slot-id '(4))
 
123
             (add-to-score! 1))
 
124
            ((and (not (null? (get-top-card 7)))
 
125
                  (= (get-suit (get-top-card slot-id))
 
126
                     (get-suit (get-top-card 7)))
 
127
                  (= (get-value (get-top-card slot-id))
 
128
                     (+ 1 (get-value (get-top-card 7)))))
 
129
             (deal-cards slot-id '(7))
 
130
             (add-to-score! 1))
 
131
            ((and (not (null? (get-top-card 10)))
 
132
                  (= (get-suit (get-top-card slot-id))
 
133
                     (get-suit (get-top-card 10)))
 
134
                  (= (get-value (get-top-card slot-id))
 
135
                     (+ 1 (get-value (get-top-card 10)))))
 
136
             (deal-cards slot-id '(10))
 
137
             (add-to-score! 1))
 
138
            (#t #f))
 
139
      #f))
 
140
            
 
141
(define (game-continuable)
 
142
  (not (game-won)))
 
143
 
 
144
(define (game-won)
 
145
  (and (= (length (get-cards 1)) 13)
 
146
       (= (length (get-cards 4)) 13)
 
147
       (= (length (get-cards 7)) 13)
 
148
       (= (length (get-cards 10)) 13)))
 
149
 
 
150
(define (check-a-foundation slot1 slot2)
 
151
  (cond ((or (= slot1 1)
 
152
             (= slot1 4)
 
153
             (= slot1 7)
 
154
             (= slot1 10))
 
155
         #f)
 
156
        ((empty-slot? slot2)
 
157
         (and (= (get-value (get-top-card slot1)) ace)
 
158
              (list 2 (get-name (get-top-card slot1)) (_"an empty foundation"))))
 
159
        ((and (= (get-suit (get-top-card slot1))
 
160
                 (get-suit (get-top-card slot2)))
 
161
              (= (get-value (get-top-card slot1))
 
162
                 (+ 1 (get-value (get-top-card slot2)))))
 
163
         (list 1
 
164
               (get-name (get-top-card slot1))
 
165
               (get-name (get-top-card slot2))))
 
166
        (#t #f)))
 
167
 
 
168
(define (check-to-foundation slot-id)
 
169
  (if (not (empty-slot? slot-id))
 
170
      (or (check-a-foundation slot-id 1)
 
171
          (check-a-foundation slot-id 4)
 
172
          (check-a-foundation slot-id 7)
 
173
          (check-a-foundation slot-id 10)
 
174
          (and (< slot-id 11)
 
175
               (check-to-foundation (+ 1 slot-id))))
 
176
      (if (< slot-id 11)
 
177
          (check-to-foundation (+ 1 slot-id))
 
178
          #f)))
 
179
 
 
180
(define (get-hint)
 
181
  (or (check-to-foundation 0)
 
182
      (list 0 (_"Try rearranging the cards"))))
 
183
 
 
184
(define (get-options) 
 
185
  #f)
 
186
 
 
187
(define (apply-options options) 
 
188
  #f)
 
189
 
 
190
(define (timeout) 
 
191
  #f)
 
192
 
 
193
(set-features droppable-feature)
 
194
 
 
195
(set-lambda new-game button-pressed button-released button-clicked
 
196
button-double-clicked game-continuable game-won get-hint get-options
 
197
apply-options timeout droppable?)