Example #1
0
int on_game_begin(sprite_t* p)
{
	game_group_t* grp = p->group;
	DEBUG_LOG("CheerSquadShow BEGIN\t[uid=%u gid=%u grpid=%u action=%u]", p->id, grp->game->id, grp->id, p->action);

	if (grp->game->id == 92 && grp->count == p->group->game->players) {
		CheerSquadShow::new_rsp_cheer_squad_show_ok(grp);
		DEBUG_LOG("CheerSquadShow Ended\t[grpid=%u]", grp->id);
		end_game(grp, p, 0);
		return 0;
	}
		
	if (grp->game->id == 57 && grp->count == p->group->game->players) {
		CheerSquadShow::rsp_cheer_squad_show_ok(grp);
		DEBUG_LOG("CheerSquadShow Ended\t[grpid=%u]", grp->id);
		end_game(grp, p, 0);
		return 0;
	}
	
	if (grp->game->id == 45)
		CheerSquadShow::update_players_info(grp, p, 0);
	if (grp->game->id == 58 || grp->game->id == 65)
		CheerSquadShow::update_fishers_info(grp, p, 0);
	if (grp->game->id == 66)
		CheerSquadShow::update_barbers_info(grp, p, 0);
	return 0;	
}
Example #2
0
int			launch_game(char **_tab, int r, t_cursor *cursor)
{
  struct termios	t;
  char			buff[1024];
  int			played;

  played = 0;
  cursor_init(cursor);
  aff_tab(_tab, cursor);
  while (42)
    {
      if (played == 1)
        {
          end_game(_tab, cursor, "IA");
          ia_turn(_tab, r);
          aff_tab(_tab, cursor);
          end_game(_tab, cursor, "Player");
        }
      init_read(&t);
      read(0, buff, 1024);
      played = move_cursor(cursor, r, buff, _tab);
      aff_tab(_tab, cursor);
    }
  return (0);
}
Example #3
0
void win(char board[6][7], char player){
	int i, j;
	for(i=0; i<6; i++){
		for(j=0; j<7; j++){
			if(board[i][j]==player){
				/*printf("%c", board[i][j]);*/
				if(i<3){
					if(board[i+1][j]==player){
						if(board[i+2][j]==player){
							if(board[i+3][j]==player){
								/*printf("buh");*/
								printf("%c as won!", player);
								end_game();
							}
						}
					}
				}
				if(j<4){
					if(board[i][j+1]==player){
						/*printf("%c", board[i][j+1]);*/
						if(board[i][j+2]==player){
							/*printf("%c", board[i][j+2]);*/
							if(board[i][j+3]==player){
								/*printf("%c", board[i][j+3]);
								printf("sneh");*/
								printf("%c as won!", player);
								end_game();
							}
						}
					}
				}
				if(i<3 && j<4){
					if(board[i+1][j+1]==player){
						if(board[i+2][j+2]==player){
							if(board[i+3][j+3]==player){
								/*printf("gub");*/
								printf("%c as won!", player);
								end_game();
							}
						}
					}
				}
				if(i>2 && j<4){
					if(board[i-1][j+1]==player){
						if(board[i-2][j+2]==player){
							if(board[i-3][j+3]==player){
								/*printf("lup");*/
								printf("%c as won!", player);
								end_game();
							}
						}
					}
				}
			}
		}
	}
}
Example #4
0
void Level::update()
{
	if(loading)
	{
		loading--;
		return;
	}
	float cx, cy, cz;
	Camera::getCamera()->getPos(&cx, &cy, &cz);
	float ay;
	Camera::getCamera()->getLookAngle(&ay, NULL);
	float vw, vh;
	Camera::getCamera()->getViewport(&vw, &vh);
	if(_is_shooting)
	{
		Camera::getCamera()->translate(0.0f, 0.0f,PLAYER_STEP*SHOT_VELOCITY);
		Camera::getCamera()->getPos(&cx, &cy, &cz);
	}else{
		gun->setPos(cx, cy, cz);
	}
	bullet->setPos(cx, cy-2, cz+2);
	glutWarpPointer(vw/2, vh/2);//+vh/4);

	for(unsigned int i=0;i<targets.size();i++)
	{
		targets.at(i)->update();
	}
	//
	if(check_collision())
	{
		unsigned int i;
		for(i=0;i<targets.size();i++)
		{
			if(targets.at(i)->getLife()>0)
				break;
		}
		if(i==targets.size())
		{
			loading_message=std::string("YOU WIN!");
			end_game(1);
		}
	}
	//
	if(!Player::bullets && !_is_shooting)
	{
		int total = 0;
		for(unsigned int i=0;i<targets.size();i++)
		{
			total+=targets.at(i)->getLife();
		}
		if(total)
			end_game(2);
	}
}
Example #5
0
void ce_game::checkEscape(){
	//Exit game
	if (key[KEY_ESC] || exit_bool){
		end_game();
		end_timer = 0;
	}
	//Goto menu
	if (key[KEY_M]){
		end_game();
	}
}
Example #6
0
void MainWindow::buttonPushed(int it){
	if( !game->is_error(it) ){
		buttons[it]->setText("X");
		game->player_move(it);
		int x = game->check_win();
		if(x!=0) end_game(x);
		buttons[game->move()]->setText("O");
		x = game->check_win();
		if(x!=0) end_game(x);
	}
}
Example #7
0
int main( int argc, char ** argv ) {
	for ( int i = 0; i < 3; ++i ){
		computersThrow = computerThrow();
		printf( "Your Score: %d\n", yourScore );
		puts( "1. Rock" );
		puts( "2. Paper" );
		puts( "3. Scissors" );
		printf( "%d: What do you want to throw? ", i );
		fflush(stdout);
		fgets( response, max_length, stdin );
		val = atoi( response );
		if( val == 1 ){
			rock();
		} else if( val == 2 ){
			paper();
		} else if( val == 3){
			scissors();
		} else {
			puts( "Enter valid choice 1, 2 or 3" );
			i -= 1;
		}
	}


	end_game();
	return 0;
}
Example #8
0
/** This methods handles the basic agent functionality: bookeeping
  *  the number of episodes, frames, etc... It calls the method 
  *  act(), which will provide it with an action. act() which should 
  *  be overriden by subclasses.
  */
