コード例 #1
0
ファイル: do_name.c プロジェクト: FredrIQ/nhfourk
int
do_tname(const struct nh_cmd_arg *arg)
{
    struct obj *obj = getargobj(arg, callable, "call");
    if (obj) {
        /* behave as if examining it in inventory; this might set dknown if it 
           was picked up while blind and the hero can now see */
        examine_object(obj);

        if (!obj->dknown) {
            pline("You would never recognize another one.");
            return 0;
        }
        docall_inner(arg, obj->otyp);
    }
    return 0;
}
コード例 #2
0
ファイル: player.c プロジェクト: Joshun/textadventure-engine
void start_game(playerType *player, roomBase *roomdb, objectBase *objectdb, enemyBase *enemydb)
{
	player->quit = 0;
	player->n_object_ids = 0;
	player->health = 100;
	int test_coordinates[2] = { 0, 0 };
	int input_size = 0;
	char input_command[INPUT_LENGTH] = { 0 };
	char input_parameter[INPUT_LENGTH] = { 0 };
	player->current_room = get_room_from_id(player->starting_room_id, roomdb);
	set_player_coordinates(player->current_room->coordinates, player);
	show_room_content(player->current_room, objectdb);
		
	while( ! player->quit )
	{
		input_size = player_input(player, input_command, input_parameter);
		
		if( COMP_STR(input_command, "exit") || COMP_STR(input_command, "quit") || feof(stdin) ) {
			printf("Thanks for playing, have a nice day!\n");
			player->quit = 1;
		}
		else if( COMP_STR(input_command, "look")	) {
			show_room_content(player->current_room, objectdb);
		}
		else if( COMP_STR(input_command, "health") ) {
			printf("Player HP: %d\n", player->health);
		}
		else if( COMP_STR(input_command, "inventory" ) ) {
			show_inventory(player, objectdb);
		}
		else if( COMP_STR(input_command, "examine" ) ) {
			examine_object(input_parameter, player, objectdb);
		}
		else if( COMP_STR(input_command, "take" ) ) {
			take_object(input_parameter, player, objectdb);
		}
		else if( COMP_STR(input_command, "use" ) ) {
			use_object(input_parameter, player, objectdb, roomdb, enemydb);
		}
		else if( COMP_STR(input_command, "north" ) ) {
			test_coordinates[0] = player->coordinates[0];
			test_coordinates[1] = player->coordinates[1] + 1;
			go_to_room(player, roomdb, test_coordinates, objectdb, enemydb);
		}
		else if( COMP_STR(input_command, "south" ) ) {
			test_coordinates[0] = player->coordinates[0];
			test_coordinates[1] = player->coordinates[1] - 1;
			go_to_room(player, roomdb, test_coordinates, objectdb, enemydb);
		}
		else if( COMP_STR(input_command, "east" ) ) {
			test_coordinates[0] = player->coordinates[0] + 1;
			test_coordinates[1] = player->coordinates[1];
			go_to_room(player, roomdb, test_coordinates, objectdb, enemydb);
		}
		else if( COMP_STR(input_command, "west" ) ) {
			test_coordinates[0] = player->coordinates[0] - 1;
			test_coordinates[1] = player->coordinates[1];
			go_to_room(player, roomdb, test_coordinates, objectdb, enemydb);
		}
		else if( COMP_STR(input_command, "help" ) ) {
			printf("Commands: %s\n", COMMANDS_LIST);
		}
		else {
			if( input_size > 0 ) /* check that the user hasn't simply just pressed enter */
				printf("I don't understand that. Type \"help\" for a list of recognised commands\n");
		}
	}
		
}