home | |||
links |
|
||
developer's mag main page article part 1 part 2 part 3 part 4 part 5 part 6 part 7 part 8 part 9 |
7 - Status CheckAre we done yet? No, there's still more. In playing the game, it's obvious that remembering whose turn it is can be annoying, so we let the program do it by changing the text at the bottom of the main screen into a status display:void paTicTacToe:: DrawStatus(const char *text) { // general status display - draw old text in white to erase, then new in black if ( NULL!=text ) // if null passed in, we simply redraw current & and skip clear { if ( m_statusText[0] ) // anything to erase? write it in white DrawText(m_statusText,m_statusX,206,0,COLOR_WHITE,COLOR_WHITE,-1,IMG_CMB_SRC); // now get new status text strcpy(m_statusText,text); } RECT rect; GetUsableRect(&rect); // and draw new text m_statusX=(rect.width-GUI_TextWidth(GetFont(),m_statusText,-1))/2; // center it DrawText(m_statusText,m_statusX,206,0,COLOR_BLACK,COLOR_WHITE,-1,IMG_CMB_SRC); }DrawStatus() stores a copy of the text, and then draws it. To speed up drawing, and avoid excessive graphical work, we use an old trick - we write the previous text in white (thereby erasing it), before we draw the new in black. The result is a fairly efficient way to draw the single line (as an alternative, we could also blank the background by drawing a white rectangle the length and height of the previous status text). The DrawStatus() call is made wherever the program needs to change the message, such as on a new turn, or when the game ends. In the case of Draw() of course, we don't know what the status text is, so we pass it a NULL pointer, which lets it bypass the erasing and setting of the text, simply redrawing the current status text. Previous Section Next Section |
||
Copyright © 2001-2006 ebmDevMag.com - Legal Notice |