Action PlayerAgent::agent_step() {
  // Terminate if we have a maximum number of frames
  if (i_max_num_frames > 0 && frame_number >= i_max_num_frames)
    end_game();

  // Terminate this episode if we have reached the max. number of frames 
  if (i_max_num_frames_per_episode > 0 && 
      episode_frame_number >= i_max_num_frames_per_episode) {
    return RESET;
  }

  // Only take an action if manual control is disabled
  Action a;
  if (manual_control) {
      a = waitForKeypress();
  } else {
      a = act();
  }

  if (record_trajectory) record_action(a);

  frame_number++;
  episode_frame_number++;
  
  return a;
}
Example #9
0
/* *********************************************************************
	This method is called when the game ends. The superclass 
	implementation takes care of counting number of episodes, and 
	saving the reward history. Here we check to see if we need to 
	swtch to the next action, and also update the episode counter and
	v_act_epis_rewards
******************************************************************** */
void ActionSummaryAgent::on_end_of_game(void) {
	v_act_epis_rewards.push_back(f_episode_reward);
	i_act_episode_counter++;
	if (i_act_episode_counter > i_max_episode_per_act) {
		// Save the average reward for this action
		float average_reward = get_vector_average(	&v_act_epis_rewards, 0, 
													v_act_epis_rewards.size());
		int ind;
		if (i_curr_action_index == -1) {
			ind = RANDOM;
		} else {
			ind = (*pv_possible_actions)[i_curr_action_index];
		}
		v_results_sum[ind] = average_reward;
		// Export the rewards 
		string filename = "reward_per_episode__act_" + str_current_action + ".txt";
		export_vector(&v_act_epis_rewards, filename);
		// switch to the next action
		i_curr_action_index++;
 		if (i_curr_action_index == i_num_actions) {
			// we are done
			save_results_summary();
			end_game();
		}
		str_current_action = action_to_string(
								(*pv_possible_actions)[i_curr_action_index]);
		cout << " ** Switching to action:" << str_current_action << " **" << endl;
		i_act_episode_counter = 0;
		v_act_epis_rewards.clear();
	}
	PlayerAgent::on_end_of_game();
}
Example #10
0
void CLI::apply_option(int option) {
    switch (option) {
        case HUMAN_VS_CPU:
        case CPU_VS_HUMAN:
        case HUMAN_VS_HUMAN:
        case CPU_VS_CPU:
            init_game(option);
            start_game();
            end_game();
            break;
        case LOAD:
            read_load();
            break;
        case SHOW_HELP:
            print_help();
            break;
        case BENCHMARK:
            run_benchmark();
            break;
        case WAC:
            run_wac_test();
            break;
        case SETTINGS:
            read_settings();
            break;
        case QUIT:
            cout << "Thanks for playing...!! Have fun..\n";
            break;
    }
}
/****************************************************************************
  Callback function that's invoked when GGZ is exited.
****************************************************************************/
static void
ggz_closed (void)
{
  gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), MAIN_PAGE);
  ggz_network_mode = FALSE;
  end_game (TRUE);
}
Example #12
0
void end( void )
{
    end_game();
    end_gui();

    exit(0);
}
Example #13
0
int Gamelan_Window::handle( int event )
{
	//propogate the event if we don't care about it (because it isn't a mouse
	//release event or because the game isn't running
	if( event != FL_RELEASE || !game )
		return Window::handle( event );

	int x = Fl::event_x();
	int y = Fl::event_y();
	//if the event could not have hit a note then throw it away
	if( y < 720 || y > 780 || x < 65 || x > 484 )
		return Window::handle( event );

	//calculate what string it hit by
	int str = (x - 65) / 60;
	//normalize the point so 0,0 is the center of the string
	bool hit = strings[ str ]->handle_mouse( x - 95 - 60*str, y - 750 );
	if( hit )
	{
		increment_all();
		index++;
		//is there another note to add?
		if( index < song.size() )
			strings[ song[index] ]->add_note();
		//was this the last note? ie is the game over?
		if( index == song.size() + NUM_DIVISIONS - 1 )
			end_game();
		Fl::redraw();
	}

	//let the event bubble down
	return Window::handle( event );
}
Example #14
0
File: board.c Project: verq/runners
int main(int argc, char **argv) {
	chosen_runner = 3;
	init_runners();
	set_runners_on_start_position();
	
	view_mode = BEHING_RUNNERS_HEAD;
	game_mode = STOP;
	
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(800, 600);
	glutCreateWindow(argv[0]);
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(keyboard_special);

	end_game();
	running();

	glutMainLoop();
	
	free_runners();
 	return 0;
}
Example #15
0
    void Offline_Survival::update(unsigned int ticks)
    {
        if (end_game()) return;

        while (need_add())
            add_enemy();

        clean();

        al.mov(ticks);

        if (player&&need_rev())
        {
            //Revive the player only if it has any lifes left
            if (--now_lif)
                player->revive_at(arrow::Vct(0,0));

            sf::Text new_text;
            new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::YOU_DIED));
            new_text.setColor(teams.get_enemy());
            texts.push_back(new_text);
        }

        for (auto it=ais.begin();it!=ais.end();++it)
        {
            it->think();
            it->play();
            it->mov(ticks);
        }
    }
