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.

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

36<br />

37<br />

38 #e n d i f // simple argument handler h<br />

10.2.7 MemoryCommandl<strong>in</strong>eArgumentHandler<br />

Da wir gerade das entsprechende Interface kennen gelernt haben, sehen wir<br />

uns auch gleich die entsprechende Implementation an, die <strong>in</strong> unserem Spiel<br />

Anwendung f<strong>in</strong>den wird.<br />

1 // memory commandl<strong>in</strong>e arg handler . h − s p e c i a l argument handler<br />

2 // f o r the memory game<br />

3<br />

4 #ifndef memory commandl<strong>in</strong>e arg handler h<br />

5 #def<strong>in</strong>e memory commandl<strong>in</strong>e arg handler h<br />

6<br />

7 //−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−<br />

8 /∗ The commandl<strong>in</strong>e argument handler f o r the memory game<br />

9 ∗ I t i s implemented as a simple conta<strong>in</strong>er that s t o r e s the number<br />

10 ∗ o f rows and columns that are s e t via c a l l b a c k s from the<br />

11 ∗ Commandl<strong>in</strong>eHandl<strong>in</strong>g or a compatible c l a s s .<br />

12 ∗/<br />

13<br />

14 class MemoryCommandl<strong>in</strong>eArgumentHandler : public ArgumentHandler<br />

15 {<br />

16 protected :<br />

17<br />

18 /∗ The i n d i c e s of the number of rows and columns accord<strong>in</strong>g to<br />

19 ∗ the commandl<strong>in</strong>e s p e c i f i c a t i o n o f the game ( argv [ 0 ] = progname ,<br />

20 ∗ argv [ 1 ] = rows , argv [ 2 ] = c o l s ) .<br />

21 ∗/<br />

22 static const u<strong>in</strong>t32 ROW DEF INDEX = 1;<br />

23 static const u<strong>in</strong>t32 COL DEF INDEX = 2;<br />

24<br />

25 /∗ The number of rows of the gameboard<br />

26 ∗/<br />

27 u<strong>in</strong>t32 num rows ;<br />

28<br />

29 /∗ The number of columns of the gameboard<br />

30 ∗/<br />

31 u<strong>in</strong>t32 num cols ;<br />

32<br />

33 public :<br />

34<br />

35 /∗ Default constructor<br />

36 ∗ I n i t i a l i z e s a l l v a r i a b l e s to 0<br />

37 ∗/<br />

38 MemoryCommandl<strong>in</strong>eArgumentHandler ( ) :<br />

39 num rows ( 0 ) , num cols ( 0) { }<br />

40<br />

41 /∗ Destructor<br />

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

43 ∗/<br />

44 virtual ˜ MemoryCommandl<strong>in</strong>eArgumentHandler ( ) { }<br />

45<br />

46 /∗ Callback f o r a n o t i f i c a t i o n accord<strong>in</strong>g to the base i n t e r f a c e<br />

47 ∗ I f everyth<strong>in</strong>g i s ok t h i s c a l l b a c k w i l l be c a l l e d f o r two<br />

48 ∗ arguments : The number of rows and the number o f columns .<br />

49 ∗ Accord<strong>in</strong>g to the convention both arguments w i l l be passed<br />

50 ∗ as p o i n t e r s to u<strong>in</strong>t32 . See a l s o c l a s s Commandl<strong>in</strong>eHandl<strong>in</strong>g<br />

51 ∗ @param <strong>in</strong>dex The <strong>in</strong>dex of the argument <strong>in</strong> the commandl<strong>in</strong>e .

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!