예제 #1
0
map createNewState(map m, int nPiece, dir d, int dist)
{
	game g = new_game(1, 1, 0, NULL);
	copy_game(m->g, g);
	map r = NULL;
	if (play_move(g, nPiece, d, dist)){
		r = newMap(g, m);
		delete_game(g);
	}
	else
		delete_game(g);
	return r;
}
예제 #2
0
// void deleteMap(map m)
// {
// 	delete_game(m->g);
// 	free(m);
// }
void deleteQueueItem(nodeQueue n)
{
	delete_game(n->m->g);
	free(n->m);
	free(n->next);
	free(n);
}
예제 #3
0
int main(int argc, char* argv[])
{
	if (argc != 3)
	{
		printf("Usage : ./solver [a|r] <file>\n");
		return 1;
	}
	game g = getGameFromConfigFile(argv[2]);
	solve(g, argv[1][0] == 'r',OPTI_MOVES);
	delete_game(g);
	return 0;
}
예제 #4
0
void clean_saves(const std::string& label)
{
	std::vector<save_info> games = get_saves_list();
	std::string prefix = label + "-" + _("Auto-Save");
	LOG_SAVE << "Cleaning saves with prefix '" << prefix << "'\n";
	for (std::vector<save_info>::iterator i = games.begin(); i != games.end(); ++i) {
		if (i->name().compare(0, prefix.length(), prefix) == 0) {
			LOG_SAVE << "Deleting savegame '" << i->name() << "'\n";
			delete_game(i->name());
		}
	}
}
예제 #5
0
int main(int argc, char *argv[]){
  if(argc != 2)
    usage(argv[0]);
  int level = atoi(argv[1]);
  if(level <= 0)
    usage(argv[0]);
  game g = init_game(level);
  char buf[3][100];
  int piece_num;
  dir d;
  int distance;
  int back_code;
  while(!game_over_hr(g)){
    bool good = false;
    while(!good){
      //Loop for the break of cancel instruction
      while(!good){
	system("clear");
	print_game(g);
	printf("Move the pieces for free the piece 0 to the exit:\n");
	printf("Write exit for quit the game or cancel for restart the current move.\n");
	printf("Total move: %d\n",game_nb_moves(g));
	//First loop to take the number piece that you want to move
	back_code = take_piece_num(g, buf[0], &(piece_num));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Second loop to take the direction where you want to move
	back_code = take_direction(g, piece_num, buf[1], &(d));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Third loop to take the number of case that need for the move
	back_code = take_number_case(g, piece_num, d, buf[2], &(distance));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	good = true;
      }
    }
  }
  system("clear");
  print_game(g);
  printf("CONGRATULATION\nYou won in %d moves\n", game_nb_moves(g));
  delete_game(g);
  return EXIT_SUCCESS;
}
예제 #6
0
void manager::remove_old_auto_saves(const int autosavemax, const int infinite_auto_saves)
{
	const std::string auto_save = _("Auto-Save");
	int countdown = autosavemax;
	if (countdown == infinite_auto_saves)
		return;

	std::vector<save_info> games = get_saves_list(NULL, &auto_save);
	for (std::vector<save_info>::iterator i = games.begin(); i != games.end(); ++i) {
		if (countdown-- <= 0) {
			LOG_SAVE << "Deleting savegame '" << i->name << "'\n";
			delete_game(i->name);
		}
	}
}
예제 #7
0
map checkMapExistence(map m, list origin)
{
	if (compareMap(m, origin->m))
	{
		//deleteMap(m);
		//return origin->m;
		delete_game(m->g);
		free(m);
		return NULL;
	}
	if (origin->next == NULL)
	{
		newListItem(m, origin);
		return m;
	}
	return checkMapExistence(m, origin->next);
}
예제 #8
0
void game_manager_t::cleanup_old_games()
{
	if(game_ttl_mins_m>0)
	{
		std::vector<std::string> games_to_delete;

		uint64_t time=get_time();
		uint64_t one_min=60000;

		for(auto ii:games_m)
			if(time-ii.second.modify_time>=one_min*game_ttl_mins_m)
				games_to_delete.push_back(ii.first);

		for(auto name:games_to_delete)
			delete_game(name);
	}
}
예제 #9
0
파일: sgame.c 프로젝트: grrk-bzzt/kqlives
/*! \brief Save/Load menu
 *
 * This is the actual save/load menu.  The only parameter to
 * the function indicates whether we are saving or loading.
 *
 * \param   am_saving 0 if loading, 1 if saving
 * \returns 0 if an error occurred or save/load cancelled
 */
