Example #1
0
extern void
CommandExportGameText(char *sz)
{

    FILE *pf;

    sz = NextToken(&sz);

    if (!plGame) {
        outputl(_("No game in progress (type `new game' to start one)."));
        return;
    }

    if (!sz || !*sz) {
        outputl(_("You must specify a file to export to (see `help export " "game text')."));
        return;
    }

    if (!confirmOverwrite(sz, fConfirmSave))
        return;

    if (!strcmp(sz, "-"))
        pf = stdout;
    else if ((pf = g_fopen(sz, "w")) == 0) {
        outputerr(sz);
        return;
    }

    ExportGameText(pf, plGame, getGameNumber(plGame), FALSE);

    if (pf != stdout)
        fclose(pf);

    setDefaultFileName(sz);
}
Example #2
0
void PBase::showGameAds()
{
    if (getGameNumber() != GameNumber::P000)
    {
        Common::showAds();
    }
}
World *GameSelectWorld::getWorld()
{
    char *name = itsPlayer->getRoom()->getName();
    if ( (strcmp(name,"SelectGameCustom") == 0) || (strcmp(name,"SelectGameCustomDifficult") == 0) )
    {
        // OK, figure it out
        int gameNumber = 1; // just in case
        for (UINT i=0; i<itsRooms->length(); i++)
        {
            if (strcmp("CustomGame2",((Room*)(itsRooms->elementAt(i)))->getName()) == 0)
            {
                gameNumber = getGameNumber( ((Room*)itsRooms->elementAt(i)) );
                break;
            }
        }

        BOOL hard = strcmp(name,"SelectGameCustomDifficult") == 0;
        BOOL extras = FALSE;

        if ( (itsPlayer->getCarriedObject() != NULL) &&
                (itsPlayer->getCarriedObject()->getType() == GameObject::GAMEOBJECT_TYPE_EXTRAITEMS) )
        {
            extras = TRUE;
        }
        switch (gameNumber)
        {
        case 1 :
            return new Game1World(hard,extras);
            break;
        case 2 :
            return new Game2World(hard,extras);
            break;
        case 3 :
            return new Game3World(hard,extras);
            break;
        case 4 :
            return new Game4World(hard,extras);
            break;
        case 5 :
            return new Game5World(hard,extras);
            break;
        case (theNumberOfGames+1) :
            return new ConnectionTestWorld();
            break;
        case (theNumberOfGames+2) :
            return new ObjectTestWorld();
            break;
        default :
            return new Game1World();

        }
    }
    return NULL;
}
Example #4
0
bool PBase::init()
{
    if ( !WJLayer::init() )
    {
        return false;
    }

#if (COCOS2D_DEBUG)
    CCLOG("Init Scene: %s...", getGameName().c_str());
#endif

    m_winSize = Director::getInstance()->getWinSize();
    m_visibleSize = Director::getInstance()->getVisibleSize();
    m_origin = Director::getInstance()->getVisibleOrigin();
    m_visibleRect = Rect(m_origin.x, m_origin.y, m_visibleSize.width, m_visibleSize.height);

    // top layer
    m_topLayer = WJLayer::create();
    m_topLayer->saveCurrentPosition();
    this->addChild(m_topLayer, ZORDER_TOP_LAYER);

    // p001 welcome
    if (getGameNumber() == GameNumber::P000 || getGameNumber() == GameNumber::P010)
    {
        // android back key
        this->addChild(LBToolbar::createBackKey([&]()
        {
            // quit app
            WJUtils::callaction_void(ACTION_VOID_CONFIRM_QUIT);
        }));
    }
    else
    {
        initPopupMenu();
        initSnapshot();
        initAdsBanner();
    }

    return true;
}
void GameSelectWorld::handleOpenableWalls(Room *room)
{
    char *roomName = room->getName();
    if (strcmp(roomName,"CustomGame2") == 0)
    {
        // yes, this is a bit cheesy, but it's a hell of a lot easier
        ((Wall*)(room->getWalls()->elementAt(3)))->changeColor(0);
        ((Wall*)(room->getWalls()->elementAt(4)))->changeColor(0);
        int gameNumber = getGameNumber(room);
        if (isValidGameNumber(gameNumber))
        {
            Logger::log("Valid game");
            // again with the cheese
            ((Wall*)(room->getWalls()->elementAt(3)))->changeColor(ScreenImage::theTransparencyColor);
            ((Wall*)(room->getWalls()->elementAt(4)))->changeColor(ScreenImage::theTransparencyColor);
        }
    }
}
Example #6
0
void PBase::initPopupMenu()
{
    if (m_popupMenu)
        return;

    m_popupMenu = LBPopupMenu::create(CC_CALLBACK_2(PBase::onPopupMenuClick, this));
    m_popupMenu->setAutoCloseMenu(true);	// auto close

    // menu main button
    m_popupMenu->setMainButton("button/menu.png", m_origin.x + 60, m_visibleRect.getMaxY() - 60, MENU_TAG_POPUP)
    ->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();

    if (!Store::isUnlockedAll())
    {
        // store button
        m_popupMenu->addHorizontalButton("button/store_popup.png", MENU_TAG_STORE)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();
    }

    // home button
    m_popupMenu->addHorizontalButton("button/home.png", MENU_TAG_GOHOME)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();

    if (getGameNumber() != GameNumber::P002)
    {
        // back button
        m_popupMenu->addHorizontalButton("button/back.png", MENU_TAG_BACK)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();
    }

    // music button
    m_popupMenu->addVerticalButton("button/music_on.png", MENU_TAG_MUSIC)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();
    // camera button
    m_popupMenu->addVerticalButton("button/camera.png", MENU_TAG_CAMERA)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();
    // rate button
    m_popupMenu->addVerticalButton("button/rate.png", MENU_TAG_RATE)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();
    // moregame button(fixed)
    m_popupMenu->addFixedVerticalButton("button/moregame.png", MENU_TAG_MOREGAME)->setClickAniType(WJButton::ClickAniType::QBreathing)->noClickMoveEffect();

    // set music button textures
    m_popupMenu->setMusicButtonFile("button/music_on.png", "button/music_off.png");


    m_popupMenu->saveCurrentPosition();
    m_topLayer->addChild(m_popupMenu, ZORDER_POPUPMENU);
}
Example #7
0
void PBase::playGameBgMusic()
{
    switch (getGameNumber())
    {
    case GameNumber::P000:
        Common::sound.playBackgroundMusic("BG:bg001");
        break;
    case GameNumber::P001:
        Common::sound.playBackgroundMusic("BG:bg002");
        break;
    case GameNumber::P002:
        Common::sound.playBackgroundMusic("BG:bg003");
        break;
    case GameNumber::P003:
        Common::sound.playBackgroundMusic("BG:bg002");
        break;
    case GameNumber::P004:
        Common::sound.playBackgroundMusic("BG:bg003");
        break;
    case GameNumber::P005:
        Common::sound.playBackgroundMusic("BG:bg003");
        break;
    case GameNumber::P006:
        Common::sound.playBackgroundMusic("BG:bg002");
        break;
    case GameNumber::P007:
        Common::sound.playBackgroundMusic("BG:bg002");
        break;
    case GameNumber::P008:
        Common::sound.playBackgroundMusic("BG:bg002");
        break;
    case GameNumber::P009:
        Common::sound.playBackgroundMusic("BG:bg004");
        break;
    case GameNumber::P010:
        Common::sound.playBackgroundMusic("BG:bg001");
        break;
    default:
        break;
    }
}
Example #8
0
int BaseAI::gameNumber()
{
  return getGameNumber(c);
}
Example #9
0
bool playGame(AI& fp,AI& sp,char* host,int&results)
{
  //cout<<"PlayGame Function Called"<<endl;
  int socket = open_server_connection(host, "19000");
  if(socket == -1)
  {
    cerr << "Unable to connect to server" << endl;
    return false;
  }
  if(!serverLogin(socket, fp.username(), fp.password()))
  {
    cerr << "Login Failed" << endl;
    return false;
  }
  socket = createGame();
  int game = getGameNumber();
  cout<<"TOP Game: "<<game<<endl;
  //cout<<"Above Fork"<<endl;
  pid_t pID = fork();
  if(pID ==0)//PLAYER 2
  {
    //cout<<"Fork Happened for Player 2"<<endl;
    socket = open_server_connection(host, "19000");
    if(socket == -1)
    {
      cerr << "Unable to connect to server" << endl;
      return false;
    }
    //cout<<"Attempting to log in"<<endl;
    if(!serverLogin(socket, sp.username(), sp.password()))
    {
      return false;
    }
    //cout<<"Joining Game"<<endl;
    socket = joinGame(game);
    //cout<<"Above while loop"<<endl;
    while(networkLoop(socket))
    {
      if(sp.startTurn())
      {
        endTurn();
      }
      else
      {
        getStatus();
      }
    }
  }
  else
  {
    //cout<<"P1 above while"<<endl;
    while(networkLoop(socket))
    {
      if(fp.startTurn())
      {
        endTurn();
      }
      else
      {
        getStatus();
      }
    }
  }

  //Wait for log
  while (networkLoop(socket)){}
  //Get the scores
  results=(fp.getWinValue());
  if(pID == 0)
  {
    close(socket);
       
    exit(0);
    //TODO Hack to kill the spawned copy
  }
  close(socket);
  cout<<"Game["<<game<<"] "<<fp.aiNum<<" VS "<<sp.aiNum<<" final score = "<<results<<endl;
  return true;
}
Example #10
0
extern void
CommandExportPositionText(char *sz)
{

    FILE *pf;
    int fHistory;
    moverecord *pmr;
    int iMove;
    GString *gsz;

    sz = NextToken(&sz);

    if (ms.gs == GAME_NONE) {
        outputl(_("No game in progress (type `new game' to start one)."));
        return;
    }

    if (!sz || !*sz) {
        outputl(_("You must specify a file to export to (see `help export " "position text')."));
        return;
    }
    pmr = get_current_moverecord(&fHistory);

    if (!confirmOverwrite(sz, fConfirmSave))
        return;

    if (!strcmp(sz, "-"))
        pf = stdout;
    else if ((pf = g_fopen(sz, "w")) == 0) {
        outputerr(sz);
        return;
    }

    gsz = g_string_new(NULL);
    TextPrologue(gsz, &ms, getGameNumber(plGame));
    fputs(gsz->str, pf);
    g_string_free(gsz, TRUE);

    if (exsExport.fIncludeMatchInfo)
        TextMatchInfo(pf, &mi);

    if (fHistory)
        iMove = getMoveNumber(plGame, pmr) - 1;
    else if (plLastMove)
        iMove = getMoveNumber(plGame, plLastMove->p);
    else
        iMove = -1;

    gsz = g_string_new(NULL);
    TextBoardHeader(gsz, &ms, getGameNumber(plGame), iMove);
    fputs(gsz->str, pf);
    g_string_free(gsz, TRUE);


    printTextBoard(pf, &ms);

    if (pmr) {

        gsz = g_string_new(NULL);
        TextAnalysis(gsz, &ms, pmr);
        fputs(gsz->str, pf);
        g_string_free(gsz, TRUE);

        if (exsExport.fIncludeAnnotation)
            TextPrintComment(pf, pmr);

    }

    TextEpilogue(pf, &ms);

    if (pf != stdout)
        fclose(pf);

    setDefaultFileName(sz);

}
Example #11
0
std::string PBase::getGameName()
{
    return Common::getGameName(getGameNumber());
}