/*- ---------------------------------------------------------------- -*/ int main(int argc, char **argv) { cSettings set; // player settings Inventory inv; // player inventory int sockfd; // socket struct sockaddr_in servaddr; // struct for server address struct hostent *server = NULL; // stores information about the given host // setting the alarm to another handler signal(SIGALRM, catch_alarm_con); // getting parameters to set up the server according to the user initcSettings(argc, argv, &set); // taking data from inventory to a struct for easy management if ( readInventory(set.inventory, &inv) ) { perror("Inventory problem"); return -1; } // printing the inventory to the user printInventory(inv); // initializing socket and server values init(&sockfd, server, &servaddr, set.host_name); // starting up the client clientUp(sockfd, &servaddr, set, inv); // free-ing allocated space free(server); return 0; }
void printAllInventory() { for(int i=0;i<nEntFiles;i++) { printf("%s\n",entFileNames[i]); if(!quiet) printf("<blockId> <amount>\n"); printInventory(i); } }
// sorting itemcode are calculated here void Inventory::sortItem_code(ingredient inventory[]) { x = readFile(); for( int i = 1; i <= x; ++i ) { while( inventory[i].itemcode < inventory[i-1].itemcode ) { // swapping the item so that the lowest is at the top swap( inventory[i].itemcode, inventory[i-1].itemcode ); swap( inventory[i].perPrice, inventory[i-1].perPrice ); swap( inventory[i].itemName, inventory[i-1].itemName ); swap( inventory[i].intrQty, inventory[i-1].intrQty ); // see predefined function above --i; if( !i ) break; } } system("cls"); cout << "Sorted by Itemcode" << endl; bar(); printInventory(inventory, x); update_file(); cout << "\n\nPress any key to continue..."; getch(); menuDisplay(); }
void printMap(SDL_Window* window,block **map, int selectedItem, Player* player){ int i,j; block currentBloc, blockVoid; int nbBlocX = NB_LIGNE; int nbBlocY = NB_COLONNE; blockVoid.type = VOID; blockVoid.back = SKY; for(i=0 ; i<nbBlocX ;i++){ for(j = 0 ; j<nbBlocY ; j++){ int mapX = player->position[0] - (nbBlocX/2) +i; int mapY = player->position[1] - (nbBlocY/2) + j; if((mapX >= 0) && (mapX < SIZE_MAX_X) && (mapY >= 0) && (mapY < SIZE_MAX_Y)){ currentBloc = map[mapX][mapY]; } else{ currentBloc = blockVoid; } printBlock(window, currentBloc, i*24, j*24, false); } } printInventory(window,selectedItem,player); //SDL_UpdateWindowSurface(window); }
/* void MovieTree::printInventory(Movie*) Description: Private, recursive method called by the public printInventory method to print the movies in the tree with title, year, rating, and price. Example: MovieTree tree; tree.printInventory(); Precondition: The ends of the tree are nil. The tree is arranged correctly. Postcondition: All information for every movie is printed to console. If the tree is empty, "Tree is empty" will be printed. */ void MovieTree::printInventory(Movie *m) { if (root == nil) { std::cout << "Tree is empty\n"; return; } if (m->left != nil) { printInventory(m->left); } std::cout << m->title << " (" << m->year << ")\n"; std::cout << "rating: " << m->rating << "\n"; std::cout << "price: $" << m->price << std::endl; if (m->right != nil) { printInventory(m->right); } }
// call this function to easy display the inventory void Inventory::invTempl() { system("cls"); readFile(); // readFile() will return the number of item and save it into x x = readFile(); welcomeMessage(); bar(); // x here are used for iteration counter printInventory(inventory, x); }
void* displayOnScreen(void* screen_void){ ScreenInfo* screen = (ScreenInfo*) screen_void; Process* process = screen->process; while(*screen->isClosed == false){ int i; if(process->player->position[0] != -1){ printMap(screen->win, process->map, *screen->selectedItem, process->player); printInventory(screen->win, *screen->selectedItem, process->player); printPlayer(screen->win, (NB_LIGNE / 2), (NB_COLONNE / 2)); for(i = 0; i < process->nbPlayers - 1; i++){ printPlayer(screen->win, process->players[i].x - process->player->position[0] + (NB_LIGNE / 2), process->players[i].y - process->player->position[1] + (NB_COLONNE / 2)); } SDL_UpdateWindowSurface(screen->win); } usleep(1000000/30); } pthread_exit(NULL); }
int main(void){ // files for input const char fInName[] = "books.in"; const char fOutName[] = "books.out"; // open input and output files FILE* fin = fopen(fInName, "r"); if(fin == NULL){ fprintf(stderr, "ERROR: Can't read input file %s!\n", fInName); exit(EXIT_FAILURE); } FILE* fout = fopen(fOutName, "w"); if(fout == NULL){ fprintf(stderr, "ERROR: Can't read input file %s!\n", fOutName); exit(EXIT_FAILURE); } // buffer to grab input from file char buffer[128]; // get number of test cases fgets(buffer, sizeof(buffer), fin); unsigned numCases = strtoul(buffer, NULL, 10); if(errno == ERANGE){ fprintf(stderr, "ERROR: Too many cases specified; can only process %u cases at a time!\n", (unsigned)(-1)); exit(EXIT_FAILURE); } // go through every test case unsigned x; for(x = 1; x <= numCases; x++){ fprintf(fout, "Test Case #%u:\n", x); // get number of operations fgets(buffer, sizeof(buffer), fin); unsigned numOps = strtoul(buffer, NULL, 10); if(errno == ERANGE){ fprintf(stderr, "ERROR: Too many operations specified; can only process %u operations at a time!\n", (unsigned)(-1)); exit(EXIT_FAILURE); } // loop through all operations node *shop = NULL; struct list *sold_out, *sold_out_end; unsigned soldOutStatus = 0; while(numOps--){ // get operation fgets(buffer, sizeof(buffer), fin); // parse operation // if operation has only 3 arguments, assume SOLD operation unsigned key, quantity; char op[9], title[50], author[30]; if(sscanf(buffer, "%s %u %u %s %s", op, &key, &quantity, author, title) == 3){ // find book entry node *entry = find(shop, key); // check if sold out if(entry->bk->quantity <= quantity){ // if first book to sell out if(!soldOutStatus){ soldOutStatus = 1; // create entry for sold-out books list sold_out = malloc(sizeof(*sold_out)); if(sold_out == NULL){ fprintf(stderr, "ERROR: Unable to allocate memory for sold-out books list!\n"); exit(EXIT_FAILURE); } // add book to sold-out books list strncpy(sold_out->title, entry->bk->title, sizeof(sold_out->title)); strncpy(sold_out->author, entry->bk->author, sizeof(sold_out->author)); sold_out->next = NULL; sold_out_end = sold_out; }else{ // create entry for sold-out books list sold_out_end->next = malloc(sizeof(*sold_out_end->next)); if(sold_out_end->next == NULL){ fprintf(stderr, "ERROR: Unable to allocate memory for sold-out books list!\n"); exit(EXIT_FAILURE); } // add book to sold-out books list sold_out_end = sold_out_end->next; strncpy(sold_out_end->title, entry->bk->title, sizeof(sold_out_end->title)); strncpy(sold_out_end->author, entry->bk->author, sizeof(sold_out_end->author)); sold_out_end->next = NULL; } // remove book entry from inventory shop = delete(shop, entry); }else entry->bk->quantity -= quantity; }else{ // create new book Book *book = malloc(sizeof(*book)); if(book == NULL){ fprintf(stderr, "ERROR: Unable to allocate memory for book!\n"); exit(EXIT_FAILURE); } book->key = key; strncpy(book->title, title, sizeof(book->title)); strncpy(book->author, author, sizeof(book->author)); book->quantity = quantity; // create entry for new book node *entry = malloc(sizeof(*entry)); if(entry == NULL){ fprintf(stderr, "ERROR: Unable to allocate memory for book entry!\n"); exit(EXIT_FAILURE); } entry->left = NULL; entry->right = NULL; entry->bk = book; // insert entry into book inventory shop = insert(shop, entry); } } // print out the inventory printInventory(fout, shop); // print out the sold-out books list while(sold_out != NULL){ fprintf(fout, "The book %s by %s sold out.\n", sold_out->title, sold_out->author); sold_out = sold_out->next; } putc('\n', fout); } return 0; }
int main() { // all of the preliminary shit basically starts here //-------------------------------------------------- srand(time(0)); World gameWorld; Player mainPlayer; gameWorld.height = SQUARE_SIZE; gameWorld.width = SQUARE_SIZE; gameWorld.world = malloc(sizeof(int*) * SQUARE_SIZE); // now we get to tap into the wonders of malloc() int i; for(i = 0; i < SQUARE_SIZE; i++) { gameWorld.world[i] = malloc(sizeof(int) * SQUARE_SIZE); // this is the godliest block in the whole program } createPlayer(&mainPlayer); printPlayerStats(mainPlayer); printf("Your current level: %d\n", mainPlayer.level); printf("Experience required to advance to level %d: %d\n", mainPlayer.level + 1, mainPlayer.nextLevelExp); createWorld(gameWorld.world, gameWorld.height, gameWorld.width, &mainPlayer); gameWorld.world[mainPlayer.positionY][mainPlayer.positionX] = 0; //-------------------------------------------------- // end preliminary bullshit, now we can start the game loop char playerChoice[20]; while(!mainPlayer.isDead) { printf("Where would you like to go?\n"); fgets(playerChoice, 20, stdin); /*----------------------------------------------------------- This section of the game loop handles all of the navigation logic, and after it establishes that the player has made a valid move, it will pass their current position to a function that will handle the actual event that corresponds to the area value. I am so, so sorry for how shitty this looks. I should take the time to clean this up, but it works right now and I'm a lazy piece of f**k. -----------------------------------------------------------*/ if((strcmp(playerChoice, "south\n") == 0) && mainPlayer.positionX < SQUARE_SIZE - 1) { mainPlayer.positionX += 1; playGameSquare(gameWorld.world[mainPlayer.positionX][mainPlayer.positionY], &mainPlayer, mainPlayer.positionX, mainPlayer.positionY, gameWorld.world); } else if((strcmp(playerChoice, "east\n") == 0) && mainPlayer.positionY < SQUARE_SIZE - 1) { mainPlayer.positionY += 1; playGameSquare(gameWorld.world[mainPlayer.positionX][mainPlayer.positionY], &mainPlayer, mainPlayer.positionX, mainPlayer.positionY, gameWorld.world); } else if((strcmp(playerChoice, "west\n") == 0) && mainPlayer.positionY > 0) { mainPlayer.positionY -= 1; playGameSquare(gameWorld.world[mainPlayer.positionX][mainPlayer.positionY], &mainPlayer, mainPlayer.positionX, mainPlayer.positionY, gameWorld.world); } else if((strcmp(playerChoice, "north\n") == 0) && mainPlayer.positionX > 0) { mainPlayer.positionX -= 1; playGameSquare(gameWorld.world[mainPlayer.positionX][mainPlayer.positionY], &mainPlayer, mainPlayer.positionX, mainPlayer.positionY, gameWorld.world); } else if((strcmp(playerChoice, "inventory\n") == 0) || (strcmp(playerChoice, "view inventory\n") == 0)) { printInventory(&mainPlayer, gameWorld.world); } else if((strcmp(playerChoice, "quit\n") == 0) || (strcmp(playerChoice, "exit\n") == 0) || (strcmp(playerChoice, "nowhere\n") == 0)) { break; } else if((strcmp(playerChoice, "status\n") == 0)) { printPlayerStats(mainPlayer); } else if((strcmp(playerChoice, "help\n") == 0) || (strcmp(playerChoice, "?\n") == 0)) { help(); } else { printf("That's wrong, retard. Try again.\n"); } fflush(stdin); // This flushes the buffer - because if I don't, then it // basically shits all over every bit of logic I just wrote } if(mainPlayer.isDead == 1) { endGame(); free(gameWorld.world); return 1; } return 0; }
/* void MovieTree::printInventory() Description: Prints the title, year, rating, and price of each movie in the tree. Example: MovieTree tree; tree.printInventory(); Precondition: The ends of the tree are nil. The tree is arranged correctly. Postcondition: Prints the title, year, rating, and price of each movie in the tree. */ void MovieTree::printInventory() { printInventory(root); }