void Engine::Close()
	{
		try {
			game_end();
		}
		catch (...) { }
	}
Esempio n. 2
0
void Statue::update()
{
	// timeout
	Game::update();

	if (!finished)
	{
		if (keysDown() & KEY_TOUCH)
		{
			touchPosition touch;
			touchRead(&touch);

			SpriteEntry* statue = oamMain.oamMemory + STATUE_SPRITE;

			if (	touch.px > statue->x && touch.px < statue->x + 64 &&
				touch.py > statue->y && touch.py < statue->y + 64)
			{
				++counter;

				// play hit sfx with random pitch
				sfxhandle_statue_hit = mmEffect( SFX_STATUE_HIT );
				mmEffectRate( sfxhandle_statue_hit, 1024 + (rand() % 256 - 128) );

				if (counter >= 3)
				{
					mmEffect( SFX_STATUE_BREAK );
					game_end(true);
				}
			}
		}
	}
}
Esempio n. 3
0
static int		brain_run_x_loop(t_brain *brain)
{
  static int	counter = 0;
  int		winner_no;
  t_bool	stopped;

  stopped = false;
  while (!stopped && game_is_ended(brain->game) == false)
    {
      if (cpu_execution(brain->cpu, brain->game, brain->ram) == RET_FAILURE)
	return (RET_ERROR);
      if (game_do_cycle(brain->game, brain->cpu) == RET_FAILURE)
	return (RET_ERROR);
      has_to_stop(&stopped);
      counter++;
      if (counter >= REFRESH)
	{
	  graphic_handler_update(NULL);
	  counter = 0;
	}
    }
  winner_no = game_end(brain->game);
  while (!stopped && pause_x());
  return (winner_no > RET_ERROR ?
	  brain->game->players_id[winner_no] : 0);
}
Esempio n. 4
0
File: app.c Progetto: rzel/dim3
void app_end(void)
{
	if (server.map_open) map_end();
	if (server.game_open) game_end();
	
		// shut down app
		
	console_add_system("Closing App");
	
		// shutdown view
		
	if (!app.dedicated_host) view_shutdown();
	
		// physics ray tracing
		
	ray_trace_shutdown();

		// shutdown server
		
	server_shutdown();
	
		// OS network shutdown
		
	net_shutdown();
}
Esempio n. 5
0
void game_main() {
    game_start();
    while(game_not_lost) {
        //Write data to SRAM to be used in OLED later

    }
    game_end();
}
Esempio n. 6
0
void game_main(void) {
    game_introMessage();
    while(!joy_read_right_button()) {
        _delay_us(10);
    }
    game_start();
    while(!game_lost) {
        _delay_us(10);
    }
    oled_printf("Game lost!");
    game_end();
}
Esempio n. 7
0
int		brain_run(t_brain *brain)
{
  if (brain == NULL)
    return (RET_FAILURE);
  if ((brain_put_programs(brain)) == RET_FAILURE)
    return (RET_FAILURE);
  while (game_is_ended(brain->game) == false)
    {
      if (cpu_execution(brain->cpu, brain->game, brain->ram) == RET_FAILURE)
	return (RET_FAILURE);
      if (game_do_cycle(brain->game, brain->cpu) == RET_FAILURE)
	return (RET_FAILURE);
    }
  game_end(brain->game);
  return (RET_SUCCESS);
}
Esempio n. 8
0
File: app.c Progetto: rzel/dim3
bool app_run_editor_launch(char *err_str)
{
		// launch directly into map
		
	server.state=gs_running;
	net_setup.mode=net_mode_none;
		
	if (!game_start(FALSE,skill_medium,0,0,err_str)) return(FALSE);
	
	if (!map_start(FALSE,TRUE,err_str)) {
		game_end();
		return(FALSE);
	}
	
	return(TRUE);
}
Esempio n. 9
0
/* Ends the player turn */
TEG_STATUS turno_end( PSPLAYER pJ )
{
	assert(pJ);

	/* FIXME: Creo que igual este chequeo no sirve, porque se chequea cuando
	 * se conquista un country. Solo sirve si uno gana sin conquistar algun country
	 * Puede pasar ???
	 */
	if( mission_chequear( pJ ) == TEG_STATUS_GAMEOVER ) {
		game_end( pJ );
		return TEG_STATUS_GAMEOVER;
	}

	player_clear_turn( pJ );
	return TEG_STATUS_SUCCESS;
}
Esempio n. 10
0
void Aim::update()
{
	// timeout
	Game::update();

	if (!finished)
	{
		if (keysDown() & KEY_TOUCH)
		{
			touchPosition touch;
			touchRead(&touch);

			SpriteEntry* capitalist = oamMain.oamMemory + SOVIET_SPRITE + capitalist_sprite;

			if (	touch.px > capitalist->x && touch.px < capitalist->x + 64 &&
				touch.py > capitalist->y && touch.py < capitalist->y + 64)
			{
				mmEffect( SFX_YEEHAW );
				game_end(true);
				capitalist->gfxIndex = SOVIET_TILE + anim[capitalist_sprite]*SOVIET_TILE_COUNT;
				capitalist->palette = 1;
				capitalist_sprite = -1;
			}
		}
	}

	for (int i = 0; i <= NUM_SOVIET; ++i)
	{
		++frame[i];
		if (frame[i] == 8)
		{
			frame[i] = 0;
			anim[i] = (anim[i] + 1) % 2;

			if (i == capitalist_sprite)
			{
				(oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = CAPITALIST_TILE + anim[i]*CAPITALIST_TILE_COUNT;
			}
			else
			{
				(oamMain.oamMemory + SOVIET_SPRITE + i)->gfxIndex = SOVIET_TILE + anim[i]*SOVIET_TILE_COUNT;
			}
		}
	}
}
Esempio n. 11
0
int		brain_run(t_brain *brain)
{
  int		no;

  if (brain == NULL)
    return (RET_FAILURE);
  if ((brain_put_programs(brain)) == RET_ERROR)
    return (RET_FAILURE);
  while (game_is_ended(brain->game) == false)
    {
      if (cpu_execution(brain->cpu, brain->game, brain->ram) == RET_FAILURE)
	return (RET_ERROR);
      if (game_do_cycle(brain->game, brain->cpu) == RET_FAILURE)
	return (RET_ERROR);
    }
  no = game_end(brain->game);
  return (no < 0 ? no : brain->game->players_id[no]);
}
Esempio n. 12
0
void cartographer_update()
{

  /*-----------------------------------------------------------------------------
   *  Warning, may slow down game loop if there are alot of objects here
   *-----------------------------------------------------------------------------*/
  jnx_node *head = object_list->head;
  jnx_list *new_draw = jnx_list_create();
  while(head)
  {
    game_object *current = head->_data;
    if(current->health > 0)
    {
      //still an active object
      jnx_list_add(new_draw,current);
    }
    else
    {
      if(strcmp(current->object_type,"player")  == 0)
      {
        /*-----------------------------------------------------------------------------
         *  If the player has been killed we'll call a clean up function to end the game
         *-----------------------------------------------------------------------------*/
        game_end();	
      }
      JNX_LOG(NULL,"Object %s at %g %g has been removed as health was %d\n", current->object_type,current->position.x, current->position.y, current->health);
      //remove the object
      play_sound(sound_lexplosion);

      /*-----------------------------------------------------------------------------
       *  Add our soon to be lost object to the score board
       *-----------------------------------------------------------------------------*/
      printf("adding object for destruction %s with health %d\n",current->object_type,current->health);
      //Possible bug here if the player starts in reach of enemy ships and they start blowing up before game time	
      score_add_destroyed_obj(current);
      sfSprite_destroy(current->sprite);
      free(current);
    }
    head = head->next_node;
  }
  object_list = new_draw;
}
Esempio n. 13
0
enum movement cursor_direction(int key) {
  switch (key) {
  case 'h':
  case KEY_LEFT:
    return(LEFT);
  case 'j':
  case KEY_DOWN:
    return(DOWN);
  case 'k':
  case KEY_UP:
    return(UP);
  case 'l':
  case KEY_RIGHT:
    return(RIGHT);
  default:
    endwin();
    game_end();
    assert(false && "invalid cursor direction");
  }
}
Esempio n. 14
0
void world_post_animation_action(t_spritePtr spr, t_id fromid, t_id toid) {
//    printf("post action... f %d t %d \n",fromid,toid);
    if (spr->is_player) {
        if (fromid==STID_PLAYER_HIT) {
         //   spr->vx=c_v_fast;
        }
        if (fromid==STID_PLAYER_PREPARINGHIT) {
         //   spr->vx=0;
        }        
        if (fromid==STID_PLAYER_PREPARINGJUMP) {
            spr->vx*=world_jump_vx_fraction;
            spr->vy=world_jump_vy;
            world_lose_life(c_life_loss_per_jump);
        }
        if (fromid==STID_PLAYER_FALLEN) {
            spr->vx=c_v_slow;
            world.player_untouchable_time=world.t+invulnerability_time;
            achievments_fallen();
        }
        if (fromid==STID_PLAYER_SIDE) {
            spr->vx=c_v_slow;
        }
        if (fromid==STID_PLAYER_TIRED) {
            game_end();
        }
    } else {
        if (fromid==STID_WALKER_RECEIVED_HIT) {
            spr->vx=c_v_slow;
            spr->n_hits=2;
        }
        if (fromid==STID_WALKER_RECEIVING_HIT) {
            spr->vx=c_v_slow;
            spr->n_hits=2;
        }
    }
    
}
Esempio n. 15
0
int main(int argc, char **argv)
{
	int i, cc;
	char msg[MSG_BFR_SZ];
	char tag[MSG_BFR_SZ];

	struct player_data *p = NULL;

	--argc; ++argv;
	setbuf(stdout, NULL);
	setbuf(stdin , NULL);
	
	struct timeval tv;
	gettimeofday(&tv, NULL);
	if (!client_setup(&argc, &argv))
		return EXIT_FAILURE;

	recv(msg); sscanf(msg, "%*s %d", &SELF.id);
	sprintf(msg, "NAME %s", BOT_NAME); send(msg);
	
	srand(tv.tv_usec+SELF.id);
	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "READY")) break;
		else if (!strcmp(tag, "BOARD"))
			sscanf(msg, "%*s %u", &BOARDSIZE);
		else if (!strcmp(tag, "PLAYERS"))
		{
			sscanf(msg, "%*s %u", &NUMPLAYERS);
			for (i = 0, p = players; i < NUMPLAYERS; ++i, ++p)
			{
				p->id = i;
				p->lastscore = p->score = 0;
			}
		}
		else if (!strcmp(tag, "ROUNDS"))
			sscanf(msg, "%*s %u", &NUMROUNDS);
	}

	copyself(); game_setup(players);

	unsigned int rnum;
	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "ENDGAME")) break;
		else if (!strcmp(tag, "ROUND"))
		{
			unsigned int rnum;
			sscanf(msg, "%*s %u", &rnum);
			
			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				
				if (!strcmp(tag, "GO")) break;
				else EXPECTED(tag, "GO");
			}

			copyself();
			player_turn(rnum, players);

			clamp(&SELF.cow.x, 0, BOARDSIZE);
			clamp(&SELF.cow.y, 0, BOARDSIZE);

			clamp(&SELF.fence1.x, 0, BOARDSIZE);
			clamp(&SELF.fence2.x, SELF.fence1.x, BOARDSIZE);

			clamp(&SELF.fence1.y, 0, BOARDSIZE);
			clamp(&SELF.fence2.y, SELF.fence1.y, BOARDSIZE);

			sprintf(msg, "MOVE %u %u %u %u %u %u"
			,	SELF.cow.x, SELF.cow.y
			,	SELF.fence1.x, SELF.fence1.y
			,	SELF.fence2.x, SELF.fence2.y
			);
			send(msg);
			
			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				
				if (!strcmp(tag, "NEXT")) break;
				else if (!strcmp(tag, "PLAYER"))
				{
					sscanf(msg, "%*s %d", &i);
					p = &players[i];

					sscanf(msg, "%*s %*d %u %u %u %u %u %u %u %u"
					,	&p->cow.x, &p->cow.y
					,	&p->fence1.x, &p->fence1.y
					,	&p->fence2.x, &p->fence2.y
					,	&p->lastscore, &p->score
					);
				}
			}
		}
		
		// got an unexpected message...
		else EXPECTED(tag, "ROUND/ENDGAME/MOVE/UPDATE");
	}

	quit: game_end();
	return EXIT_SUCCESS;
}
Esempio n. 16
0
File: files.c Progetto: rzel/dim3
void file_click(void)
{
	int			id,k;
	char		err_str[256],file_name[256];

	id=-1;

		// keyboard

	if (input_get_keyboard_escape()) id=file_button_cancel_id;
	if (input_get_keyboard_return()) id=file_is_save?file_button_save_id:file_button_load_id;

		// clicking

	if (id==-1) {
		id=gui_click();
		if (id!=-1) hud_click();
	}
		
	if (id==-1) return;

		// handle click
		
	switch (id) {
	
		case file_button_save_id:
			if (!game_file_save(FALSE,FALSE,err_str)) console_add_error(err_str);
			server.next_state=gs_running;
			break;
			
		case file_button_load_id:

			k=element_get_value(file_info_table_id);
			if (k==-1) break;
			
			element_get_table_column_data(file_info_table_id,k,1,file_name,256);

			server.next_state=gs_running;

			if (game_file_load(file_name,FALSE,err_str)) {
				game_time_pause_end();
				break;
			}

			if (server.map_open) map_end();
			if (server.game_open) game_end();

			error_setup(err_str,"Game Load Canceled");
			server.next_state=gs_error;
			break;
			
		case file_button_delete_id:
			file_save_delete();
			break;
			
		case file_button_cancel_id:
			server.next_state=file_last_state;
			break;
			
		case file_info_table_id:
			file_save_selected();
			break;
			
	}
}
void action_end_game() { game_end(); }
Esempio n. 18
0
 void Engine::Shutdown()
 {
     game_end();
 }
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	MSG msg;
	srand((unsigned int)time(NULL));
	g_hInstance = hInstance;
	g_nCmdShow = nCmdShow;
	DWORD dwStyle, dwExStyle;
	RECT windowRect;

	/**
	 * Create engine object first!
	**/
	g_engine = new Advanced2D::Engine();
	
	//let main program have a crack at things before window is created
	if (!game_preload()) {
		MessageBox(g_hWnd, "Error in game preload!", "Error", MB_OK);
		return 0; 
	}
	
	//get window caption string from engine
	char title[255];
	sprintf(title, "%s", g_engine->getAppTitle().c_str());

	//set window dimensions
	windowRect.left = (long)0;
	windowRect.right = (long)g_engine->getScreenWidth();
	windowRect.top = (long)0;
	windowRect.bottom = (long)g_engine->getScreenHeight();


   //create the window class structure
	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX); 

	//fill the struct with info
	wc.style		 = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)WinProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hIcon		 = NULL;
	wc.hCursor	   = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = title;
	wc.hIconSm	   = NULL;

	//set up the window with the class info
	RegisterClassEx(&wc);

	//set up the screen in windowed or fullscreen mode?

	if (g_engine->getFullscreen()) 
	{
	   DEVMODE dm;
	   memset(&dm, 0, sizeof(dm));
	   dm.dmSize = sizeof(dm);
	   dm.dmPelsWidth = g_engine->getScreenWidth();
	   dm.dmPelsHeight = g_engine->getScreenHeight();
	   dm.dmBitsPerPel = g_engine->getColorDepth();
	   dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

	   if (ChangeDisplaySettings(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
		  MessageBox(NULL, "Display mode failed", NULL, MB_OK);
		  g_engine->setFullscreen(false);
	   }

		dwStyle = WS_POPUP;
		dwExStyle = WS_EX_APPWINDOW;
		ShowCursor(FALSE);
	}
	else {
		dwStyle = WS_OVERLAPPEDWINDOW;
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
	}

	//adjust window to true requested size
	AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);

	//create the program window
	g_hWnd = CreateWindowEx( 0,
	   title,								 //window class
	   title,								 //title bar
	   dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,	  
	   0, 0,											 //x,y coordinate
	   windowRect.right - windowRect.left,			   //width of the window
	   windowRect.bottom - windowRect.top,			   //height of the window
	   0,											 //parent window
	   0,											 //menu
	   g_hInstance,									  //application instance
	   0);											//window parameters

	//was there an error creating the window?
	if (!g_hWnd) 	{
		MessageBox(g_hWnd, "Error creating program window!", "Error", MB_OK);
		return 0; 
	}

	//display the window
	ShowWindow(g_hWnd, g_nCmdShow);
	UpdateWindow(g_hWnd);

	//initialize the engine
	g_engine->setWindowHandle(g_hWnd);
	if (!g_engine->Init(g_engine->getScreenWidth(), g_engine->getScreenHeight(), g_engine->getColorDepth(), g_engine->getFullscreen())) 	{
		MessageBox(g_hWnd, "Error initializing the engine", "Error", MB_OK);
		return 0;
	}

	// main message loop
	gameover = false;
	while (!gameover)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		g_engine->Update();
	}

   if (g_engine->getFullscreen()) {
	  ShowCursor(TRUE);
   }

	game_end();

	delete g_engine;

   return 1;
}
Esempio n. 20
0
/* single player game win/point screen 
 * 1. setup all player data
 * 2. setup second local player and ai players
 * 3. setup all other game related data
 */
