void main(void) { int nFrame, nStay; int x, y; SetCursorType(NOCURSOR), init_rand(); for (; 1;) // 게임이 끝났을 경우 다시 시작하거나 끝내는 루프 { Score = 0, bricknum = 0; CLS; // 무한루프에 들어가기전 초기화 for (x = 0; x < BW + 2; x++) // 외부벽 초기화 { for (y = 0; y < BH + 2; y++) { board[x][y] = (y == 0 || y == BH + 1 || x == 0 || x == BW + 1) ? WALL : EMPTY; } } DrawScreen(); nFrame = 10; nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0])); for (; 2;) // 전체 게임 루프 { bricknum++; brick = nbrick; nbrick = make_rand(sizeof(Shape) / sizeof(Shape[0])); // 새 벽돌 생성 DrawNext(); //DrawPresent() nx = BW / 2, ny = 2; rot = 0; PrintBrick(TRUE); if (GetAround(nx, ny, brick, rot) != EMPTY) break; // 게임 끝 점검 nStay = nFrame; for (; 3;) // 벽돌 하나 처리 루프 { if (--nStay == 0) { nStay = nFrame; if (MoveDown()) break; // 벽돌 내림 } if (ProcessKey()) break; // 키처리 delay(1000 / 20); // 시간 지연 } if (bricknum % 5 == 0 && nFrame > 3) nFrame--; } CLS; gotoxy(30, 12), puts("G A M E O V E R"); // 게임 끝 처리 gotoxy(23, 14), puts("If you want restart game press [ Y ]"); // 재시작 gotoxy(27, 16), puts("another any key [ Exit ]"); if (tolower(getch()) != 'y') break; } SetCursorType(NORMALCURSOR); }
void wxTabbedCtrl::OnPaint(wxPaintEvent &) { wxPaintDC dc(this); wxSize size = GetSize(); wxBrush back_brush = wxBrush(GetBackgroundColour()); wxBrush nosel_brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); wxBrush sel_brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)); wxPen border_pen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); wxPen sel_pen = wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNHIGHLIGHT)); wxPen back_pen = wxPen(GetBackgroundColour()); wxFont normal_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); wxFont bold_font = normal_font; bold_font.SetWeight(wxFONTWEIGHT_BOLD); bool mirror = style & wxTB_BOTTOM; bool fullborder = !(style & wxNO_BORDER); dc.BeginDrawing(); //background dc.SetTextBackground(GetBackgroundColour()); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); dc.SetBrush(back_brush); if(fullborder) { dc.SetPen(border_pen); dc.DrawRectangle(0, 0, size.x, size.y); } else { dc.SetPen(back_pen); dc.DrawRectangle(0, 0, size.x, size.y); dc.SetPen(border_pen); dc.DrawLine(0, mirror ? 0 : size.y-1, size.x, mirror ? 0 : size.y-1); } int height, width, pom; dc.SetFont(bold_font); dc.GetTextExtent("Aq", &pom, &height); int posx = 3; //and tabs int i = m_intStartPage; for( ; i < GetPageCount(); i++) { dc.SetPen(border_pen); dc.SetFont((i==GetSelection()) ? bold_font : normal_font); dc.SetBrush((i==GetSelection()) ? sel_brush : nosel_brush); dc.GetTextExtent(GetPageText(i), &width, &pom); int space = padding.x; if( ( posx + width+space+padding.x + BUTTON_BAR_SIZE ) > size.x ) { break; } dc.DrawRoundedRectangle(posx, size.y-height-padding.y*2, width+space+padding.x, height+padding.y*2+3, 3); dc.DrawText(GetPageText(i), posx+space, size.y-height-padding.y); if(i!=GetSelection()) dc.DrawLine(posx, size.y-1, posx+width+space+padding.x, size.y-1); posx += width+space+padding.x; } m_intLastPage = i - 1; //X DrawX(hover, dc); DrawNext( hover_next, dc ); DrawPrev( hover_prev, dc ); DrawMenu( hover_menu, dc ); dc.EndDrawing(); }
void wxTabbedCtrl::OnMouse(wxMouseEvent &ev) { wxPoint mouse = ev.GetPosition(); int page = HitTest(ev.GetPosition()); if(ev.GetEventType()==wxEVT_MOTION) { bool xhover = mouse.x >= x_rect.x && mouse.x <= x_rect.x+x_rect.width && mouse.y >= x_rect.y && mouse.y <= x_rect.y+x_rect.height; bool nhover = (mouse.x >= Next_rect.x && mouse.x <= Next_rect.x + Next_rect.width && mouse.y >= Next_rect.y && mouse.y <= Next_rect.y + Next_rect.height ) && ( m_intLastPage < ( GetPageCount() - 1 ) ); bool phover = (mouse.x >= Prev_rect.x && mouse.x <= Prev_rect.x + Prev_rect.width && mouse.y >= Prev_rect.y && mouse.y <= Prev_rect.y + Prev_rect.height ) && ( m_intStartPage > 0 ); bool mhover = (mouse.x >= Menu_rect.x && mouse.x <= Menu_rect.x + Menu_rect.width && mouse.y >= Menu_rect.y && mouse.y <= Menu_rect.y + Menu_rect.height ); if(hover != xhover) { hover = xhover; wxClientDC dc(this); DrawX(hover, dc); } else if(hover_next != nhover) { hover_next = nhover; wxClientDC dc(this); DrawNext(hover_next, dc); } else if(hover_prev != phover) { hover_prev = phover; wxClientDC dc(this); DrawPrev(hover_prev, dc); } else if ( hover_menu != mhover ) { hover_menu = mhover; wxClientDC dc(this); DrawMenu(hover_menu, dc); } else { wxToolTip * tooltip = GetToolTip(); if ( page != wxNOT_FOUND ) { if ( tipTab != page ) { tipTab = page; tooltip->Enable( true ); wxString info; int pg = page + 1; info << pg << " of " << GetPageCount() << " - " << GetPageText( page ); tooltip->SetTip( info ); } } else { tipTab = -1; tooltip->Enable( false ); } } } else if( ev.GetEventType()==wxEVT_LEFT_UP ) { if(hover ) { wxClientDC dc(this); DrawX(false, dc); SetVisible( active ); wxCommandEvent event( wxEVT_COMMAND_MENU_SELECTED, Menu_Close ); GetEventHandler()->ProcessEvent( event ); } else if( hover_next ) { wxClientDC dc(this); DrawNext(false, dc); if( GetPageCount() > ( m_intStartPage + 1 ) && ( m_intLastPage + 1 ) < GetPageCount() ) { m_intStartPage++; Refresh(); } } else if( hover_prev ) { wxClientDC dc(this); DrawPrev(false, dc); if( m_intStartPage > 0 ) { m_intStartPage--; Refresh(); } } else if( hover_menu ) { hover_menu = false; wxClientDC dc(this); DrawMenu(false, dc); GenerateConextMenu( mouse ); } else { if(page != wxNOT_FOUND) SetSelection(page); } } else if( ev.GetEventType() == wxEVT_RIGHT_UP && page == wxNOT_FOUND ) { GenerateConextMenu( mouse ); } }
/* 현재 블록을 나타내는 창.. 생각해보니 필요없음 void DrawPresent() { int x, y, i; for (x = 32; x <= 44; x = x + 2) { for (y = 12; y <= 17; y++) { gotoxy(x, y); puts(arTile[(x == 32 || x == 44 || y == 12 || y == 17) ? WALL : EMPTY]); } } for (i = 0; i < 4; i++) { gotoxy(37 + (Shape[brick][0][i].x) * 2, 15 + Shape[brick][0][i].y); puts(arTile[BRICK]); } } */ BOOL ProcessKey() { int ch, trot; if (kbhit()) // 눌러진 키가 있을때 { ch = getch(); // 키입력받음 if (ch == 0xE0 || ch == 0) { ch = getch(); switch (ch) { case LEFT: // 왼쪽 if (GetAround(nx - 1, ny, brick, rot) == EMPTY) // 현재 좌표의 왼쪽에 무엇이 있는지 조사 { PrintBrick(FALSE); // 지우고 nx--; // 왼쪽이동 PrintBrick(TRUE); // 출력 } break; case RIGHT: if (GetAround(nx + 1, ny, brick, rot) == EMPTY) { PrintBrick(FALSE); nx++; PrintBrick(TRUE); } break; case UP: trot = (rot == 3 ? 0 : rot + 1); // 다음에 회전시킨 모양을 구한다. if (GetAround(nx, ny, brick, trot) == EMPTY) // 회전 했을때 주변에 무엇이 있는지 조사 { PrintBrick(FALSE); rot = trot; PrintBrick(TRUE); } break; case DOWN: if (MoveDown()) { return TRUE; } break; } } else { switch (tolower(ch)) { case ' ': while (MoveDown() == FALSE) { ; } // 아래로 내려가는것을 반복적으로 호출(한번에 내림) return TRUE; case ESC: exit(0); case 'p': while (1) { gotoxy(20, 13), puts(" < PAUSE > press any key restart"); delay(600); gotoxy(20, 13), puts(" "); delay(600); if (kbhit()) break; } DrawScreen(); DrawNext(); //DrawPresent(); PrintBrick(TRUE); break; } } } return FALSE; }