⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game.cpp

📁 上面上传的autotools一文(也就是《使用GNU autotools 改造一个软件项目》)配套的示例程序源代码。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//// Copyright (c) 2005, Wei Mingzhi <whistler@openoffice.org>// All Rights Reserved.//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License as// published by the Free Software Foundation; either version 2 of// the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA// 02110-1301, USA//#include "main.h"CGame *gpGame = NULL;CGame::CGame():m_iCurGirl(-1),m_iLevelClearFlag(0){   m_pPlayer = new CPlayer;   m_pBot = new CBot;   if (m_pPlayer == NULL || m_pBot == NULL) {      TerminateOnError("CGame::CGame(): Not enough memory!");   }   m_pPlayer->m_pOpponent = m_pBot;   m_pBot->m_pOpponent = m_pPlayer;   m_iFirstChancePercent = atoi(cfg.Get("GAME", "FirstChancePercent", "20"));   m_iLastChancePercent = atoi(cfg.Get("GAME", "LastChancePercent", "20"));   m_iReachBonusPercent = atoi(cfg.Get("GAME", "ReachBonusPercent", "5"));   m_iBonusGamePercent = atoi(cfg.Get("GAME", "BonusGamePercent", "2"));   m_iSanGenRushPercent = atoi(cfg.Get("GAME", "SanGenRushPercent", "5"));   m_iTotalDonDen = atoi(cfg.Get("GAME", "DonDen", "5"));   if (m_iTotalDonDen > 8) {      m_iTotalDonDen = 8;   }}CGame::~CGame(){   if (m_pPlayer != NULL)      delete m_pPlayer;   if (m_pBot != NULL)      delete m_pBot;}void CGame::RunGame(){   m_iTotalScore = 0;   while (1) {      if (m_iCurGirl == -1) {         SelectCurGirl();      }      GameInit();      while (1) {         NewRound();         PlayRound();         if (m_pPlayer->m_iScore <= 0) {            gpGeneral->GameOver();            m_iTotalScore = 0;            break;         } else if (m_pBot->m_iScore <= 0) {            m_iTotalScore += m_pPlayer->m_iScore;            StageClear();            break;         }      }   }}void CGame::DonDen(){   if (m_iDonDen >= m_iTotalDonDen ||      m_pBot->m_iNumDiscarded >= 20 ||      m_pPlayer->m_iNumDiscarded >= 20) {      return;   }   m_iDonDen++;   int i;   CTile justgot = 0;   for (i = 0; i < m_pPlayer->m_Hand.m_iNumTiles; i++) {      if (m_pPlayer->m_Hand.m_Tiles[i].flags & HT_JUSTGOT) {         justgot = m_pPlayer->m_Hand.m_Tiles[i].tile;         m_pPlayer->m_Hand.RemoveTile(i);         break;      }   }   discarded_t d[20];   int dis = m_pPlayer->m_iNumDiscarded;   for (i = 0; i < dis; i++) {      d[i] = m_pPlayer->m_Discarded[i];   }   m_pPlayer->m_iNumDiscarded = m_pBot->m_iNumDiscarded;   for (i = 0; i < m_pBot->m_iNumDiscarded; i++) {      m_pPlayer->m_Discarded[i] = m_pBot->m_Discarded[i];   }   m_pBot->m_iNumDiscarded = dis;   for (i = 0; i < dis; i++) {      m_pBot->m_Discarded[i] = d[i];   }   CHand b = m_pPlayer->m_Hand;   m_pPlayer->m_Hand = m_pBot->m_Hand;   m_pBot->m_Hand = b;   if (justgot() != 0) {      m_pPlayer->m_Hand.AddTile(justgot, HT_JUSTGOT);   }   bool r = m_pBot->m_fReach;   m_pBot->m_fReach = m_pPlayer->m_fReach;   m_pPlayer->m_fReach = r;   gpGeneral->EraseArea(0, 0, 640, 200);   gpGeneral->UpdateScreen(0, 0, 640, 200);   gpGeneral->EraseArea(0, 265, 640, 480 - 265);   gpGeneral->UpdateScreen(0, 265, 640, 480 - 265);   gpGeneral->PlaySound(SND_DISCARD1);   UTIL_Delay(300);   gpGeneral->PlaySound(SND_DISCARD2);   m_pPlayer->DrawHand();   m_pPlayer->DrawDiscarded();   m_pBot->DrawHand();   m_pBot->DrawDiscarded();   DrawDonDen();}void CGame::NewRound(){   if (m_pBot->m_iScore < 0 || m_pPlayer->m_iScore < 0) {      GameInit();   }   CTile::NewRound();   m_fBonusGame = false;   if (RandomLong(0, 100) < m_iBonusGamePercent) {      gpGeneral->BonusGame();      m_fBonusGame = true;   }   for (int i = 0; i < 6; i++) {      m_Dora[i] = CTile::RandomTile();   }   m_pPlayer->NewRound();   m_pBot->NewRound();   m_fSanGenRush = false;   if (RandomLong(1, 100) < m_iSanGenRushPercent && !m_fBonusGame) {      m_fSanGenRush = true;      ((CPlayer *)m_pPlayer)->SanGenInit();   }   if (m_fBonusGame) {      m_pPlayer->GetBonusHand();      m_pBot->GetHand();      gpGeneral->PlayBGMusic(6);   } else {      m_pPlayer->GetHand();      m_pBot->GetHand();      gpGeneral->PlayBGMusic(RandomLong(0, 1000) & 1);   }   gpGeneral->DrawBGFade(m_iCurGirl, 1);   gpGeneral->UpdateScreen();   UTIL_Delay(1000);   DealTiles();   gpGeneral->PlaySound(SND_DISCARD1);   m_pPlayer->m_Hand.Sort();   m_pBot->m_Hand.Sort();   gpGeneral->EraseArea(0, 0, 640, 18 + TILE_HEIGHT_CONCEALED);   gpGeneral->EraseArea(0, 380, 640, TILE_HEIGHT_CONCEALED);   gpGeneral->DrawTiles(NULL, 13, 72, 18, WALL_CONCEALED);   gpGeneral->DrawTiles(NULL, 13, 20, 396, WALL_CONCEALED);   gpGeneral->UpdateScreen(0, 0, 640, 18 + TILE_HEIGHT_CONCEALED);   gpGeneral->UpdateScreen(0, 380, 640, 100);   UTIL_Delay(1000);   gpGeneral->PlaySound(SND_DISCARD1);   m_pPlayer->DrawHand();   m_pBot->DrawHand();   UTIL_Delay(1000);   gpGeneral->DrawBG(m_iCurGirl, 0);   m_pPlayer->DrawHand();   m_pBot->DrawHand();   gpGeneral->DrawTiles(NULL, 7, 415, 215, WALL_CONCEALED, 0);   gpGeneral->DrawTiles(NULL, 7, 415, 200, WALL_CONCEALED, 0);   gpGeneral->DrawTile(m_Dora[0], (int)(415 + TILE_WIDTH * 0.7 * 2),      200, WALL_SHOWN, 0);   gpGeneral->DrawTurn(m_iRound, 387, 202);   m_iDonDen = 0;   DrawScore();   DrawDonDen();   gpGeneral->UpdateScreen();   m_iKongs = 0;   m_fReachBonus = false;   if (RandomLong(0, 100) < m_iReachBonusPercent && !m_fBonusGame && !m_fSanGenRush) {      m_fReachBonus = true;      gpGeneral->DrawMessage(msg("hint_reachbonus"));      gpGeneral->WaitForAnyKey();      gpGeneral->DrawMessage(NULL);   }}void CGame::DealTiles(){   gpGeneral->DrawTiles(NULL, 10, 100, 145, WALL_CONCEALED);   gpGeneral->DrawTiles(NULL, 10, 100, 125, WALL_CONCEALED);   gpGeneral->DrawTiles(NULL, 10, 100, 250, WALL_CONCEALED);   gpGeneral->DrawTiles(NULL, 10, 100, 230, WALL_CONCEALED);   gpGeneral->UpdateScreen(100, 125, TILE_WIDTH * 10, TILE_HEIGHT_WALL + 20);   gpGeneral->UpdateScreen(100, 230, TILE_WIDTH * 10, TILE_HEIGHT_WALL + 20);   SDL_Delay(500);   CBasePlayer *pCurrent = m_pPlayer;   if (pCurrent->m_iTurn != TURN_EAST) {      pCurrent = pCurrent->m_pOpponent;   }   int i;   for (i = 0; i < 8; i++) {      int t = (i / 2 + 1) * 4;      if (t > 13) {         t = 13;      }      if (i == 0) {         gpGeneral->EraseArea(100 + TILE_WIDTH * 8, 230, TILE_WIDTH * 2, TILE_HEIGHT_WALL + 20);      } else if (i == 1) {         gpGeneral->EraseArea(100 + TILE_WIDTH * 8, 125, TILE_WIDTH * 2, TILE_HEIGHT_WALL + 20);      } else if (i == 6) {         gpGeneral->EraseArea(100 + TILE_WIDTH * 7, 125, TILE_WIDTH, TILE_HEIGHT_WALL + 20);         gpGeneral->DrawTiles(NULL, 1, 100 + TILE_WIDTH * 7, 150, WALL_CONCEALED);      } else if (i == 7) {         gpGeneral->EraseArea(100 + TILE_WIDTH * 7, 125, TILE_WIDTH, TILE_HEIGHT_WALL + 20);      } else {         gpGeneral->EraseArea(100 + TILE_WIDTH * (8 - i * 2 + 2), 230, TILE_WIDTH * 2, TILE_HEIGHT_WALL + 20);      }      gpGeneral->UpdateScreen(100, 125, TILE_WIDTH * 10, TILE_HEIGHT_WALL + 20);      gpGeneral->UpdateScreen(100, 230, TILE_WIDTH * 10, TILE_HEIGHT_WALL + 20);      pCurrent->m_Hand.m_iNumTiles = t;      pCurrent->DrawHand();      pCurrent = pCurrent->m_pOpponent;      gpGeneral->PlaySound(SND_BOOM);      UTIL_Delay(250);   }   m_pBot->m_Hand.m_iNumTiles = m_pPlayer->m_Hand.m_iNumTiles = 13;   UTIL_Delay(750);   gpGeneral->EraseArea(100, 125, TILE_WIDTH * 7, TILE_HEIGHT_WALL + 20);   gpGeneral->DrawTiles(NULL, 7, 415, 215, WALL_CONCEALED, 0);   gpGeneral->DrawTiles(NULL, 7, 415, 200, WALL_CONCEALED, 0);   gpGeneral->PlaySound(SND_BOOM);   gpGeneral->UpdateScreen();   UTIL_Delay(750);}void CGame::SelectCurGirl(){   gpGeneral->DrawBG(4, 0);   if (m_iLevelClearFlag == ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3))) {      m_iLevelClearFlag = 0; // If all level are clear, restart from the beginning   }   if (m_iLevelClearFlag & (1 << 0))      gpGeneral->DrawGirl(20, 20, 280, 200, 0, 0);   else      gpGeneral->DrawGirl(20, 20, 280, 200, 0, 1);   if (m_iLevelClearFlag & (1 << 1))      gpGeneral->DrawGirl(340, 20, 280, 200, 1, 0);   else      gpGeneral->DrawGirl(340, 20, 280, 200, 1, 1);   if (m_iLevelClearFlag & (1 << 2))      gpGeneral->DrawGirl(20, 260, 280, 200, 2, 0);   else      gpGeneral->DrawGirl(20, 260, 280, 200, 2, 1);   if (m_iLevelClearFlag & (1 << 3))      gpGeneral->DrawGirl(340, 260, 280, 200, 3, 0);   else      gpGeneral->DrawGirl(340, 260, 280, 200, 3, 1);   gpGeneral->DrawText("A", 40, 30, 1);   gpGeneral->DrawText("B", 360, 30, 1);   gpGeneral->DrawText("C", 40, 270, 1);   gpGeneral->DrawText("D", 360, 270, 1);   gpGeneral->DrawUTF8Text(msg("girlselmsg"), 55, 225, 0, 255, 255, 0);   gpGeneral->UpdateScreen();   gpGeneral->PlayBGMusic(4);   while (1) {      SDLKey key = gpGeneral->ReadKey();      if (key == SDLK_a && !(m_iLevelClearFlag & (1 << 0))) {         gpGeneral->PlaySound(SND_DING);         gpGeneral->DrawGirl(20, 20, 280, 200, 0, 0);         gpGeneral->DrawText("A", 40, 30, 1, 250, 250, 0);         gpGeneral->UpdateScreen(20, 20, 280, 200);         m_iCurGirl = 0;         UTIL_Delay(800);         break;      } else if (key == SDLK_b && !(m_iLevelClearFlag & (1 << 1))) {         gpGeneral->PlaySound(SND_DING);         gpGeneral->DrawGirl(340, 20, 280, 200, 1, 0);         gpGeneral->DrawText("B", 360, 30, 1, 250, 250, 0);         gpGeneral->UpdateScreen(340, 20, 280, 200);         m_iCurGirl = 1;         UTIL_Delay(800);         break;      } else if (key == SDLK_c && !(m_iLevelClearFlag & (1 << 2))) {         gpGeneral->PlaySound(SND_DING);         gpGeneral->DrawGirl(20, 260, 280, 200, 2, 0);         gpGeneral->DrawText("C", 40, 270, 1, 250, 250, 0);         gpGeneral->UpdateScreen(20, 260, 280, 200);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -