~ubuntu-branches/ubuntu/oneiric/denemo/oneiric

« back to all changes in this revision

Viewing changes to actions/menus/MainMenu/Educational/LineOrSpace

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-10-27 08:00:18 UTC
  • mfrom: (1.3.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20101027080018-tuekd0869v8ptnqv
Tags: upstream-0.8.16
ImportĀ upstreamĀ versionĀ 0.8.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version="1.0"?>
2
 
<Denemo>
3
 
  <merge>
4
 
    <title>A Denemo Keymap</title>
5
 
    <author>AT, JRR, RTS</author>
6
 
    <map>
7
 
      <row>
8
 
        <action>LineOrSpace</action>
9
 
        <scheme>;;;;;;;;;;;;;;;
10
 
;;LineOrSpace
11
 
;; tests note name recognition.
12
 
 
13
 
(define LineOrSpace::positionwas #t)
14
 
(define LineOrSpace::acceptable_input (list "l" "space"))
15
 
(define LineOrSpace::userinput #t)
16
 
(define LineOrSpace::start (current-time))
17
 
(define LineOrSpace::end (current-time))
18
 
(define LineOrSpace::score 0)
19
 
(define LineOrSpace::steps 0)
20
 
(define LineOrSpace::position 6) ;in middle c offset
21
 
(define LineOrSpace::note_highest 12)
22
 
(define LineOrSpace::note_lowest 0)
23
 
(define LineOrSpace::span 8) ;; how many LineOrSpace::steps of the scale to test.
24
 
(define LineOrSpace::num-goes 30) ;; how many notes to present for the whole test
25
 
(define LineOrSpace::input_device 1) ;0 = mouse 1 = keyboard
26
 
 
27
 
(define (LineOrSpace::showscore)
28
 
  (d-DirectivePut-score-display "LineOrSpace::GameScore" (string-append "&lt;b&gt;Score: " (object-&gt;string LineOrSpace::score) "&lt;/b&gt; in " (object-&gt;string (- LineOrSpace::end LineOrSpace::start)) " Secs.")))
29
 
 
30
 
(define (LineOrSpace::help) 
31
 
  (d-InfoDialog "Click on the *Spacebar* if the note is on a space and the *L* key if it is on a line.")
32
 
)
33
 
 
34
 
(define (LineOrSpace::GameOver)
35
 
   (d-InfoDialog (string-append "Game Over\n" "Your Score = " (number->string LineOrSpace::score)))
36
 
)
37
 
 
38
 
(define (LineOrSpace::ScoreBoard)
39
 
    (d-InfoDialog (EducationGames::Scoreboard_Pretty_Print 
40
 
      (EducationGames::ScoreboardFile "LineOrSpace")))
41
 
)
42
 
 
43
 
(CreateButton "LineOrSpace::GameScore" "&lt;span font_desc=\"12\"&gt;Score&lt;/span&gt;")
44
 
(d-SetDirectiveTagActionScript "LineOrSpace::GameScore" "(LineOrSpace::ScoreBoard)")
45
 
(CreateButton "LineOrSpace::GameHelp" "&lt;b&gt;Help&lt;/b&gt;")
46
 
(d-SetDirectiveTagActionScript "LineOrSpace::GameHelp" "(LineOrSpace::help)")
47
 
          
48
 
(define (LineOrSpace::offerNote) 
49
 
        (let (    
50
 
              (outofrange? 0)
51
 
              (seed 0)
52
 
              (interval 0)
53
 
              )
54
 
              (set! outofrange?
55
 
                (lambda ()
56
 
                  (or (> LineOrSpace::position LineOrSpace::note_highest) 
57
 
                      (> LineOrSpace::note_lowest LineOrSpace::position)) 
58
 
                        ))
59
 
              (set! seed 
60
 
                (lambda ()
61
 
                  (set! interval (random 4))
62
 
                  (if (= (random 2) 0)
63
 
                    (set! LineOrSpace::position (+ LineOrSpace::position interval))
64
 
                    (set! LineOrSpace::position (- LineOrSpace::position interval)))
65
 
                    (if (outofrange?)
66
 
                      (seed))
67
 
                    ))
68
 
 
69
 
          (seed)
70
 
          ;;  (d-GoToEnd)
71
 
          (let gotoEnd () (if  (d-NextObject) (gotoEnd)))
72
 
 
73
 
          (d-CursorToNote (EducationalGames::middle_c_offset->lily LineOrSpace::position))
74
 
          (d-Insert1)
75
 
          (if (or (even? LineOrSpace::position) 
76
 
                  (= 0 LineOrSpace::position))
77
 
              (set! LineOrSpace::positionwas "line")
78
 
              (set! LineOrSpace::positionwas "space"))
79
 
 
80
 
          (LineOrSpace::showscore)
81
 
          ))
82
 
 
83
 
;;;;;;;;; callback when user chooses a note
84
 
(define (LineOrSpace::positionchosen userinput)
85
 
         (if (> LineOrSpace::num-goes 0)
86
 
                (begin
87
 
                        (set! LineOrSpace::end (current-time))
88
 
                        (let gotoEnd () (if  (d-NextObject) (gotoEnd))) 
89
 
                        (if  (string=? LineOrSpace::positionwas userinput)
90
 
                             (begin
91
 
                               (set! LineOrSpace::score (+ LineOrSpace::score 1))
92
 
                               (EducationGames::PlaceAnswerStatus "CheckMark"))
93
 
                             (begin
94
 
                               (set! LineOrSpace::score (- LineOrSpace::score 1))
95
 
                               (EducationGames::PlaceAnswerStatus "CrossSign"))) 
96
 
                        
97
 
                        (if (= LineOrSpace::input_device 0)
98
 
                                (begin
99
 
                                  (set! LineOrSpace::num-goes (- LineOrSpace::num-goes 1)) 
100
 
                                  (if (= LineOrSpace::num-goes 0)
101
 
                                    (LineOrSpace::EndGame))
102
 
                                    ))
103
 
                        (if (> LineOrSpace::num-goes 0)
104
 
                          (LineOrSpace::offerNote))
105
 
                               )))
106
 
        
107
 
 
108
 
;;;;;;;; the main function to run the test
109
 
(define LineOrSpace::runtest 
110
 
        (lambda (n)
111
 
          (if (> n 0) (begin
112
 
              (set! LineOrSpace::userinput (EducationGames::GetAcceptableKeyInput LineOrSpace::acceptable_input))
113
 
              (if (string=? LineOrSpace::userinput "l")
114
 
                   (set! LineOrSpace::userinput "line"))
115
 
              (LineOrSpace::positionchosen LineOrSpace::userinput)      
116
 
              (LineOrSpace::runtest (- n 1))))))
117
 
 
118
 
 
119
 
(define (LineOrSpace::createbuttons position)
120
 
  (CreateButton (string-append "LineOrSpace::" position)  (string-append " &lt;span font_desc=\"32\" foreground=\"blue\"&gt;" position  "&lt;/span&gt;"))
121
 
  (d-SetDirectiveTagActionScript  (string-append "LineOrSpace::" position) (string-append "(LineOrSpace::positionchosen \"" position "\")")))
122
 
 
123
 
(define (LineOrSpace::EndGame)
124
 
    (EducationGames::Chime)  
125
 
    (if (not 
126
 
      (EducationGames::Write_Scoreboard_File 
127
 
      (EducationGames::ScoreboardFile "LineOrSpace") LineOrSpace::score))
128
 
      (LineOrSpace::GameOver)
129
 
      (LineOrSpace::ScoreBoard)
130
 
    ))
131
 
 
132
 
 
133
 
;;;
134
 
(define (LineOrSpace::go)
135
 
  (if (not (zero? LineOrSpace::score))
136
 
      (let ((response #f))
137
 
        (set! response (d-GetUserInput "Reset Score" "Do you want to reset your score" "y"))
138
 
        (if (equal? response "y")
139
 
            (begin
140
 
              (set! LineOrSpace::start (current-time))
141
 
              (set! LineOrSpace::end (current-time))
142
 
 
143
 
              (set! LineOrSpace::score 0)))))
144
 
  (d-DeletePreviousObject)
145
 
  (if (= LineOrSpace::input_device 0)
146
 
    (begin ;mouse 
147
 
      (LineOrSpace::createbuttons "line")
148
 
      (LineOrSpace::createbuttons "space")
149
 
      (EducationGames::Chime)
150
 
      (LineOrSpace::offerNote)
151
 
      )
152
 
    (begin ;keyboard
153
 
      (EducationGames::Chime)
154
 
      (LineOrSpace::offerNote)
155
 
      (LineOrSpace::runtest LineOrSpace::num-goes)
156
 
      (LineOrSpace::EndGame))
157
 
      )
158
 
   )
159
 
 
160
 
(CreateButton "LineOrSpace::GameScore" "&lt;span font_desc=\"32\"&gt;Click to start&lt;/span&gt;")
161
 
(d-SetDirectiveTagActionScript "LineOrSpace::GameScore" "(LineOrSpace::go)")
162
 
 
163
 
 
164
 
(define (LineOrSpace::Input_Select)
165
 
  (if (= LineOrSpace::input_device 0)
166
 
    (begin 
167
 
      (set! LineOrSpace::input_device 1)
168
 
      (d-DirectivePut-score-display "LineOrSpace::SetInput" "&lt;span font_desc=\"12\"&gt;Input:keyboard&lt;/span&gt;")
169
 
      )
170
 
    (begin
171
 
      (set! LineOrSpace::input_device 0)
172
 
      (d-DirectivePut-score-display "LineOrSpace::SetInput" "&lt;span font_desc=\"12\"&gt;Input:mouse&lt;/span&gt;")
173
 
    )  
174
 
    ))
175
 
 
176
 
(CreateButton "LineOrSpace::SetInput" "&lt;span font_desc=\"12\"&gt;Input:keyboard&lt;/span&gt;")
177
 
(d-SetDirectiveTagActionScript "LineOrSpace::SetInput" "(LineOrSpace::Input_Select)")
178
 
 
179
 
</scheme>
180
 
        <label>Line and space recognition</label>
181
 
        <tooltip>%tests your ability to recognize the difference between line and space</tooltip>
182
 
      </row>
183
 
    </map>
184
 
  </merge>
185
 
</Denemo>