void
single_playergame (int second_player, int ai_players)
{
    int p,
      done = 0;

	bman.p_nr = -1;
	bman.p2_nr = -1;
	
    /* delete player and teams from the game */
    for (p = 0; p < MAX_PLAYERS; p++) {
        players[p].points = 0;
        players[p].wins = 0;
        players[p].state = 0;
		players[p].team_nr = -1;
        players[p].gfx_nr = -1;
        players[p].gfx = NULL;
		memset (&players[p].net, 0x0, sizeof (_net_player));
    }

	for (p = 0; p < MAX_TEAMS; p++) {
		teams[p].wins = 0;
		teams[p].points = 0;
		
		for (done = 0; done < MAX_PLAYERS; done++)
			teams[p].players[done] = NULL;
	}
	
	done = 0;
    for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
        if (!(PS_IS_used (players[p].state)))
            bman.p_nr = p;
	players[bman.p_nr].team_nr = 0;

    if (bman.p_nr >= MAX_PLAYERS) {
        printf ("ERROR in function (single_game_new): couldn't find any free player\n");
        exit (1);
    }

	strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);
	do {
		done = playermenu_selgfx (bman.p_nr);
	} while (players[bman.p_nr].gfx_nr == -1 && done != -1);
		
    players[bman.p_nr].state = PSF_used + PSF_alife + PSF_playing;
    strncpy (players[bman.p_nr].name, bman.playername, LEN_PLAYERNAME);

	if (done != -1 && second_player) {
		player2_join ();
		do {
			done = playermenu_selgfx (bman.p2_nr);
		} while (players[bman.p2_nr].gfx_nr == -1 && done != -1);
		players[bman.p2_nr].team_nr = 0;
	}

	if (done == -1)
		return;
	
    single_create_ai (ai_players);
	
	if (bman.gametype == GT_team) {
		playermenu ();
		team_update ();
		ai_team_choosegfx ();
	}
	
    bman.state = GS_ready;

    while (!done && bman.state != GS_quit && bman.state != GS_startup) {
        single_game_new ();
        game_start ();
		bman.state = GS_running;
        game_loop ();
        game_end ();
    }
	
	gfx_blitdraw ();
	draw_logo ();
	gfx_blitdraw ();
};
Esempio n. 21
0
int main(int argc, char* argv[])
{
	struct deck thisDeck;
	struct player thisPlayer;
	struct game thisGame;
	int inputValidity;
	int menu;
	int game;
	int load = 0;
	
	//Not Working!!! card_init_deck(&thisDeck);
	
	//This is the exact same algorithm used in card.c and it works great here!!! Why!!!
	for (int k = 0; k < 4; k++)
	{
		for (int i = 0; i < 13; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				strcpy(thisDeck.oneCard[k*52+i*4+j].rank, ranks[i]);
				strcpy(thisDeck.oneCard[k*52+i*4+j].suit, suits[j]);
				thisDeck.oneCard[k*52+i*4+j].value = value[i];
			}
		}
	}
	
	card_shuffle(&thisDeck);
	thisPlayer.chip = 0;
	
	system("clear");
		
	while (1)
	{
		printf("\n\n**********BlackJack**********\n\n");
		printf(" 1. Play\n");
		printf(" 2. Load\n");
		printf(" 3. Player status\n");
		printf(" 4. Exit\n\n");
		printf("*****************************\n\n");
		while(1)
		{
			printf("Please enter menu number: ");
			inputValidity = scanf("%d", &menu);
			while(getchar()!='\n'){}
			if (inputValidity)
			{
				if (menu < 1 || menu > 4)
				{
					printf("Please select from menu!\n");
				}
				else
				{
					break;
				}
			}
			else
			{
				printf("Please enter a NUMBER!\n");
			}
		}
		
		if (menu == 4)
		{
			player_save(&thisPlayer);
			printf("Thanks for playing! Bye!\n");
			break;
		}
		else if (menu == 3)
		{
			if (thisPlayer.name == NULL)
			{
				printf("No player record.\n");
				continue;
			}
			player_status(&thisPlayer);
			continue;
		}
		else if (menu == 2)
		{
			player_load(&thisPlayer);
			continue;
		}
		else
		{
			if (thisPlayer.chip == 0)
			{
				player_name(&thisPlayer);
				player_chip(&thisPlayer);
			}
			printf("Welcome %s!\nHave fun!\n\n", thisPlayer.name);
			
			while(1)
			{
				//Deal initial cards
				game_init(&thisGame);
				if (thisDeck.cardNow > 180)
				{
					printf("\n\nShuffling...\n\n");
					card_shuffle(&thisDeck);
				}
				if (thisPlayer.chip <= 0)
				{
					printf("You are penniless!\n");
					thisPlayer.win = 0;
					thisPlayer.lose = 0;
					thisPlayer.push = 0;
					break;
				}
				game_bet(1, &thisPlayer, &thisGame);
				printf("\nDealer is dealing the cards...\n\n");
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				printf("Dealer shows %s of %s\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].rank, thisDeck.oneCard[thisGame.dealer_inhand[0]].suit);
				printf("Dealer\'s point is %d\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].value);
				printf("Your cards: ");
				game_print_card(2, &thisGame, &thisDeck);
				printf("\n");
				printf("Your point is %d\n", game_totalvalue(2, &thisGame, &thisDeck));
				
				//Check if dealer shows an Ace
				if (thisDeck.oneCard[thisGame.dealer_inhand[0]].value == 11)
				{
					game_bet(2, &thisPlayer, &thisGame);
					if (game_totalvalue(1, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) != 4)
					{
						if (thisGame.is_insured)
						{
							thisPlayer.chip += thisGame.bet;
						}
						thisPlayer.lose++;
						printf("Dealer\'s cards: ");
						game_print_card(1, &thisGame, &thisDeck);
						printf("\n");
						printf("Dealer\'s point is %d\n", game_totalvalue(1, &thisGame, &thisDeck));
						printf("Dealer is BlackJack!\n");
						if (game_end())
						{
							break;
						}
						else
						{
							continue;
						}
					}
					else if (game_totalvalue(2, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) == 4)
					{
						thisPlayer.chip += thisGame.bet;
						thisPlayer.push++;
						printf("Push!\n");
					}
				}
				
				game_play(&thisPlayer, &thisDeck, &thisGame);
				if (game_end())
				{
					break;
				}
				continue;
			}
			continue;
		}
	}
	
	return 0;
}
Esempio n. 22
0
int main(int argc, char **argv)
{
	int i, cc;
	char msg[MSG_BFR_SZ];
	char tag[MSG_BFR_SZ];

	struct player_data *p = NULL;

	--argc; ++argv;
	setbuf(stdout, NULL);
	setbuf(stdin , NULL);

	if (!client_setup(&argc, &argv))
		return EXIT_FAILURE;

	recv(msg); sscanf(msg, "%*s %d", &SELF.id);
	sprintf(msg, "NAME %s", BOT_NAME); send(msg);

	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "READY")) break;
		else if (!strcmp(tag, "PLAYERS"))
		{
			sscanf(msg, "%*s %u", &numplayers);
			for (i = 0, p = players; i < numplayers; ++i, ++p)
			{
				recv(msg); sscanf(msg, "%u %u", &p->id, &p->pool);
				p->wager = p->card = p->active = 0;
			}
		}
		else if (!strcmp(tag, "CARDS"))
			sscanf(msg, "%*s %u %u", &XRANGE, &XDUP);
		else if (!strcmp(tag, "ANTE"));
			sscanf(msg, "%*s %*d %u", &ROUNDS_TO_DBL);
	}

	if (!p) EXPECTED(tag, "PLAYERS");
	copyself(); game_setup(players, numplayers);

	while ((cc = recv(msg)))
	{
		sscanf(msg, "%s", tag);
		
		if (!strcmp(tag, "ENDGAME")) break;
		else if (!strcmp(tag, "ROUND"))
		{
			unsigned int rnum, pstart, rante;
			sscanf(msg, "%*s %u %u %u", &rnum, &pstart, &rante);
			copyself(); round_start(rnum, pstart, rante);

			while ((cc = recv(msg)))
			{
				sscanf(msg, "%s", tag);
				if (!strcmp(tag, "TURN"))
				{
					for (i = 0, p = players; i < numplayers; ++i, ++p)
					{
						recv(msg);
						sscanf(msg, "%u %u %u %u %u", &p->id, &p->card, &p->pool, 
							&p->wager, &p->active);
					}

					copyself(); recv(tag);
					if (strcmp(tag, "GO")) EXPECTED(tag, "GO");
					int k = player_turn(players, numplayers);

					// perform the chosen action
					switch (k)
					{
						case CALL: sprintf(msg, "CALL"); break;
						case FOLD: sprintf(msg, "FOLD"); break;
						default:   sprintf(msg, "WAGER %d", k); break;
					}
					send(msg);
				}
				else if (!strcmp(tag, "ENDROUND"))
				{
					int winnings; sscanf(msg, "%*s %u", &winnings);
					for (i = 0, p = players; i < numplayers; ++i, ++p)
					{
						recv(msg); p->wager = p->active = 0;
						sscanf(msg, "%u %u %u", &p->id, &p->card, &p->pool);
					}
					copyself(); round_end(players, numplayers, winnings);
					break;
				}
				// got an unexpected message...
				else EXPECTED(tag, "TURN/ENDROUND");
			}
		}
		// got an unexpected message...
		else EXPECTED(tag, "ROUND/ENDGAME");
	}

	game_end();
	return EXIT_SUCCESS;
}
Esempio n. 23
0
File: app.c Progetto: rzel/dim3
bool app_run_dedicated_host(char *err_str)
{
	char			str[256];

		// launch directly into hosting
		// setup hosting flags and IPs
		
	host_game_setup();
	net_host_game_setup();

	net_setup.mode=net_mode_host;
	net_setup.client.latency=0;
	net_setup.client.host_addr.ip=0;
	net_setup.client.host_addr.port=0;
	
	net_create_project_hash();

		// setup map
		
	map.info.name[0]=0x0;
	strcpy(map.info.host_name,setup.network.map_list.maps[net_setup.host.current_map_idx].name);
	
		// start game
	
	if (!game_start(FALSE,skill_medium,0,0,err_str)) {
		net_host_game_end();
		return(FALSE);
	}
	
		// add any multiplayer bots
		
	if (!game_multiplayer_bots_create(err_str)) {
		game_end();
		net_host_game_end();
		return(FALSE);
	}
	
		// start the map
		
	if (!map_start(FALSE,TRUE,err_str)) {
		game_end();
		net_host_game_end();
		return(FALSE);
	}

		// start hosting

	if (!net_host_game_start(err_str)) {
		map_end();
		game_end();
		net_host_game_end();
		return(FALSE);
	}

		// dedicated hosting, no local
		// player to add, only add
		// multiplayer bots to host

	net_host_join_multiplayer_bots();

		// game is running

	sprintf(str,"Running on %s...",net_setup.host.ip_resolve);
	console_add(str);
	
	server.next_state=gs_running;

	return(TRUE);
}
Esempio n. 24
0
int main(int argc, char *argv[]) {
  int option;
  int option_index;
  int passes_through_deck = 3;
  int use_utf8 = 0;
  static const struct option options[] = {
    {"help",    no_argument,       NULL, 'h'},
    {"version", no_argument,       NULL, 'v'},
    {"passes",  required_argument, NULL, 'p'},
    {"utf8",    no_argument,       NULL, 'u'}
  };

  program_name = argv[0];

  while ((option = getopt_long(argc, argv, "hvp:u", options, &option_index)) != -1) {
    switch (option) {
    case 'v':
      version();
      exit(0);
    case 'p':
      passes_through_deck = atoi(optarg);
      break;
    case 'u':
      use_utf8 = true;
      break;   
    case 'h':
    default:
      usage(program_name);
      exit(0);
    }
  }

  set_utf8_mode(use_utf8);
  setlocale(LC_ALL, "");
  initscr();
  raw();
  noecho();
  keypad(stdscr, TRUE);
  start_color();
  curs_set(FALSE);
  set_escdelay(0);
  assume_default_colors(COLOR_WHITE, COLOR_GREEN);
  init_pair(1, COLOR_BLACK, COLOR_WHITE);
  init_pair(2, COLOR_RED, COLOR_WHITE);
  init_pair(3, COLOR_WHITE, COLOR_BLUE);
  init_pair(4, COLOR_WHITE, COLOR_GREEN);

  int key;

  while (!term_size_ok()) {
    clear();
    mvprintw(1, 1, SMALL_TERM_MSG);
    refresh();
    if ((key = getch()) == 'q' || key == 'Q') {
      endwin();
      return(0);
    }
  }

  clear();
  draw_greeting();
  refresh();

  for (;;) {
    if ((key = getch()) == 'q' || key == 'Q') {
      endwin();
      return(0);
    }
    if (term_size_ok()) {
      clear();
      draw_greeting();
      refresh();
      if (key == KEY_SPACEBAR) {
        clear();
        refresh();
        game_init(&game, passes_through_deck);
        break;
      }
    } else if (key == KEY_RESIZE) {
      clear();
      mvprintw(1, 1, SMALL_TERM_MSG);
      refresh();
    }
  }

  do {
    keyboard_event(getch());
  } while (!game_won());

  endwin();
  game_end();
  printf("You won.\n");

  return(0);
}
Esempio n. 25
0
/* A player is attacking from src to dst */
STATIC TEG_STATUS token_attack( int fd, char *str )
{
	PARSER p;
	DELIM igualador={ ':', ':', ':' };
	DELIM separador={ ',', ',', ',' };
	int src,dst,src_lost,dst_lost;
	char d_src[3],d_dst[3];
	PSPLAYER pJ_src, pJ_dst;
	int conq = 0;
	int tropas = 0;
	char buffer[4096];

	PLAY_DEBUG("token_attack()\n");

	if( strlen(str)==0)
		goto error;

	if( !SPLAYER_ATAQUE_P(fd,&pJ_src)) {
		if( SPLAYER_TROPAS_P(fd,&pJ_src)) {
			pJ_src->estado=PLAYER_STATUS_ATAQUE;
			pJ_src->country_src = pJ_src->country_dst = -1;
		} else goto error;
	}

	p.igualador = &igualador;
	p.separador = &separador;
	p.data = str;

	if( parser_call( &p ) && p.hay_otro ) {
		src = atoi( p.token );		
	} else goto error;

	if( parser_call( &p ) && !p.hay_otro ) {
		dst = atoi( p.token );		
	} else goto error;

	if( src >= COUNTRIES_CANT || src < 0 || dst >= COUNTRIES_CANT || dst < 0) {
		goto error;
	}

	if( pJ_src->numjug != g_countries[src].numjug || pJ_src->numjug == g_countries[dst].numjug )  {
		goto error;
	}

	if( g_countries[src].ejercitos < 2 || !countries_eslimitrofe( src, dst) ) {
		goto error;
	}

	if( player_whois( g_countries[dst].numjug, &pJ_dst ) != TEG_STATUS_SUCCESS ){
		goto error;
	}

	if( pactos_attack( src, dst ) != TEG_STATUS_SUCCESS )
		goto error;

	/* aviso a todos que hay un attack */
	if( ! g_game.fog_of_war )
		netall_printf( "%s=%d,%d\n",TOKEN_ATAQUE,src,dst );
	else {
		fow_2_netall_printf( src, dst, "%s=%s,%s\n",TOKEN_ATAQUE,"%d","%d" );
	}

	/* so far, attack... */
	aux_token_attack( g_countries[src].ejercitos, g_countries[dst].ejercitos, &src_lost, &dst_lost, d_src, d_dst );

	g_countries[src].ejercitos -= src_lost;
	g_countries[dst].ejercitos -= dst_lost;
	pJ_src->tot_armies -= src_lost;
	pJ_dst->tot_armies -= dst_lost;

	/* updated statistics */
	pJ_src->player_stats.armies_killed += dst_lost;
	pJ_dst->player_stats.armies_killed += src_lost;
	pJ_dst->player_stats.armies_lost += dst_lost;
	pJ_src->player_stats.armies_lost += src_lost;

	/* conquisto el country | country was conquered */
	if( g_countries[dst].ejercitos == 0) {
		PLIST_ENTRY l;

		conq = 1;

		pJ_src->turno_conq++;
		pJ_src->tot_countries++;

		
		g_countries[dst].numjug = pJ_src->numjug;

		g_countries[dst].ejercitos++;		/* se pasa automaticamente */
		g_countries[src].ejercitos--;		/* un ejercito */

		tropas = g_countries[src].ejercitos - 1;	/* cantidad que se pueden pasar */
		if( tropas > 2 )			/* En verdad son 3, pero ya se le paso 1 */
			tropas =2;

		pJ_src->estado = PLAYER_STATUS_TROPAS;
		pJ_src->country_src = src;
		pJ_src->country_dst = dst;
	
		pJ_dst->tot_countries--;

		l= RemoveHeadList( g_countries[dst].next.Blink );
		InsertTailList( &pJ_src->countries, l);

		/* updated statistics */
		pJ_src->player_stats.countries_won ++;
		pJ_dst->player_stats.countries_lost ++;
	}

	/* update the scores */
	stats_score( &pJ_src->player_stats );
	stats_score( &pJ_dst->player_stats );

	/* tell everybody the result of the attack */

	memset( buffer, 0, sizeof(buffer) );

	if( ! g_game.fog_of_war ) {
		netall_printf( "%s=%d,%d,%d,%d,%d,%d,%d,%d\n", TOKEN_DADOS,
			src,d_src[0],d_src[1],d_src[2], dst,d_dst[0],d_dst[1],d_dst[2] );
	} else {
		fow_2_netall_printf( src, dst, "%s=%s,%d,%d,%d,%s,%d,%d,%d\n"
			, TOKEN_DADOS
			, "%d",d_src[0],d_src[1],d_src[2]
			, "%d",d_dst[0],d_dst[1],d_dst[2] );
	}

	if( ! g_game.fog_of_war ) {
		netall_printf( "%s=%d,%d,%d;%s=%d,%d,%d\n",
			TOKEN_COUNTRY, src, g_countries[src].numjug, g_countries[src].ejercitos,
			TOKEN_COUNTRY, dst, g_countries[dst].numjug, g_countries[dst].ejercitos
			);
	} else {
		fow_netall_printf( src, "%s=%d,%d,%d\n", TOKEN_COUNTRY,
				src, g_countries[src].numjug, g_countries[src].ejercitos );

		fow_netall_printf( dst, "%s=%d,%d,%d\n", TOKEN_COUNTRY,
				dst, g_countries[dst].numjug, g_countries[dst].ejercitos );
	}

	if( conq == 1 ) {

		/* Did 'dst' player lose the game ? */
		if( player_is_lost( pJ_dst ) ) {
			con_text_out(M_INF,_("Player %s(%d) lost the game\n"),pJ_dst->name,pJ_dst->numjug);
			netall_printf( "%s=%d\n",TOKEN_LOST, pJ_dst->numjug );
			player_poner_perdio(pJ_dst);
		}

		/* Did 'src' player win the game ? */
		if( mission_chequear( pJ_src ) == TEG_STATUS_GAMEOVER || game_is_finished() ) {
#ifdef WITH_GGZ
			ggz_server_gameover(pJ_src->fd);
#endif
			con_text_out(M_INF,_("Player %s(%d) is the winner! Game Over\n"),pJ_src->name,pJ_src->numjug);
			pJ_src->estado = PLAYER_STATUS_GAMEOVER;
			game_end( pJ_src );
			return TEG_STATUS_SUCCESS;
		}

		net_printf(fd,"%s=%d,%d,%d\n", TOKEN_TROPAS, src,dst,tropas);


		/* in FOW show the boundaries countries */
		if( g_game.fog_of_war ) {
			char buffer[2048];

			memset( buffer, 0, sizeof(buffer) );
			if( fow_fill_with_boundaries( dst, buffer, sizeof(buffer) ) == TEG_STATUS_SUCCESS )
				net_printf( fd, "%s\n", buffer );
		}
	}

	return TEG_STATUS_SUCCESS;
error:
	net_print(fd,TOKEN_ERROR"="TOKEN_ATAQUE"\n");
	return TEG_STATUS_PARSEERROR;
}
Esempio n. 26
0
static void game_tick(void *data)
{
    if (game->alive) {
        if (!game->is_resetting) {
             game_timer = app_timer_register(GAME_TICK_INTERVAL, game_tick, NULL);
        }
    } else {
        game_end(1);
    }

    // If game is paused, has the user presed the resume button?
    if (game->is_paused && game->queued_input != 3) {
        return;
    }

    // Check User Input
    if (game->queued_input) {
        switch (game->queued_input) {
            case 1:
                // Up pressed, TURN COUNTERCLOCKWISE
                if (snake->direction > 0) {
                    snake->direction -= 1;
                } else {
                    snake->direction = 3;
                }
                break;
            case 2:
                // Down pressed, TURN CLOCKWISE
                if (snake->direction < 3) {
                    snake->direction  += 1;
                } else {
                    snake->direction = 0;
                }
                break;
            case 3:
                game->is_paused = !game->is_paused;
                break;
            default:
                break;
        }
        game->queued_input = 0; 
    }

    if (game->alive) {
        move_snake(snake);
    }

    // Check if snake ate apple
    if(snake_has_eaten_apple(snake, apple)) {
        add_to_head(snake);
        // Move apple
        move_apple();
        game->score += (1 + game->bonus_points);
        snake->length += 1;
        vibes_short_pulse();

        if (game->bonus_points == 0) {
            bonus_points_timer = app_timer_register(BONUS_TIMER_INVTERVAL, bonus_timer_callback, NULL);
        }

        game->bonus_points = snake->length / 2;
        
    }

    // Update the graphics
    // Note: this could be moved to a separate graphics update interval
    // But since the game tick here is the same as the graphics tick
    // I saw no need to do two timers

    layer_mark_dirty(game_layer);
    
    static char score_text[12];

    // Update score layer
    if (game->is_paused) {
        snprintf(score_text, sizeof(score_text), "Paused");  
    } else {
        snprintf(score_text, sizeof(score_text), "Score: %d ", game->score);   
    }

    text_layer_set_text(game_score_label, score_text);

    static char bonus_text[12];
    snprintf(bonus_text, sizeof(bonus_text), "Bonus: %d", game->bonus_points);
    text_layer_set_text(game_bonus_label, bonus_text);
}
Esempio n. 27
0
static void window_unload(Window *window) {
    game_end(0);
    text_layer_destroy(game_bonus_label);
    text_layer_destroy(game_score_label);
    layer_destroy(game_layer);
}
Esempio n. 28
0
/* p[0] = map, p[1] = &player, p[2] = bmap */
task_func floor_load(LPTCB t)
{
	int i, x, y, monscnt, id, bosscnt[2];
	struct _list *room_list;
	LPSPLAYER pl;
	LPSMONSTER mo;
	
	/* floor設定 */
	room_list = init_floor(t->p[0], t->p[2]);
	set_object(&x, &y, room_list, t->p[0], STAIRS);
	set_bmap_smell(t->p[2], x, y, SMELL_ST);
//	show_map2(t->p[2]);
	
	/* player設定 */
	pl = (LPSPLAYER)t->p[1];
	set_object(&x, &y, room_list, t->p[0], PLAYER);
	pl->x = x;
	pl->y = y;
	pl->fturn = 1;
	set_bmap_smell(t->p[2], x, y, SMELL_PL);
	
	/* monster設定 */
	chose_monscnt();
	monscnt = get_monscnt();
//	printf("monscnt: %d\n", monscnt);
	mo = get_mo_p();
	if(read_monster_area(floor_cnt, moarray) == 0){
		int chk;
		LPTCB mt;
		
		bosscnt[0] = bosscnt[1] = 0;
		for(i = 0; i < ENEMY_MAX; i++){
//			printf("%d: %d\n", i, moarray[i]);
			if(moarray[i] > 990000) bosscnt[0]++;
			else if(moarray[i] == 0) break;
			bosscnt[1]++;
		}
		
		/* ボス設定 */
		for(i = 0; i < bosscnt[0]; i++){
			if((chk = read_monster(moarray[i], mo+i)) == -1){
				list_free(room_list);
				game_end();
				return;
			}
			mt = create_monster(create_boss_monster(moarray[i]), get_des(moarray[i]), chk);
			mt->p[1] = t->p[1];
			mt->p[2] = t->p[2];
			
			set_object(&x, &y, room_list, t->p[0], MO_BOSS);
			(mo+i)->x = x;
			(mo+i)->y = y;
			set_bmap_smell(t->p[2], x, y, SMELL_BOSS);
		}
		
		/* 標準/Level monster設定 */
		for(i = bosscnt[0]; i < monscnt; i++){
			id = bosscnt[0] + get_random_range(0, bosscnt[1] - bosscnt[0]);
			if((chk = read_monster(moarray[id], mo+i)) == -1){
				list_free(room_list);
				game_end();
				return;
			}
			mt = create_monster(monster_move1, NULL, chk);
			mt->p[1] = t->p[1];
			mt->p[2] = t->p[2];
/*			printf("id: %d, name: %s, hp: %d, mp: %d, p: %d, d: %d\n",
				id, (mo+i)->name,(mo+i)->hp,(mo+i)->mp,(mo+i)->p,(mo+i)->d);
*/
			set_object(&x, &y, room_list, t->p[0], MONSTER);
			(mo+i)->x = x;
			(mo+i)->y = y;
			set_bmap_smell(t->p[2], x, y, SMELL_MO);
		}
	}
	
	/* キノコ設定 */
	init_mush(t->p[0], room_list);
	
	list_free(room_list);
	t->state = TASK_SLEEP;
}