C++ Maze App

  • _JMRTN
    Likes 0

    Problem Description

    Hi,

    I am currently setting myself a project to make an android app using C++. The idea I had was to make a randomly generated maze each time the user starts, the user will be at the bottom of the screen and they will have to move to the top of the screen. Whilst this is happening, the maze will be moving down the screen, the user dies when their sprite falls of the bottom of the screen. There will be 3 difficulties and the difficulty will determine the speed of which the maze moves up the screen. This is the code that I currently have..

    void Play(Ref *pSender);
    void Options(Ref *pSender);
    void BackgroundImage(Ref *pSender);
    void StopMusic(float dt);
    
    auto menu_item_1 = MenuItemFont::create("Play", CC_CALLBACK_1(HelloWorld::Play, this));
    auto menu_item_2 = MenuItemFont::create("Options", CC_CALLBACK_1(HelloWorld::Options, this));
    auto menu_item_3 = MenuItemImage::create("EPQBackgroundImage.png", CC_CALLBACK_1(HelloWorld::BackgroundImage, this));
    
    Menu_Item_1->setposition(point(visiblesize.width / 2, (visiblesize.height / 4) * 3));
    Menu_Item_2->setposition(point(visiblesize.width / 2, (visiblesize.height / 4) * 2));
    Menu_Item_3->setposition(point(visiblesize.width, (visiblesize.height)));
    
    auto *menu = menu::create(menu_item_1, menu_item_2, menu_item_3, void);
    menu->setPosition(Point(0, 0));
    this->addChild(menu);
    
    void HelloWorld::Play(cocos2d::ref *pSender)
    {
        CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
        CCLOG("Play");        
    }
    
    void HelloWorld::Options(cocos2d::ref *pSender)
    {
      CCLOG("Options");        
    }
    
    void HelloWorld::BackgroundImage(cocos2d::ref *pSender)
    {
      CCLOG("BackgroundImage");        
    }
    
    CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("FILENAME");
    CocosDenshion::SimpleAudioEngine::getInstance()->PlayBackgroundMusic("FILENAME", true);
    
    #include
    #include
    #include
    using namespace std;
     
    int main()
    {
       srand(time(0));
     
       const int maze_size_x= visiblesize.width ;
       const int maze_size_y= 99999999;
       vector < vector < bool > > maze;
       list < pair < int, int> > drillers;
     
       maze.resize(maze_size_y);
       for (size_t y=0;y            maze[y].resize(maze_size_x);
     
       for (size_t x=0;x            for (size_t y=0;y                    maze[y][x]=false;
     
       drillers.push_back(make_pair(maze_size_x/2,maze_size_y/2));
       while(drillers.size()>0)
       {
               list < pair < int, int> >::iterator m,_m,temp;
               m=drillers.begin();
               _m=drillers.end();
               while (m!=_m)
               {
                       bool remove_driller=false;
                       switch(rand()%4)
                       {
                       case 0:
                               (*m).second-=2;
                               if ((*m).second<0 || maze[(*m).second][(*m).first])
                               {
                                       remove_driller=true;
                                       break;
                               }
                               maze[(*m).second+1][(*m).first]=true;
                               break;
                       case 1:
                               (*m).second+=2;
                               if ((*m).second>=maze_size_y || maze[(*m).second][(*m).first])
                               {
                                       remove_driller=true;
                                       break;
                               }
                               maze[(*m).second-1][(*m).first]=true;
                               break;
                       case 2:
                               (*m).first-=2;
                               if ((*m).first<0 || maze[(*m).second][(*m).first])
                               {
                                       remove_driller=true;
                                       break;
                               }
                               maze[(*m).second][(*m).first+1]=true;
                               break;
                       case 3:
                               (*m).first+=2;
                               if ((*m).first>=maze_size_x || maze[(*m).second][(*m).first])
                               {
                                       remove_driller=true;
                                       break;
                               }
                               maze[(*m).second][(*m).first-1]=true;
                               break;
                       }
                       if (remove_driller)
                               m = drillers.erase(m);
                       else
                       {
                               drillers.push_back(make_pair((*m).first,(*m).second));
                               // uncomment the line below to make the maze easier
                               // if (rand()%2)
                               drillers.push_back(make_pair((*m).first,(*m).second));
     
                               maze[(*m).second][(*m).first]=true;
                               ++m;
                       }
               }
       }
     
       // Done
       for (size_t y=0;y            for (size_t x=0;x            {
                       if (maze[y][x]==true)
                               printf(".");
                       else
                               printf("#");
               }
     
       return 0;
    }

     

     

    It is a combination of your tutorials, and random maze generation code I got off the internet.

    Please could you give me help make the app as I am not experienced with c++. Thanks


  • Sonar Systems admin
    Likes 0

    Honestly I would recommend becoming more familiar with C++ first, you can use this series http://www.sonarlearning.co.uk/coursepage.php?topic=desktop&course=cplusplus

     

    This will serve you best in the long term


    This reply has been verified.

Login to reply