Example #16
0
int			main(UNUSED int ac, char **av, char **env)
{
  t_config		config;
  t_tetrimino		*tetri;
  char			key[10];
  int			c;
  struct winsize	win;

  tetri = NULL;
  if ((tetri = init_main(av, env, &config, tetri)) == NULL)
    return (-1);
  c = 0;
  key[0] = 0;
  while (compare_key(key, config.quit) == 0)
    {
      ioctl(0, TIOCGWINSZ, &win);
      get_entry(key);
      if (key[0] != 0)
	key_control(key, &config, tetri);
      if (++c >= 100 && config.brek == 0 && (c = -1) == -1)
	if (game_physics(&config, tetri))
	  end_game(&config, key);
      usleep(get_speed(config.speed, config.level));
    }
  endwin();
  return (0);
}
Example #17
0
void game::on_event(const SDL_Event& event) {
  if (event.type == SDL_MOUSEBUTTONDOWN &&
      event.button.button == SDL_BUTTON_LEFT) {
    if (in_board()) {
      if (m_active_special) {
        const int digit = m_board.get_digit(m_selx, m_sely);

        // Attempt a special move
        if (m_active_special->m_type == special_move::nuke && digit == -1) {
          clear_3x3(m_selx, m_sely);
          m_active_special->m_type = special_move::none;
        }

        if (m_active_special->m_type == special_move::clear_digit &&
            digit != -1) {
          for (int y = 0; y != 9; ++y)
            for (int x = 0; x != 9; ++x)
              if (m_board.get_digit(x, y) == digit) m_board.set_digit(x, y, -1);

          m_active_special->m_type = special_move::none;
        }

        m_active_special = 0;
      } else {
        do_digit();
      }

      if (m_queue.digits_left() == 0 || m_board.get_filled() == 0) end_game();
    }

    for (int i = 0; i != 3; ++i)
      if (m_specials[i].m_button.click(event.button) &&
          m_specials[i].m_type != special_move::none)
        do_special(m_specials[i]);

    if (m_quit.click(event.button)) m_sm.set_next_state("title");
  }

  if (event.type == SDL_MOUSEMOTION) {
    // Check if the cursor is inside the board
    int mx = event.motion.x;
    int my = event.motion.y;

    if (mx >= board_xpos && mx < (board_xpos + 32 * 9) && my >= board_ypos &&
        my < (board_ypos + 32 * 9)) {
      m_selx = (mx - board_xpos) / 32;
      m_sely = (my - board_ypos) / 32;
    } else {
      m_selx = -1;
      m_sely = -1;
    }

    m_quit.motion(event.motion);

    for (int i = 0; i != 3; ++i)
      if (m_specials[i].m_type != special_move::none)
        m_specials[i].m_button.motion(event.motion);
  }
}
Example #18
0
void processa_buffer(Buffer* buffer){
	processa_wave(buffer->invasores);
	processa_nave(buffer->ovni);
	move_nave(buffer->ovni);
	processa_tanque(buffer->tanque);
	processa_colisao(buffer);

	//Caso vitorioso:
	if (get_linhas_wave(buffer->invasores) == 0)
		end_game(buffer);

	//Derrota:
	if(get_bottom_wave(buffer->invasores) >= get_top_tanque(buffer->tanque) || *buffer->vidas < 0){
		*buffer->vidas = -1;
		end_game(buffer);
	}
}
Example #19
0
/* Ends the game and shows the title */
void cb_end_game(GtkWidget *widget, gpointer data) {
	GuiInfo *gui;
	gui = (GuiInfo *) data;

	if(gui->game->state != STATE_STOPPED) {
		end_game(gui->game, ENDGAME_MENU);
	}
}
Example #20
0
File: main.c Project: Touzen/snake
int main() {
    init();

    while(tick())
        ;

    end_game();
    return 0;
}
Example #21
0
void MainMenu::loop()
{
    while (!end_menu() &	 !end_game() )
    {
        Keyboard::GetInstance()->update_events();
        update();
        update_graphics();
    }
}
int abandon( string str ) {
  if (this_player() == player1 || this_player() == player2) {
    write("You call off the game of darts.\n");
    say("The game of darts is called off by "
      + this_player()->query_short()+".\n");
    end_game();
    return 1;
  }
} /* abandon() */
Example #23
0
int main(void)
{
	setup_game();
	
	play_game();
	
	end_game();
	
	return 0;
}
Example #24
0
void		ending_intell(t_var *var, int total)
{
  if (total == 1 || total == 0)
    {
      tputs(tgetstr("cl", NULL), 1, my_putchar);
      tputs(tgetstr("md", NULL), 1, my_putchar);
      my_putstr("There is only one matche on the plate\n");
      my_putstr("You loose, too bad !\n");
      tputs(tgetstr("me", NULL), 1, my_putchar);
      end_game(var);
    }
}
Example #25
0
    void Multi_DM::update(unsigned int ticks)
    {
        if (delay1)
        {
            if (ticks>delay1)
                delay1=0;
            else
            delay1-=ticks;
        }
        if (delay2)
        {
            if (ticks>delay2)
                delay2=0;
            else
                delay2-=ticks;
        }

        if (end_game())
        {
            if (!ended)
            {
                ended=true;
                if (get_winner().friendly(player->team()))
                {
                    sf::Text new_text;
                    new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::WON));
                    new_text.setColor(teams.get_friendly());
                    texts.push_back(new_text);

                    sf::Text new_text2;
                    new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE));
                    new_text2.setColor(teams.get_enemy());
                    texts2.push_back(new_text2);
                }
                else
                {
                    sf::Text new_text;
                    new_text.setString(fdx::menu::Language::getText(fdx::menu::Language::LOSE));
                    new_text.setColor(teams.get_enemy());
                    texts.push_back(new_text);

                    sf::Text new_text2;
                    new_text2.setString(fdx::menu::Language::getText(fdx::menu::Language::WON));
                    new_text2.setColor(teams.get_friendly());
                    texts2.push_back(new_text2);
                }
            }
        }

        al.mov(ticks);

        rev_ships();
    }
