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.

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

72 /∗ Call t h i s method to stop the dispatcher loop . I f i t i s c a l l e d<br />

73 ∗ from with<strong>in</strong> the event handler while i t i s j u s t handl<strong>in</strong>g an<br />

74 ∗ event , the loop w i l l be stopped as soon as the handler<br />

75 ∗ n o t i f i c a t i o n method returns . I f i t i s c a l l e d from any other<br />

76 ∗ po<strong>in</strong>t <strong>in</strong> the program , the dispatcher loop w i l l be stopped<br />

77 ∗ a f t e r the next word event has been processed .<br />

78 ∗/<br />

79 static void stopDispatcher ( )<br />

80 {<br />

81 s t o p d i s p a t c h e r l o o p = true ;<br />

82 }<br />

83 } ;<br />

84<br />

85<br />

86 #endif // s i m p l e i n p u t h a n d l i n g h<br />

10.2.21 SimpleEventHandl<strong>in</strong>g<br />

Wo Events durch die Gegend geschickt werden, braucht es auch e<strong>in</strong>en Handler<br />

dazu. Die Basisklasse dafür, von der alle Möchtegern-Event-Handler abgeleitet<br />

se<strong>in</strong> müssen, sieht so aus:<br />

1 // simple event handler . h − a simple a b stract event handler<br />

2<br />

3 #ifndef s i m p l e e v e n t h a n d l e r h<br />

4 #def<strong>in</strong>e s i m p l e e v e n t h a n d l e r h<br />

5<br />

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

7<br />

8 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

9 /∗ A simple base c l a s s . All event handlers that s h a l l be used<br />

10 ∗ with SimpleInputHandl<strong>in</strong>g have to be derived from i t<br />

11 ∗/<br />

12<br />

13 class EventHandler<br />

14 {<br />

15 public :<br />

16<br />

17 /∗ Destructor<br />

18 ∗ Just to make sure that a v i r t u a l d e s t r u c t o r e x i s t s<br />

19 ∗/<br />

20 virtual ˜ EventHandler ( ) { }<br />

21<br />

22 /∗ This method i s the c a l l b a c k that i s c a l l e d f o r every s i n g l e<br />

23 ∗ event that i s dispatched .<br />

24 ∗ @param event The event that i s dispatched . I t can be an<br />

25 ∗ a r b i t r a r y s u b c l a s s of Event .<br />

26 ∗/<br />

27 virtual void handleEvent ( const Event &event ) = 0 ;<br />

28 } ;<br />

29<br />

30<br />

31 #endif // s i m p l e e v e n t h a n d l e r h<br />

10.2.22 MemoryGameControl<br />

Die Klasse MemoryGameControl ist die Drehscheibe, die alles steuert, was den<br />

Spielablauf betrifft. Sie ist e<strong>in</strong>erseits dafür verantwortlich, das Spielfeld mit

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!