示例#1
0
/**
 * Inserts a ship to a LinkedList of ships.
 * If the node is not defined, the ship to insert is inserted.
 * Otherwise, the function is called recursively using the next node until the 
 * ship can be inserted.
 * 
 * @param node The node in which to check for the ability to insert.
 * @param toInsert The ship to be inserted.
 */
void insertShip(ship** node, ship* toInsert){
    if(*node == NULL){
        *node = toInsert;
    }
    else{
        insertShip(&(*node)->next, toInsert);
    }
}
void RandomSetShips::setShip(Ship::TubesShip nTubes, Board& board)
{
	Ship ship(nTubes);

	if (checkShip(ship, board))
		insertShip(ship, board);
	else
		setShip(nTubes, board);
}
示例#3
0
/**
 * Processes the user input file and creates a ship for each entry.
 * 
 * @param fr File pointer to specified input file
 * @param head Pointer to pointer of list containing each ship on map
 * @param t Pointer to time_t containing simulator clock
 */
void processInput(FILE *fr, ship** head, time_t *t){
    char line[80];

    //Get the date.
    if((fgets(line, 80, fr) != NULL)){
        struct tm timestamp;
        sscanf(line, "%d %d %d %d %d %d", 
                &timestamp.tm_mday, &timestamp.tm_mon, &timestamp.tm_year, 
                &timestamp.tm_hour, &timestamp.tm_min, &timestamp.tm_sec);

        timestamp.tm_year -= 1900;
        timestamp.tm_isdst = -1;
        *t = mktime(&timestamp);
    }
    
    //Process ship entries.
    while(fgets(line, 80, fr) != NULL){
        if(strcmp(line, "++++++++\n") != 0){
            insertShip(head, createShip(line));
        }
    }
    fclose(fr);
}