static int saveload (int am_saving)
{
   int stop = 0;

   // Have no more than 5 savestate boxes onscreen, but fewer if NUMSG < 5
   max_onscreen = 5;
   if (max_onscreen > NUMSG)
      max_onscreen = NUMSG;

   play_effect (SND_MENU, 128);
   while (!stop) {
      check_animation ();
      clear_bitmap (double_buffer);
      show_sgstats (am_saving);
      blit2screen (0, 0);

      readcontrols ();
      if (up) {
         unpress ();
         save_ptr--;
         if (save_ptr < 0)
            save_ptr = NUMSG - 1;

         // Determine whether to update TOP
         if (save_ptr < top_pointer)
            top_pointer--;
         else if (save_ptr == NUMSG - 1)
            top_pointer = NUMSG - max_onscreen;

         play_effect (SND_CLICK, 128);
      }
      if (down) {
         unpress ();
         save_ptr++;
         if (save_ptr > NUMSG - 1)
            save_ptr = 0;

         // Determine whether to update TOP
         if (save_ptr >= top_pointer + max_onscreen)
            top_pointer++;
         else if (save_ptr == 0)
            top_pointer = 0;

         play_effect (SND_CLICK, 128);
      }
      if (right) {
         unpress ();
         if (am_saving < 2)
            am_saving = am_saving + 2;
      }
      if (left) {
         unpress ();
         if (am_saving >= 2)
            am_saving = am_saving - 2;
      }
      if (balt) {
         unpress ();
         switch (am_saving) {
         case 0:               // Load
            if (snc[save_ptr] != 0) {
               if (load_game () == 1)
                  stop = 2;
               else
                  stop = 1;
            }
            break;
         case 1:               // Save
            if (confirm_action () == 1) {
               if (save_game () == 1)
                  stop = 2;
               else
                  stop = 1;
            }
            break;
         case 2:               // Delete (was LOAD) previously
         case 3:               // Delete (was SAVE) previously
            if (snc[save_ptr] != 0) {
               if (confirm_action () == 1)
                  delete_game ();
            }
            break;
         }
      }
      if (bctrl) {
         unpress ();
         stop = 1;
      }
   }
   return stop - 1;
}
예제 #10
0
int real_main() {
    srand48(time(NULL));

    if (!al_init()) {
        puts("Could not initialise allegro");
        return 1;
    }
    if (!al_install_keyboard()) {
        puts("Could not initialise allegro keyboard subsystem");
        return 1;
    }
    keys = malloc(sizeof(ALLEGRO_KEYBOARD_STATE));
    if (!init_font()) {
        puts("Could not initialise allegro font subsystem");
        return 1;
    }

    al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);

    ALLEGRO_DISPLAY* display = al_create_display(1, 1);
    if (!display) {
        puts("Could not initialise allegro display");
        return 1;
    }

    Vector size = new_vector();
    size.x = al_get_display_width(display);
    size.y = al_get_display_height(display);

    Game* game = new_game(size);
    int i;
    for (i = 0; i < ASTEROIDN; i++)
        spawn_asteroid(game);

    ALLEGRO_TIMER* timer = al_create_timer(1.0/FPS);

    ALLEGRO_EVENT_QUEUE *timereq = al_create_event_queue();
    ALLEGRO_EVENT_QUEUE *genericeq = al_create_event_queue();
    if (!timereq || !genericeq) {
        puts("Could not create allegro event queue");
        return 1;
    }
    al_register_event_source(timereq, al_get_timer_event_source(timer));

    al_register_event_source(genericeq, al_get_keyboard_event_source());
    al_register_event_source(genericeq, al_get_display_event_source(display));

    al_start_timer(timer); // Start generating timer events
    ALLEGRO_EVENT *timerevent = malloc(sizeof(ALLEGRO_EVENT));
    ALLEGRO_EVENT *genericevent = malloc(sizeof(ALLEGRO_EVENT));

    float last_drawn, now;
    last_drawn = now = al_get_time();
    while (game->status != Quit) {
        al_get_keyboard_state(keys);

        al_wait_for_event(timereq, NULL);
        al_get_next_event(timereq, timerevent);
        // No need to fill up the queue if we are late drawing frames
        al_flush_event_queue(timereq);

        handle_key_status(game, keys);

        while(al_get_next_event(genericeq, genericevent))
            switch(genericevent->type) {
            case ALLEGRO_EVENT_KEY_DOWN:
                handle_key_event(game, genericevent->keyboard.keycode);
                break;

            case ALLEGRO_EVENT_DISPLAY_RESIZE:
                game->size.x = genericevent->display.x;
                game->size.y = genericevent->display.y;
                al_acknowledge_resize(display);
                break;

            case ALLEGRO_EVENT_DISPLAY_CLOSE:
                game->status = Quit;
                break;
            }

        now = al_get_time();
        update_game(game, now - last_drawn);
        last_drawn = now;

        draw_game(game, game->status == Playing ? 1 : 0.2);
        switch(game->status) {
        case Playing:
            break;
        case Paused:
            draw_paused(game);
            break;
        case Won:
            draw_won(game);
            break;
        case Lost:
            draw_lost(game);
            break;
        default:
            break;
        }

        al_flip_display();
    }

    free(timerevent);
    free(genericevent);
    delete_game(game);
    return 0;
}
예제 #11
0
void delete_node(node s){
  delete_game(s->game);
  free(s);
}
예제 #12
0
파일: game_cli.c 프로젝트: norips/projetEPP
int main(int argc, char *argv[])
{
    WINDOW *my_win, *score;
    WINDOW **car;
    game newGame, tmpGame;
    MEVENT event;

    int ch = 0, choosenCar = -1, soluce_move = 0;
    char message[1024];
    bool quit = false;
    bool show_solution = false;
    gameStruct *resultSolv = NULL;
    //INIT
    setup();
    //END INIT
    //Wait for good size
    wait_for_size(MINH, MINW);
    //Instruction
    show_instruction(MINH, MINW);
    while (!quit) {
        quit = false;
        show_solution = false;
        soluce_move = 0;
        strcpy(message, "Playing");
        //Select game
        newGame = select_game();
        //Check for level file
        if (handle_level(&tmpGame)) {
            delete_game(newGame);
            newGame = tmpGame;
            MAXCOL = game_width(newGame);
            MAXROW = game_height(newGame);
            MINH = MAXROW * SIZE + 2;
            MINW = MAXCOL * SIZE;
        }
        car = malloc(sizeof (WINDOW*) * game_nb_pieces(newGame));
        //First draw
        draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        //Loop while the game is not finished
        while (!game_over(newGame)) {
            //Print on bottom of grid
            mvprintw(MAXROW * SIZE + 1, 0, "Please choose car :");
            ch = getch();
            if (ch == 's' && !show_solution) {
                show_solution = true;
                strcpy(message, "Solution");
                resultSolv = solv(newGame, gameOverRh,true);
                if(!resultSolv){
                    strcpy(message, "No solution");
                    show_solution=false;
                }
            }
            if (show_solution) {
                newGame = play_solution(newGame, resultSolv, soluce_move++);
            } else {
                if (KEY_MOUSE == ch) {
                    /* Mouse event. */
                    if (OK == getmouse(&event)) {
                        choosenCar = get_car_with_mouse(event.y, event.x, car, game_nb_pieces(newGame));
                    }
                } else {
                    if (ch == 'q') {
                        quit = true;
                        break;
                    }
                    play_input(newGame, ch, &choosenCar);
                }
            }
            wait_for_size(MINH, MINW);
            erase_game(newGame, my_win, car, score);
            draw_game(newGame, 0, 0, MAXROW, MAXCOL, &my_win, car, &score, choosenCar, message, gameOverRh);
        }
        if (!quit) {
            display_score(newGame);
        }
        for (int i = 0; i < game_nb_pieces(newGame); i++) {
            destroy_win(car[i]);
        }
        destroy_win(my_win);
        destroy_win(score);
        free(car);
        delete_game(newGame);
        if (resultSolv != NULL) {
            delete_game(resultSolv->current);
            free(resultSolv->move);
            free(resultSolv);
            resultSolv = NULL;
        }
    }
    endwin(); /* End curses mode		  */
    return 0;
}
예제 #13
0
파일: game.c 프로젝트: auduchinok/homework
void delete_data()
{
	delete_game();
	delete_all_templates();
}