static int checkValues(){
	if(device_click[0] && device_click[1]){
		if(click_val[0]==click_val[1]){
			length = sprintf(game_buffer, "\n* Tie! Both players chose %s\n\n", returnValueName(click_val[0]));
			sendMessage_rpsgame("rpsgame", game_buffer, length);
			resetTurn();
		}
		else{
			int winner = 42;
			int loser = 42;
			if(click_val[0]==1 && click_val[1]==2){
				winner=0;
			}
			else if(click_val[0]==2 && click_val[1]==4){
				winner=0;
			}
			else if(click_val[0]==4 && click_val[1]==1){
				winner=0;
			}
			else{
				winner=1;
			}

			score[winner]++;

			if(winner){
				loser=0;
			}
			else{
				loser=1;
			}

			length = sprintf(game_buffer, "\n* %s wins matchup! %s beats %s\n\n\n", player_names[winner], returnValueName(click_val[winner]), returnValueName(click_val[loser]));
			sendMessage_rpsgame("rpsgame", game_buffer, length);
			sleep(1);

			if(score[winner] >= NUMTOWIN){
				end_game(winner, loser);
			}
			else{
				resetTurn();
			}

			
		}
		
		return 0;
	}
	else{
		return -1;
	}
}
Example #27
0
/* We need this here because gnome-breakout tends to output alot of nasty
 * warning messages if we quit without killing off alot of canvas objects */
