void OnKeyS() { int nRow = g_nCurBoxRow + 1; if (IsCanMove(nRow, g_nCurBoxCol)) { ClearBox(); g_nCurBoxRow++; CreateNewBox(g_nCurBoxType, g_nCurBoxSubType, g_nCurBoxRow, g_nCurBoxCol); ShowGame(); } else { FixBox(); ReleaseLine(); g_nCurBoxType = rand() % (sizeof(g_szBox) / 64); g_nCurBoxSubType = rand() % 4; g_nCurBoxRow = 0; g_nCurBoxCol = 4; CreateNewBox(g_nCurBoxType, g_nCurBoxSubType, g_nCurBoxRow, g_nCurBoxCol); ShowGame(); } }
void Show(void) { /* 初始化控制台 */ ConSetBackgroundColor(ConBlack); ConSetTextColor(ConWhite); ConClear(); switch(iGameStatus) { case GameMainMenu: ShowMenu(); break; case GameRunning: ShowGame(); break; case GameWon: ShowWon(); break; case GameLostLife: ShowLostLife(); break; case GameLost: ShowLost(); break; case GameExit: ShowExit(); break; case GameSplashScreen: ShowSplash(); break; default: break; }/* switch */ }
void ribi::con3::WtConnectThreeGameDialog::RestartGame() { m_state = state_playing; ShowGame(); assert(m_board); m_board->Restart(); UpdatePlayersPanel(); StartTimer(); }
void OnKeyD() { int nCol = g_nCurBoxCol + 1; if (IsCanMove(g_nCurBoxRow, nCol)) { ClearBox(); g_nCurBoxCol++; CreateNewBox(g_nCurBoxType, g_nCurBoxSubType, g_nCurBoxRow, g_nCurBoxCol); ShowGame(); } }
int main() { srand(time(NULL)); InitWall(); g_nCurBoxType = rand() % (sizeof(g_szBox) / 64); g_nCurBoxSubType = rand() % 4; g_nCurBoxRow = 0; g_nCurBoxCol = 4; CreateNewBox(g_nCurBoxType, g_nCurBoxSubType, g_nCurBoxRow, g_nCurBoxCol); ShowGame(); clock_t tLast = 0; clock_t tCur = 0; tLast = clock(); char cKey = 0; while(g_nEndGame == 0) { if(_kbhit()) { cKey = getch(); switch(cKey) { case 'W': case 'w': pfnKey = OnKeyW; break; case 'A': case 'a': pfnKey = OnKeyA; break; case 'S': case 's': pfnKey = OnKeyS; break; case 'D': case 'd': pfnKey = OnKeyD; break; } (*pfnKey)(); } tCur = clock(); if (tCur - tLast >= 600) { tLast = clock(); OnKeyS(); } } return 0; }
void OnKeyW() { int nSubType = (g_nCurBoxSubType + 1) % 4; if (IsCanRotate(nSubType)) { ClearBox(); g_nCurBoxSubType = (g_nCurBoxSubType + 1) % 4; CreateNewBox(g_nCurBoxType, g_nCurBoxSubType, g_nCurBoxRow, g_nCurBoxCol); ShowGame(); } }
void ShowLostLife(void) { ShowGame(); ConSetPosition(20,11); ConSetBackgroundColor(ConGreen); ConSetTextColor(ConRed); ConOutputString("#####################################"); ConSetPosition(20,12); ConOutputString("# 你失去一条生命 #"); ConSetPosition(20,13); ConOutputString("#####################################"); }
void ShowLost(void) { ShowGame(); ConSetPosition(20,11); ConSetBackgroundColor(ConGreen); ConSetTextColor(ConRed); ConOutputString("#####################################"); ConSetPosition(20,12); ConOutputString("# 胜败乃兵家常事, #"); ConSetPosition(20,13); ConOutputString("# 英雄请重新来过。 #"); ConSetPosition(20,14); ConOutputString("#####################################"); }
void ShowWon(void) { ShowGame(); ConSetPosition(20, 11); ConSetBackgroundColor(ConGreen); ConSetTextColor(ConRed); ConOutputString("#####################################"); ConSetPosition(20, 12); ConOutputString("# 恭喜! #"); ConSetPosition(20, 13); ConOutputString("# 你已经杀死了所有的小怪兽。 #"); ConSetPosition(20, 14); ConOutputString("#####################################"); }
ribi::con3::WtConnectThreeGameDialog::WtConnectThreeGameDialog( const boost::shared_ptr<const ConnectThreeResources> resources, const std::bitset<3>& is_player_human) : m_board{}, m_is_player_human(is_player_human), m_players{}, m_resources(resources), m_state(state_playing), m_timer(new Wt::WTimer(this)) { this->setContentAlignment(Wt::AlignCenter); m_timer->timeout().connect( this, &ribi::con3::WtConnectThreeGameDialog::DoComputerTurn); m_timer->setInterval(100); ShowGame(); //OnValidMove(); //Draw screen }