30.06.2013 Aufrufe

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

Softwareentwicklung in C++ - ASC

MEHR ANZEIGEN
WENIGER ANZEIGEN

Erfolgreiche ePaper selbst erstellen

Machen Sie aus Ihren PDF Publikationen ein blätterbares Flipbook mit unserer einzigartigen Google optimierten e-Paper Software.

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

66<br />

67 public :<br />

68<br />

69 /∗ Standard Constructor<br />

70 ∗ The constructor has to c a l l the appropriate methods to<br />

71 ∗ f i l l the vector and d i s t r i b u t e the symbols randomly <strong>in</strong><br />

72 ∗ i t . D i r e c t l y a f t e r construction the symbols can be<br />

73 ∗ obta<strong>in</strong>ed by subsequent c a l l s to getNextSymbol .<br />

74 ∗ I f the number of symbols to be generated i s g r e a t e r than<br />

75 ∗ MAX NUM SYMBOLS i t i s c o r r e c t e d accord<strong>in</strong>gly ( j u s t because<br />

76 ∗ exceptions are not known yet ) .<br />

77 ∗ @param num symbols The number o f symbols that have to<br />

78 ∗ be generated <strong>in</strong> a range from 1 . . .MAX NUM SYMBOLS<br />

79 ∗ @return<br />

80 ∗/<br />

81 explicit MemoryCardSymbolGenerator ( u<strong>in</strong>t32 num symbols ) ;<br />

82<br />

83 /∗ Destructor<br />

84 ∗ Just to make sure a v i r t u a l constructor e x i s t s<br />

85 ∗/<br />

86 virtual ˜ MemoryCardSymbolGenerator ( ) { }<br />

87<br />

88 /∗ D e l i v e r s the symbols one a f t e r the other . I f no more<br />

89 ∗ symbols e x i s t <strong>in</strong> the vector i t returns 0 ( j u s t because<br />

90 ∗ exceptions are not known yet ) .<br />

91 ∗/<br />

92 virtual char getNextSymbol ( ) ;<br />

93 } ;<br />

94<br />

95<br />

96 #endif // memory card symbol generator h<br />

10.2.24 MemoryCardpair<br />

Die Hilfsklasse MemoryCardpair dient zur Vere<strong>in</strong>fachung der Logik <strong>in</strong> der<br />

Spielsteuerung. Sie ist dafür verantwortlich, sich die Karten e<strong>in</strong>es Paars zu<br />

merken und zusätzlich noch zu speichern, was mit ihnen passiert ist, also ob<br />

sie umgedreht wurden oder nicht. Dadurch, dass hier die entsprechende Undo<br />

Information vorhanden ist, unterstützt diese Klasse s<strong>in</strong>nigerweise Methoden<br />

wie Orig<strong>in</strong>alzustand wiederherstellen und man kann sie auch fragen, ob die<br />

Symbole zue<strong>in</strong>ander passen. Dies liest sich dann als Source Code so:<br />

1 // memory cardpair . h − d e c l a r a t i o n o f a p a i r o f cards f o r memory<br />

2<br />

3 #ifndef memory cardpair h<br />

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

5<br />

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

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

8<br />

9 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

10 /∗ U t i l i t y c l a s s f o r manag<strong>in</strong>g c a r d p a i r s <strong>in</strong> the memory game .<br />

11 ∗/<br />

12<br />

13 class MemoryCardpair<br />

14 {<br />

15 public :<br />

16<br />

17 /∗ Status f l a g s to be able to f i n d out whether no card , one

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!