void main_update(struct Game *game) { /* set the of the player */ game->input = gather_input(); handle_input(game); /* save the opposite of the player's input so we can 'replay' it */ game->past_input_frame = ++game->past_input_frame % INPUT_FRAMES; game->past_input[game->past_input_frame] = opposite_input(game->input); handle_asteroids(game->asteroids, game->speed, game->current_max_asteroids); handle_stars(game->stars, game->speed); }
int mod_ui::show_layering_ui() { DebugLog() << "mod_ui:: now showing layering ui\n"; const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; const int header_y = 4; const int list_y = 6; const int shift_y = list_y + 1; DebugLog() << "iOffsetX <" << iOffsetX << ">\tiOffsetY <" << iOffsetY << ">\n"; DebugLog() << "TERMX, TERMY <" << TERMX << ", " << TERMY << ">\nFULL_SCREEN_[WIDTH|HEIGHT] <" << FULL_SCREEN_WIDTH << ", " << FULL_SCREEN_HEIGHT << ">\n"; std::vector<std::string> available_cores, available_supplementals; std::vector<std::string> ordered_mods, active_mods; for(mod_manager::t_mod_map::iterator a = active_manager->mod_map.begin(); a != active_manager->mod_map.end(); ++a) { MOD_INFORMATION *mod = a->second; switch(mod->_type) { case MT_CORE: available_cores.push_back(mod->ident); break; case MT_SUPPLEMENTAL: available_supplementals.push_back(mod->ident); break; } } std::vector<std::string>::iterator it = ordered_mods.begin(); ordered_mods.insert(it, available_supplementals.begin(), available_supplementals.end()); it = ordered_mods.begin(); ordered_mods.insert(it, available_cores.begin(), available_cores.end()); // set up windows for display WINDOW *mod_screen;//, *mod_infopanel, *mod_list, *mod_order; mod_screen = newwin(FULL_SCREEN_HEIGHT, FULL_SCREEN_WIDTH, iOffsetY, iOffsetX); werase(mod_screen); std::vector<std::string> headers; headers.push_back(" Mod List "); headers.push_back(" Mod Load Order "); int selection[2] = {0, 0}; int active_header = 0; do { werase(mod_screen); draw_layering_ui_lines(mod_screen); draw_headers(mod_screen, header_y, headers, active_header); draw_modlist(mod_screen, list_y, 0, ordered_mods, active_header == 0, selection[0]); draw_modlist(mod_screen, list_y, FULL_SCREEN_WIDTH / 2 + 2, active_mods, active_header == 1, selection[1]); if (active_header == 1) { draw_shift_information(mod_screen, shift_y, FULL_SCREEN_WIDTH / 2 - 2, active_mods, selection[1]); } refresh(); wrefresh(mod_screen); refresh(); if (gather_input(active_header, selection[active_header], ordered_mods, active_mods) != 0) { return -1; } } while(true); }
int main(void) { char decission[50]; int s, sem; packet* rec = malloc(sizeof (packet)); if(rec == NULL){ ERR("malloc"); } packet* tmp = malloc(sizeof (packet)); if(tmp == NULL){ ERR("malloc"); } char c; int x, y, points,i; int isAnyTileAvaliable; semaphore_init(&sem, 'E', 1); /* Set signals handlers */ if(sethandler(sigint_handler,SIGINT)) ERR("Setting SIGINT:"); if(sethandler(sigterm_handler,SIGTERM)) ERR("Setting SIGTERM:"); /********* TCP IP *********/ s = tcp_connect_socket("localhost", 2000); printf("##############################\n"); printf("## WELCOME TO SCRABBLE GAME ##\n"); printf("##############################\n"); while (g_doWork) { int t; if ((t = tcp_socket_read_packet(s, rec)) == 0 && g_doWork==1) { perror("Server closed connection client\n"); break; } else if (t < 0) { perror("recv"); break; } switch (rec->msg) { case NO_PLAYER: printf("Waiting for another player to connect...\n"); break; case PAIR_MATCH: printf("Player found - starting the game...\n"); break; case INFO: printf("Player found - starting the game...\n"); scrabble_game_print_title(); scrabble_game_print_board(rec->currentBoard); scrabble_game_print_wait_for_move(); break; case REQUEST_MOVE: /* Print points in the right order */ scrabble_game_print_title(); scrabble_game_print_points(rec->p1Points, rec->p2Points, rec->playerType); /* Print current board state */ scrabble_game_print_board(rec->currentBoard); /* Print available tiles */ printf("----------------------------------------\n "); scrabble_game_print_available_tiles(rec->tiles, 5); printf("----------------------------------------\n"); isAnyTileAvaliable = 0; for(i=0; i<5;i++){ if(rec->tiles[i] != 'x'){ isAnyTileAvaliable = 1; } } if(isAnyTileAvaliable == 1) { points = 0; if(-1 == gather_input(&c, &x, &y, &points, rec->tiles, rec->currentBoard)) { printf("gater input error\n"); }else { /* Print updated points */ scrabble_game_print_title(); if (rec->playerType == FIRST) rec->p1Points += points; if (rec->playerType == SECOND) rec->p2Points += points; scrabble_game_print_points(rec->p1Points, rec->p2Points, rec->playerType); /* Print updated board */ rec->currentBoard[x][y] = c; scrabble_game_print_board(rec->currentBoard); /* Send data to server. */ tmp->msg = MOVE_DATA; tmp->letter = c; tmp->x_coord = x; tmp->y_coord = y; tmp->p1Points = rec->p1Points; tmp->p2Points = rec->p2Points; tcp_socket_send_packet(s, tmp); scrabble_game_print_wait_for_move(); } } else{ printf("##########################################\n"); printf("## END OF MATCH ##\n"); printf("##########################################\n"); printf("Do you want to play another game?(Y/N)\n"); scanf(" %c", decission); printf("%s \n",decission); tmp->isMatchOngoing = -1; if (decission[0] == 'Y') { tmp->msg = PLAY_ANOTHER_GAME; tcp_socket_send_packet(s, tmp); } else { tmp->msg = FINISH_GAME; printf("isMatchOngoing = %d \n", tmp->isMatchOngoing); tcp_socket_send_packet(s, tmp); return EXIT_SUCCESS; } } break; case DISCONNECTED: printf("##########################################\n"); printf("## Connection lost! ##\n"); printf("##########################################\n"); printf("Sorry but connection with other player is\n"); printf("lost. Do you want to play another game?(Y/N)\n"); scanf(" %c", decission); printf("%s \n",decission); if (decission[0] == 'Y') { tmp->msg = PLAY_ANOTHER_GAME; tcp_socket_send_packet(s, tmp); } else { tmp->msg = FINISH_GAME; tcp_socket_send_packet(s, tmp); return EXIT_SUCCESS; } break; case EXIT: printf("Server disconnected.\n"); return EXIT_SUCCESS; default: printf("Cannot interpret packet's message: %d \n", rec->msg); } }; printf("Disconnected\n"); if(-1 == close(s)){ ERR("close"); } return 0; }