Ejemplo n.º 1
0
int main() {
	std::vector<t_bomb *> test;
  tinyxml2::XMLDocument xmlDoc;
  tinyxml2::XMLError eResult = xmlDoc.LoadFile("test.xml");
  XMLCheckResult(eResult);
  tinyxml2::XMLNode *pRoot = xmlDoc.FirstChild();
  if (pRoot == 0)
    return tinyxml2::XML_ERROR_FILE_READ_ERROR;
  tinyxml2::XMLElement *pElement = xmlDoc.FirstChildElement("save")->FirstChildElement("players");
  if (pElement == 0) {std::cout << "error" << std::endl; return tinyxml2::XML_ERROR_PARSING_ELEMENT;}
  player(pElement->FirstChildElement("player"));
	test= bombs();
  return (0);
}
Ejemplo n.º 2
0
bool cPlayer::collisionAt(float x, float y)
{
    bool collision = false;

    cMap &map = getMapRef();
    cRect &mapBounds = map.getBounderies();
    cBombContainer &bombs = getBombsRef();

    float nx = x - mapBounds.x1;
    float ny = y - mapBounds.y1;

    if(! map(nx, ny).walkable)
    {
        if(bombs(nx, ny).playerId != this->playerId)
        {
            collision = true;
        }
    }

    return collision;
}
Ejemplo n.º 3
0
int main(void)
{
    //fixed dimensions for board
   static int width, height; 
    // dimension markers 
    int x, y;
    // flag counter
    int flagcount = 0;
    // command character
    char com; 
    
    //check for proper number of arguments and correct data types
    if( scanf(" %c%d%d",&com, &width, &height) != 3 ) 
    {
        //! TEST PRINT
        //printf("initial scanf failure width:%d, height:%d, com:%c\n", width, height, com);
        printf("error\n");
        exit(0); 
    }
    // check for valid initial character 'g'
    if( com !='g')
    {
        //! TEST PRINT
        //printf("game initialisation command wrong com: %c\n", com);
        printf("error\n");
        exit(0); 
    }
    
    //check for valid dimensions 
    if( width < MIN || width > MAX || height < MIN || height > MAX || height * width < 10)
    {
        //! TEST PRINT
        //printf("initial dimension failure width: %d , height: %d\n", width, height);
        printf("error\n");
        exit(0); 
    }
    // print game statement
    printf("%c %d %d\n", com, width, height);
    //initialize minesweeper matrix 
    char mine[width * height];
    //creates border for board
    char board[(width + 2) * (height + 2)];
    boardy(board,width, height);
    
    // intialises minemine,  use 'x' to hold unchecked coordinates
    for(int i = 0; i < height; i++ )
    {
        for(int j = 0; j < width; j++ )
        {
            mine[width * i + j] = 'x'; 
        }
    }
    //state(mine, width, height, board);
  
    //populate with bombs 
    for(int i = 0; i < 10; i++)
    {
        if( scanf(" %c%d%d",&com, &x, &y) != 3)
        {
            //! TEST PRINT
            //printf("scanf fail during bomb phase\n");
            printf("error\n");
            exit(0); 
        }
        //check valid dimensions
        else if( dcheck(width, height, com, mine, x, y, flagcount) != 0)
        {
            //! TEST PRINT
            //printf("dcheck fail during bomb phase\n");
            printf("error\n");
            exit(0); 
        }
        // check valid command
        else if( com != 'b')
        {
            //! TEST PRINT
            //printf("command for bomb not found in bomb adding\n");
            printf("error\n");
            exit(0);
        }
        else
        {
            mine[width * y + x] = 'b';
            printf("%c %d %d\n",com, x, y);
        }
        
    }
    // prints current board 
    state(mine, width, height, board);
    
    //uncover or flag turns given n amount of turns where n = width * height 
    for(int i = 0; i  < width * height; i++)
    {
        if( scanf(" %c%d%d",&com, &x, &y) != 3)
        {
            //! TEST PRINT
            //printf("scanf during placement\n");
            printf("error\n");
            exit(0); 
        }
        
        int check = dcheck(width, height, com, mine, x, y,flagcount);

        if( check != 0)
        {
            // returns 4 if site has a bomb and is flagged 
            if( check == 4 )
            {
            mine[width * y + x] = 'k';
            flagcount++;
            printf("%c %d %d\n",com, x, y);
            }
            else if(check == 3)
            {
            printf("lost\n");
            exit(0); 
            }
            else
            {
            //! TEST PRINT
            //printf("dcheck fail during bomb phase\n");
            printf("error\n");
            exit(0); 
            }
        }
        //check valid dimensions
       
         else if( com != 'u' && com !='f')
        {
            //! TEST PRINT
            //printf("not valid placement command\n");
            printf("error\n");
            exit(0);
        }
        else if ( com == 'u')
        {
            mine[width * y + x] = bombs(mine, width, height, x, y);
            printf("%c %d %d\n",com, x, y);
        }
        else
        {
            mine[width * y + x] = 'f';
            printf("%c %d %d\n",com, x, y);
        }
        state(mine, width, height, board);
    }
    
    //If all steps are made correctly then game is won 
    printf("won\n");
    exit(0);
    
    
    return 0;
   
}