Ejemplo n.º 1
0
int main(void) {
    register_debugging_signal_handlers();
    initialize();
    glfwSetErrorCallback(error_callback);
    glfwSetWindowSizeCallback(main_window, window_resize_callback);
    glfwSetFramebufferSizeCallback(main_window, window_resize_callback);
    glfwSetKeyCallback(main_window, key_callback);
    glfwSetScrollCallback(main_window, scroll_callback);
    while (!glfwWindowShouldClose(main_window)) {
        if (event_flag_resized) {
            current_width = new_width;
            current_height = new_height;
            if (grid_index) {
                glDeleteLists(grid_index, 1);
            }
            set_gl_view(current_width, current_height);
            initialize_grid();
            event_flag_resized = 0;
        }
        if (event_flag_zoomed) {
            display_zoom = new_display_zoom;
            event_flag_zoomed = 0;
        }
        redraw();
        glfwPollEvents();
    }
    glfwTerminate();
    exit(EXIT_SUCCESS);
}
Ejemplo n.º 2
0
void initialize_application() {
  gtk_init(0, NULL);

  initialize_window();
  initialize_horizontal_box();
  initialize_grid();
  initialize_vertical_box();
  initialize_button_newgame();
  initialize_score_label();
  initialize_next_piece();

  new_game();
}
Ejemplo n.º 3
0
// -------------------------------------------------------------------------
// Main program to find drone in a grid
int main(int argc, char *argv[]) {

    if (argc != 4) {
	printf("Need four integers as input \n"); 
	printf("Use: <executable_name> <grid_size> <random_seed> <nanosleep_ntime\n"); 
	exit(0);
    }
    // Initialize grid
    gridsize = abs((int) atoi(argv[argc-3])); 		// Do not remove
    int seed = (int) atoi(argv[argc-2]); 		// Do not remove
    int nanosleep_ntime = abs((int) atoi(argv[argc-1]));	// Do not remove
    initialize_grid(gridsize, seed, nanosleep_ntime); 	// Do not remove
    gridsize = get_gridsize();	 			// Do not remove

    clock_gettime(CLOCK_REALTIME, &start); 	// Do not remove

    // Multithreaded code to find drone in the grid 
    // ...
    // ...
    // ... sample serial code shown below ...
    int i, j;
    for (i = 0; i < gridsize; i++) {
	for (j = 0; j < gridsize; j++) {
	    if (check_grid(i,j) == 0) {
		drone_i = i; 
		drone_j = j; 
	    }
	}
    }
    // ...
    // ...
    // ...

    // Compute time taken
    clock_gettime(CLOCK_REALTIME, &stop);			// Do not remove
    total_time = (stop.tv_sec-start.tv_sec)			// Do not remove
	+0.000000001*(stop.tv_nsec-start.tv_nsec);		// Do not remove

    // Check if drone found, print time taken		
    printf("Drone = (%d,%d), success = %d, time (sec) = %8.4f\n", // Do not remove
	    drone_i, drone_j, check_drone_location(drone_i,drone_j), total_time);// Do not remove

    // Other code to wrap up things
    // ...
    // ...
    // ...

}
Ejemplo n.º 4
0
static void initialize(void) {
    samples_drawable_lock = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(samples_drawable_lock, NULL);
    samples_drawable = (TYPE*) calloc(max_window_width, sizeof(TYPE));
    ring_buffer = ring_buffer_init(sizeof_ring_buffer);
    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }
    main_window = glfwCreateWindow(default_window_width, default_window_height, default_window_title, NULL, NULL);
    if (!main_window) {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(main_window);
    glDisable(GL_DEPTH_TEST);
    set_gl_view(current_width, current_height);
    initialize_grid();
    glfwSwapInterval(1);
    producer_thread = malloc(sizeof(pthread_t));
    pthread_create(producer_thread, NULL, signal_source_start, ring_buffer);
}
Ejemplo n.º 5
0
void loop()
{
    if( flag )
    {
        flag = 0;

        initialize_grid();

        explore( X_START, Y_START, 0);

        p.init(EXPLORE_RADIUS*2, START_ADDR);

        int i;
        for( i=0; i<EXPLORE_RADIUS*EXPLORE_RADIUS*4; i++)
        {
            p.write( get_bit( i*BITS_PER_NODE + OBSTRUCTED_BIT_OFFSET) );
        }
        p.flush();
        free_grid();

    }
}
Ejemplo n.º 6
0
/*program for the game "tank"*/
int main()/*begin finction main*/
{
   /*declare variables for this program*/
   int size;
   int x;
   int y;
   int counter = 0;
   int check = 0;
   int checkpos;
   int antibomb = 1;

   printf("\nEnter the grid size: ");/*prompt user to enter a grid size*/
   scanf("%d", &size);/*assign value to the variable size*/

   srand(time(NULL));/*ranomize the function rand*/

   initialize_grid(size);/*initialize the display array*/

   set_bomb(size);/*set bombs and open spots on the grid*/

   set_antibomb(size);/*set two antibombs on grid*/

   while (counter < 5)/*begin game code for 5 rounds of safe tank moves*/
   {
      check = 0;/*set check back to 0*/
      
      while (check == 0)
      {
         printf("\nEnter the x position for tank: ");/*promt user to enter x postition to move tank to*/
         scanf("%d", &x);

         printf("Enter the y position for tank: ");/*prompt user to enter y position to move tank to */
         scanf("%d", &y);
         
         check = error_check(x, y, size); /*check to see that user entered correct coordnance to move tank to*/
      }    

      checkpos = check_position(x, y);/*check to see what lies where user chose to move tank*/

      if (checkpos == 1)/*case user landed on a bomb*/
      { 
         --antibomb;/*remove antibomb*/
         if (antibomb == 0)/*if no anti bombs, GAME OVER*/
         {   
            printf("\nTank was bombed\nYou lost the game\n\n");
            play[y][x] = '$';/*mark where bomb was*/
            display_grid(play, size);/*display play grid*/
            printf("\n");
            return 0;/*game over*/
         }
         else
         {
            printf("Tank was bombed but but anti-bomb saved the tank\n\n");/*if user had an anti bomb, game continues*/
            display_grid(display, size);
         } 
      }
      else if (checkpos == 2)/*case user lands on antibomb*/
      {
         ++antibomb;/*add an antibomb*/
         printf("\nAntibomb collected\n\n");/*let user know they collected an antibomb*/
         display_grid(display, size);/*display grid with moves marked*/
      }
      else
      {
         counter++;/*add one to counter*/
         display[y][x] = '+';/*add one to counter and mark spot that user has already moved to*/
         printf("\n");
         display_grid(display, size);/*display grid with move marked moves*/
      }
   }

   printf("\nCongratulations you won the game.\nTank survived all the bomb attacks.\n\n");/*prompt the user that they have won the game*/

}/*end function main*/
int main()
{
	
	const std::string gol_name = "Game of Life Mini V0.2";
	
	
	const int delaz = 100;
	
	assert(delaz > 0);
	
	const std::chrono::milliseconds delay(delaz);
	
	const int x_size = 80, y_size = 80;
	
	const bool term = false, sfml = true;
	
	assert(x_size > 2);
	assert(x_size <= 100);
	
	assert(y_size > 2);
	assert(y_size <= 100);
	
	assert(generation_loop > 0);
	
	const int dot_size = 8;
	
	const int window_x = x_size*dot_size, window_y = y_size*dot_size;
	
	assert(x_size > 0);
	assert(y_size > 0);
	
	std::vector < std::vector<int>> life_grid(y_size, std::vector<int>(x_size, 0));
	
	std::vector < std::vector<int>> change_grid(y_size, std::vector<int>(x_size, 0));
	
	
	initialize_grid(life_grid);
	
	
	for (int pos = 0; pos < y_size; ++pos)
	{
	
		life_grid[pos][pos] = 1;
		
		life_grid[y_size - 1 - pos][pos] = 1;
	
	}
	
	
	const std::string life_dot_img = "Life_Dot.png";
	
	sf::Texture life_dot_tex;
	
	if (!life_dot_tex.loadFromFile(life_dot_img))
	{
			
		std::cout << life_dot_img << " not found!\n";
			
	}
	
	sf::Sprite life_dot_sprite;
	
	life_dot_sprite.setTexture(life_dot_tex);

	sf::RenderWindow window(sf::VideoMode(window_x, window_y), gol_name, sf::Style::Default);

	
	int cur_gen = 0;
	
	while (window.isOpen())
	{
		
		if (sfml)
		{
			
			show_grid_sfml(life_grid, window, life_dot_sprite, dot_size);
			
		}
		
		if (term)
		{			
			
			show_grid_term(life_grid, cur_gen);
		
		}
		
		next_generation(life_grid, change_grid);
		
		life_grid = change_grid;
		
		++cur_gen;
		
		
		std::this_thread::sleep_for(delay);
		
		if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
		{
			
			window.close();
					
			return 1;
					
		}
		
	}
	
	
	return 0;
	
}