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.

10.2.13 GameCard<br />

10.2 Das DDD 281<br />

Die Basisklasse für unsere Spielkarte ist e<strong>in</strong>e weitere kle<strong>in</strong>e Variation der im<br />

letzten Kapitel besprochenen Karten, die folgendermaßen aussieht:<br />

1 // game card v3 . h − d e c l a r a t i o n o f a general card f o r games<br />

2<br />

3 #ifndef game card v3 h<br />

4 #def<strong>in</strong>e game card v3 h<br />

5<br />

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

7<br />

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

9 /∗ A general c l a s s of a card f o r games . I t has two s i d e s and can<br />

10 ∗ be turned around . One way of turn<strong>in</strong>g i t i s to d e l i b e r a t e l y put<br />

11 ∗ the f r o n t or the back s i d e up . The other way i s to f l i p the<br />

12 ∗ card . This c l a s s does not handle any other <strong>in</strong>formation than<br />

13 ∗ the v i s i b l e s i d e . I t has noth<strong>in</strong>g to do with d i s p l a y<br />

14 ∗ r e p r e s e n t a t i o n s and other s t u f f .<br />

15 ∗/<br />

16<br />

17 class GameCard<br />

18 {<br />

19 protected :<br />

20<br />

21 /∗ Stores the s i d e of the card that i s v i s i b l e at the moment .<br />

22 ∗/<br />

23 u<strong>in</strong>t8 v i s i b l e s i d e ;<br />

24<br />

25 public :<br />

26<br />

27 /∗ The f o l l o w i n g two constants d e f i n e the p o s s i b l e values f o r<br />

28 ∗ the v i s i b l e s i d e of the card .<br />

29 ∗/<br />

30 static const u<strong>in</strong>t8 FRONT SIDE = 0 x01 ;<br />

31 static const u<strong>in</strong>t8 BACK SIDE = 0x02 ;<br />

32<br />

33 /∗ Standard Constructor<br />

34 ∗ @param v i s i b l e s i d e Has to be e i t h e r o f the two constants<br />

35 ∗ def<strong>in</strong>ed above . The parameter i s checked f o r<br />

36 ∗ v a l i d i t y and i f i t i s i n v a l i d the i n i t i a l l y<br />

37 ∗ v i s i b l e s i d e i s the f r o n t s i d e .<br />

38 ∗/<br />

39 explicit GameCard( u<strong>in</strong>t8 v i s i b l e s i d e ) :<br />

40 v i s i b l e s i d e ( ( ( v i s i b l e s i d e == FRONT SIDE ) | |<br />

41 ( v i s i b l e s i d e == BACK SIDE) ) ?<br />

42 v i s i b l e s i d e : FRONT SIDE) {}<br />

43<br />

44 /∗ Copy Constructor<br />

45 ∗ Implemented e x p l i c i t l y to make sure that i t cannot be<br />

46 ∗ f o r g o t t e n <strong>in</strong> f uture changes .<br />

47 ∗/<br />

48 GameCard( const GameCard & s r c )<br />

49 {<br />

50 v i s i b l e s i d e = s r c . v i s i b l e s i d e ;<br />

51 }<br />

52<br />

53 /∗ Destructor<br />

54 ∗ 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 />

55 ∗/<br />

56 virtual ˜GameCard( ) { }<br />

57<br />

58 /∗ Turns the card to the other s i d e . No checks f o r the<br />

59 ∗ v a l i d i t y of the stored s i d e are necessary because i t s<br />

60 ∗ v a l i d i t y i s f u l l y guaranteed by the constructor and

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!