30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.

YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.

298 10. Memory – e<strong>in</strong> kle<strong>in</strong>es Beispiel<br />

2. Durch E<strong>in</strong>gabe von h (=hide) werden sie wieder verdeckt.<br />

Um nun nicht mit zu vielen Spezialfällen kämpfen zu müssen, nehmen wir<br />

e<strong>in</strong>fach e<strong>in</strong>mal an, dass alle Spieler sich an die Regeln halten und zu Beg<strong>in</strong>n<br />

e<strong>in</strong>mal s drücken, sich die Karten kurz e<strong>in</strong>prägen, dann h drücken und danach<br />

regulär spielen. Es werden daher ke<strong>in</strong>e Sonderabfragen e<strong>in</strong>gebaut, ob e<strong>in</strong> Spiel<br />

bereits <strong>in</strong> Gange ist und deshalb s nicht mehr zulässig ist, etc...<br />

E<strong>in</strong>e kle<strong>in</strong>e Anregung me<strong>in</strong>erseits: Interessierte Leser könnten das Programm<br />

z.B. um diese Funktionalität ergänzen. Dem Spieltrieb s<strong>in</strong>d natürlich<br />

ke<strong>in</strong>e Grenzen gesetzt und man könnte auch noch e<strong>in</strong>e Hilfe implementieren,<br />

die durch E<strong>in</strong>gabe von h angezeigt wird. Im Rahmen des Buchs bleiben wir<br />

jedoch am Boden und bei der Grundfunktionalität, die sich <strong>in</strong> der folgenden<br />

Klasse niederschlägt:<br />

1 // memory game control . h − the ma<strong>in</strong> c o n t r o l o f the memory game<br />

2<br />

3 #ifndef memory game control h<br />

4 #def<strong>in</strong>e memory game control h<br />

5<br />

6 #<strong>in</strong>clude ” simple event handler . h”<br />

7 #<strong>in</strong>clude ”memory game control . h”<br />

8 #<strong>in</strong>clude ” simple event handler . h”<br />

9 #<strong>in</strong>clude ”memory gameboard . h”<br />

10 #<strong>in</strong>clude ” simple output handl<strong>in</strong>g . h”<br />

11 #<strong>in</strong>clude ”memory cardpair . h”<br />

12 #<strong>in</strong>clude ”memory game card v5 . h”<br />

13 #<strong>in</strong>clude ” u s e r t y p e s . h”<br />

14<br />

15 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

16 /∗<br />

17 ∗ MemoryGameControl<br />

18 ∗<br />

19 ∗ the ma<strong>in</strong> c o n t r o l of the memory game<br />

20 ∗<br />

21 ∗/<br />

22<br />

23 class MemoryGameControl : public EventHandler<br />

24 {<br />

25 protected :<br />

26<br />

27 /∗ The p o s s i b l e event handl<strong>in</strong>g s t a t e s f o r every s i n g l e card .<br />

28 ∗ Because the event handler d e l i v e r s <strong>in</strong>put word by word , the<br />

29 ∗ coord<strong>in</strong>ates come one a f t e r the other . Therefore i t i s<br />

30 ∗ necessary to keep track of what i s expected next .<br />

31 ∗/<br />

32 static const u<strong>in</strong>t8 WAITING FOR ROW AND COL = 0x0 ;<br />

33 static const u<strong>in</strong>t8 WAITING FOR COL = 0x1 ;<br />

34<br />

35 /∗ This i s the back s i d e symbol o f the cards<br />

36 ∗/<br />

37 static const char CARD BACK SYMBOL[ ] = ” . ” ;<br />

38<br />

39 /∗ The gameboard that t h i s <strong>in</strong>stance o f the game c o n t r o l i s<br />

40 ∗ r e s p o n s i b l e f o r .<br />

41 ∗/<br />

42 MemoryGameboard &gameboard ;<br />

43<br />

44 /∗ The output handler f o r the game . I f cards are turned the<br />

45 ∗ request to redraw the board has to go to t h i s handler .<br />

46 ∗/

Hurra! Ihre Datei wurde hochgeladen und ist bereit für die Veröffentlichung.

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!