void cb_exit_game(GtkWidget *widget, gpointer data) {
	GuiInfo *gui;

        gui = (GuiInfo *) data;
	if(gui->game->state != STATE_STOPPED) {
		end_game(gui->game, ENDGAME_MENU);
	}

        gtk_object_destroy(GTK_OBJECT(gui->background));
        gtk_object_destroy(GTK_OBJECT(gui->title_image));

        gtk_main_quit();
}
Example #28
0
void ce_game::checkState(){
	//Check if the player and swans collide
	ce_rect playerFrame = col_collisionFrame(player->frame,player->bounds);
	
	//Loop through each swan
	for (int i=0; i<swans.size(); i++){

		//Get swan collision frames
		ce_swan *swan = swans[i];
		ce_rect swanFrame = col_collisionFrame(swan->frame,swan->bounds);

		//Check for collision
		if (col_rectIntersects(swanFrame,playerFrame) && !invincible){
			end_game();
		}
	}

	//Check if player has fallen through map
	if (player->frame.cord.y > (grid_h * level->layout.size())){
		end_game();
	}
}
static void
start_level_cb (GtkWidget * widget, gpointer data)
{
  gint level;

  if (!pref_dialog)
    return;

  end_game (1);

  level = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (data));
  gnibbles_properties_set_start_level (level);
}
Example #30
0
void collision_check(void *spart) {
    snake_part *me = (snake_part *)spart;
    NODE *node = snake.firstNode;
    for ( ; node; node = node->next ) {
        snake_part *comp = (snake_part *)node->data;
        if (comp == me) {
            continue;
        }
        if (comp->x == me->x && comp->y == me->y) {
            end_game();
        }
    }
}