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.

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

59 void MemoryGameboard : : d i s p l a y a b l e R e g i s t e r e d (<br />

60 SimpleOutputHandl<strong>in</strong>g &handler )<br />

61 {<br />

62 // already r e g i s t e r e d with some handler , no f u r t h e r<br />

63 // setup necessary<br />

64 i f ( r o w h e a d i n g d i s p l a y a b l e s )<br />

65 return ;<br />

66<br />

67 u<strong>in</strong>t32 num displayables = ( num rows ∗ num cols ) + // cards<br />

68 num rows + 1 + // EOL elements<br />

69 num rows + 1 + // c o l head<strong>in</strong>gs<br />

70 num cols ; // row head<strong>in</strong>gs<br />

71 r o w h e a d i n g d i s p l a y a b l e s = new Vector (<br />

72 num cols , DisplayableDeletor : : getInstance ( ) ) ;<br />

73 c o l h e a d i n g d i s p l a y a b l e s = new Vector (<br />

74 num rows + 1, DisplayableDeletor : : getInstance ( ) ) ;<br />

75 e o l d i s p l a y a b l e s = new Vector (<br />

76 num rows + 1, DisplayableDeletor : : getInstance ( ) ) ;<br />

77 c o n t a i n e r o u t p u t c o n t e x t = handler . getOutputContextClone ( ) ;<br />

78 conta<strong>in</strong>er output handl<strong>in</strong>g = new SimpleOutputHandl<strong>in</strong>g (<br />

79 num displayables , ∗ c o n t a i n e r o u t p u t c o n t e x t ) ;<br />

80<br />

81 // j u s t because some compilers have a wrong treatment f o r<br />

82 // v a r i a b l e s <strong>in</strong> c o n t r o l statements . . .<br />

83 u<strong>in</strong>t32 row count = 0;<br />

84 u<strong>in</strong>t32 col count = 0;<br />

85<br />

86 // generate the top l i n e with the column head<strong>in</strong>gs and<br />

87 // r e g i s t e r i t<br />

88 IntDisplayable ∗ head<strong>in</strong>g = 0;<br />

89 TextDisplayable ∗ text = 0;<br />

90 // a space needs to be the f i r s t element o f the head<strong>in</strong>gs<br />

91 text = new TextDisplayable ( ” ” ) ;<br />

92 c o l h e a d i n g d i s p l a y a b l e s −>setElementAt ( 0 , text ) ;<br />

93 conta<strong>in</strong>er output handl<strong>in</strong>g −>addDisplayable (∗ text ) ;<br />

94 // the r e s t of the head<strong>in</strong>g l i n e conta<strong>in</strong>s the consecutive<br />

95 // numbers of the columns<br />

96 for ( col count = 1 ; col count setElementAt ( c o l count , head<strong>in</strong>g ) ;<br />

100 conta<strong>in</strong>er output handl<strong>in</strong>g −>addDisplayable (∗ head<strong>in</strong>g ) ;<br />

101 }<br />

102 // an e o l i s placed at the end o f the l i n e<br />

103 text = new TextDisplayable ( ”\n” ) ;<br />

104 e o l d i s p l a y a b l e s −>setElementAt ( 0 , text ) ;<br />

105 conta<strong>in</strong>er output handl<strong>in</strong>g −>addDisplayable (∗ text ) ;<br />

106 // now f o r each row :<br />

107 // ( 1 ) generate the row head<strong>in</strong>g and r e g i s t e r i t<br />

108 // ( 2 ) r e g i s t e r a l l cards <strong>in</strong> the row .<br />

109 // ( 3 ) generate an EOL d i s p l a y a b l e and r e g i s t e r i t<br />

110 for ( row count = 0 ; row count < num rows ; row count++)<br />

111 {<br />

112 head<strong>in</strong>g = new IntDisplayable ( row count + 1 ) ;<br />

113 r o w h e a d i n g d i s p l a y a b l e s −>setElementAt ( row count , head<strong>in</strong>g ) ;<br />

114 conta<strong>in</strong>er output handl<strong>in</strong>g −>addDisplayable (∗ head<strong>in</strong>g ) ;<br />

115 for ( col count = 0 ; col count < num cols ; c o l c o unt++)<br />

116 {<br />

117 // not very e f f i c i e n t but e a s i e r to read<br />

118 conta<strong>in</strong>er output handl<strong>in</strong>g −>addDisplayable (<br />

119 ∗dynamic cast(<br />

120 <strong>in</strong>ternalGetCard ( row count , c o l count ) ) ) ;<br />

121 }<br />

122 text = new TextDisplayable ( ”\n” ) ;<br />

123 e o l d i s p l a y a b l e s −>setElementAt ( row count + 1, text ) ;

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

Erfolgreich gespeichert!

Leider ist etwas schief gelaufen!