Example #1
0
//The main game loop.
void Game::play() {
    player->mutual_fov();
    int input;
    do {
        floors[current_level]->monsters_mutual_fov();
        wclear(level_win);
        floors[current_level]->print();
        wrefresh(level_win);
        
        show_messages();
        end_message_turn();
        
        wclear(stats_win);
        mvwprintw(stats_win, 0, 0, "HP %2i/%2i    Floor %i", player->get_hp(), player->get_max_hp(), current_level);
		if (floors[current_level]->contains_item(player->get_x_pos(), player->get_y_pos()))
			mvwprintw(stats_win, 0, 40, "There is a %s on the floor.", floors[current_level]->get_item(player->get_x_pos(), player->get_y_pos())->get_name());
		mvwprintw(stats_win, 1, 0, "Equipment:  Melee weapon: %-12s Suit: %s", player->get_inventory()->get_current_melee_weapon()->get_name(), player->get_inventory()->get_current_suit()->get_name());
		mvwprintw(stats_win, 2, 0, "           Ranged weapon: %-13s Hat: %s", player->get_inventory()->get_current_ranged_weapon()->get_name(), player->get_inventory()->get_current_hat()->get_name());
        wrefresh(stats_win);
        
        refresh();
        player_acted = false;
        input = player->take_turn();
        if(!game_over && player_acted)
            floors[current_level]->monsters_take_turns();
    } while(input != 'Q' && !game_over);
    if(game_lost) {
        show_messages();
        while(getch() != 'Q');
    }
}
Example #2
0
void show_screen() {
  graphmode();
  show_map();
  show_sm_map();
  show_side();
  show_player();
  show_messages();
  }
Example #3
0
void Game::write_message(const char *msg) {
    unsigned int mx = getmaxx(message_win);
    if(strlen(msg) + strlen(message_line_1) >= mx) {
        strcpy(message_line_0, message_line_1);
        message_line_1[0] = '\0';
    }
    strcat(message_line_1, msg);
    strcat(message_line_1, " ");
    show_messages();
}
Example #4
0
static notmuch_status_t
show_messages (void *ctx,
	       const notmuch_show_format_t *format,
	       sprinter_t *sp,
	       notmuch_messages_t *messages,
	       int indent,
	       notmuch_show_params_t *params)
{
    notmuch_message_t *message;
    notmuch_bool_t match;
    notmuch_bool_t excluded;
    int next_indent;
    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;

    sp->begin_list (sp);

    for (;
	 notmuch_messages_valid (messages);
	 notmuch_messages_move_to_next (messages))
    {
	sp->begin_list (sp);

	message = notmuch_messages_get (messages);

	match = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH);
	excluded = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);

	next_indent = indent;

	if ((match && (!excluded || !params->omit_excluded)) || params->entire_thread) {
	    status = show_message (ctx, format, sp, message, indent, params);
	    if (status && !res)
		res = status;
	    next_indent = indent + 1;
	} else {
	    sp->null (sp);
	}

	status = show_messages (ctx,
				format, sp,
				notmuch_message_get_replies (message),
				next_indent,
				params);
	if (status && !res)
	    res = status;

	notmuch_message_destroy (message);

	sp->end (sp);
    }

    sp->end (sp);

    return res;
}
Example #5
0
static void
show_messages (void *ctx,
	       const notmuch_show_format_t *format,
	       notmuch_messages_t *messages,
	       int indent,
	       notmuch_show_params_t *params)
{
    notmuch_message_t *message;
    notmuch_bool_t match;
    int first_set = 1;
    int next_indent;

    fputs (format->message_set_start, stdout);

    for (;
	 notmuch_messages_valid (messages);
	 notmuch_messages_move_to_next (messages))
    {
	if (!first_set)
	    fputs (format->message_set_sep, stdout);
	first_set = 0;

	fputs (format->message_set_start, stdout);

	message = notmuch_messages_get (messages);

	match = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH);

	next_indent = indent;

	if (match || params->entire_thread) {
	    show_message (ctx, format, message, indent, params);
	    next_indent = indent + 1;

	    fputs (format->message_set_sep, stdout);
	}

	show_messages (ctx,
		       format,
		       notmuch_message_get_replies (message),
		       next_indent,
		       params);

	notmuch_message_destroy (message);

	fputs (format->message_set_end, stdout);
    }

    fputs (format->message_set_end, stdout);
}
Example #6
0
/* Formatted output of threads */
static int
do_show (void *ctx,
         notmuch_query_t *query,
         const notmuch_show_format_t *format,
         notmuch_show_params_t *params)
{
    notmuch_threads_t *threads;
    notmuch_thread_t *thread;
    notmuch_messages_t *messages;
    int first_toplevel = 1;
    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;

    if (format->message_set_start)
        fputs (format->message_set_start, stdout);

    for (threads = notmuch_query_search_threads (query);
            notmuch_threads_valid (threads);
            notmuch_threads_move_to_next (threads))
    {
        thread = notmuch_threads_get (threads);

        messages = notmuch_thread_get_toplevel_messages (thread);

        if (messages == NULL)
            INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
                            notmuch_thread_get_thread_id (thread));

        if (!first_toplevel && format->message_set_sep)
            fputs (format->message_set_sep, stdout);
        first_toplevel = 0;

        status = show_messages (ctx, format, messages, 0, params);
        if (status && !res)
            res = status;

        notmuch_thread_destroy (thread);

    }

    if (format->message_set_end)
        fputs (format->message_set_end, stdout);

    return res != NOTMUCH_STATUS_SUCCESS;
}
Example #7
0
/* Formatted output of threads */
static int
do_show (void *ctx,
	 notmuch_query_t *query,
	 const notmuch_show_format_t *format,
	 sprinter_t *sp,
	 notmuch_show_params_t *params)
{
    notmuch_threads_t *threads;
    notmuch_thread_t *thread;
    notmuch_messages_t *messages;
    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;

    threads = notmuch_query_search_threads (query);
    if (! threads)
	return 1;

    sp->begin_list (sp);

    for ( ;
	 notmuch_threads_valid (threads);
	 notmuch_threads_move_to_next (threads))
    {
	thread = notmuch_threads_get (threads);

	messages = notmuch_thread_get_toplevel_messages (thread);

	if (messages == NULL)
	    INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
			    notmuch_thread_get_thread_id (thread));

	status = show_messages (ctx, format, sp, messages, 0, params);
	if (status && !res)
	    res = status;

	notmuch_thread_destroy (thread);

    }

    sp->end (sp);

    return res != NOTMUCH_STATUS_SUCCESS;
}
Example #8
0
/* Formatted output of threads */
static int
do_show (void *ctx,
	 notmuch_query_t *query,
	 const notmuch_show_format_t *format,
	 notmuch_show_params_t *params)
{
    notmuch_threads_t *threads;
    notmuch_thread_t *thread;
    notmuch_messages_t *messages;
    int first_toplevel = 1;

    fputs (format->message_set_start, stdout);

    for (threads = notmuch_query_search_threads (query);
	 notmuch_threads_valid (threads);
	 notmuch_threads_move_to_next (threads))
    {
	thread = notmuch_threads_get (threads);

	messages = notmuch_thread_get_toplevel_messages (thread);

	if (messages == NULL)
	    INTERNAL_ERROR ("Thread %s has no toplevel messages.\n",
			    notmuch_thread_get_thread_id (thread));

	if (!first_toplevel)
	    fputs (format->message_set_sep, stdout);
	first_toplevel = 0;

	show_messages (ctx, format, messages, 0, params);

	notmuch_thread_destroy (thread);

    }

    fputs (format->message_set_end, stdout);

    return 0;
}
Example #9
0
static void prefs_form_save_prefs(Short rw, Short ws)
{
  Boolean dirty, verydirty;
  dirty = prefs_save_lists(rw, ws);
  verydirty = prefs_save_checkboxes_1();
  dirty = prefs_save_checkboxes_2() || dirty;

  writePrefs();
  LeaveForm();
  if (verydirty) { // clear-and-redraw absolutely everything
    clear_visible();
    move_visible_window(you.ux, you.uy, true);
    show_messages();
    refresh();
    flags.botl = BOTL_ALL;
    print_stats(0);
  } else if (dirty) { // don't need to redraw msgs or stats
    // ?
    move_visible_window(you.ux, you.uy, true);
    refresh();
  }

}
Example #10
0
/**
 * Process data from the server
 */
int handle_server(int server_socket){
	char buffer[BUFFER_SIZE];
	memset(buffer,0,sizeof(buffer));

	struct header header;
	if(get_header(server_socket,&header)){
		printf("Failed to receive header from server, disconnecting\n");
		close(server_socket);
		return -1;
	}

	if(get_data(server_socket, &buffer, (header.length)) < 0){
		printf("Could not retrieve server's data\n");
		close(server_socket);
		return -1;
	}

	switch(header.type){
		case JOIN_RESP:
			perror("We should have already received our join response.... strange hapenings\n");
		break;
		case MESSAGE:
		{
			struct message *msg = (struct message*)buffer;
			add_message(msg);
			show_messages(windows[CHAT_WIN]);
			//wprintw(windows[CHAT_WIN],"%s\n",msg->message);
			wrefresh(windows[CHAT_WIN]);
		}
				
		break;
		case COMMAND:
		break;
		case USER_LIST_RESP:
		{
			struct message msg;
			msg.user_id = 65535;
			memset(msg.message,0,sizeof(msg.message));
			strcpy(msg.message,"[server: WHO]");
			msg.length = strlen(msg.message);

			add_message(&msg);

			struct user_list *list = (struct user_list*)buffer;
			list->user_count = ntohs(list->user_count);

			int index = sizeof(struct user_list);
			while(list->user_count --> 0){

				struct user *user = (struct user*)(buffer+index);
				index += sizeof(struct user);

				msg.user_id = 65535;
				memset(msg.message,0,sizeof(msg.message));
				strcpy(msg.message,"[who:  ");

				strcat(msg.message,user->name);

				strcat(msg.message,"]");
				msg.length = strlen(msg.message);
				add_message(&msg);
			}
			show_messages(windows[CHAT_WIN]);
			wrefresh(windows[CHAT_WIN]);
		}
		break;
		case WHOIS:
		{
			struct message msg;
			msg.user_id = 65535;
			memset(msg.message,0,sizeof(msg.message));
			strcpy(msg.message,"[server: WHOIS]");
			msg.length = strlen(msg.message);

			add_message(&msg);

			struct whois_response *who = (struct whois_response*)buffer;
			who->status = ntohs(who->status);
			switch(who->status){
				case OK:
				{
					strcpy(msg.message,"[name: ");
					strcat(msg.message,who->user.name);
					strcat(msg.message,"]");
					msg.length = strlen(msg.message);
					add_message(&msg);
					strcpy(msg.message,"[id: ");
					sprintf(msg.message+strlen(msg.message),"%d",ntohs(who->user.id));
					//strcat(msg.message,ntohs(who->user.id));
					strcat(msg.message,"]");
					msg.length = strlen(msg.message);
					add_message(&msg);
				}
				break;
				case NO_USER:
				{
					strcpy(msg.message,"[server: User not found]");
					msg.length = strlen(msg.message);
					add_message(&msg);
				}
				break;

				default:
				break;
			}

			show_messages(windows[CHAT_WIN]);
			wrefresh(windows[CHAT_WIN]);
		}
		break;
		break;
		default:
			printf("Unknown command type: %d\nDisconnecting client\n",header.type);
			close(server_socket);
			return -1;
	}

	return 0;

	/*while(get_message(client, &msg) >= 0){
		printf("Friend: %s\n",msg.message);
		printf("You: ");

		memset(&msg,0, sizeof msg);
		send_message(client, &msg);
		memset(&msg,0,sizeof msg);
	}
	*/
}
Example #11
0
/**
 * Process the user input
 * It handles building commands to the server as well as just sending messages
 */
int process_user(){
	int buffer_len = strlen(buffer);
	int command = 0;
	unsigned char* next_arg = buffer;

	print_prompt(windows[INPUT_WIN]);

	if(buffer_len == 0){
		return 0;
	}

	// TODO: add command processing
	if(buffer[0] == '/'){
		next_arg = strchr(buffer,' ');
		if(next_arg){
			*next_arg = 0; // null terminate the command
			next_arg++;
		}

		if(strcmp(buffer+1,"who") == 0){
			command = USER_LIST;
		}
		else if(strcmp(buffer+1,"pm") == 0){
			command = PM;
		}
		else if(strcmp(buffer+1,"whois") == 0){
			command = WHOIS;
		}
		else if(strcmp(buffer+1,"q") == 0){
			command = -1;
		}
		else if(strcmp(buffer+1,"quit") == 0){
			command = -1;
		}
		else if(strcmp(buffer+1,"help") == 0){
			command = HELP;
		}
	}

	switch(command){
		case -1:
			close_interface();
			return -1;
		break;
		case 0:
		{
			struct message message;
			memset(&message,0,sizeof(struct message));
			strcpy(message.message,buffer);

			message.length = strlen(message.message);
			message.user_id = CONFIG->self.id;
			send_message(CONFIG->self.socket,&message);
		}
		break;
		case PM:
		{
			unsigned char* to = next_arg;
			next_arg = strchr(next_arg,' ');
			if(next_arg){
				*next_arg = 0; // null terminate the command
				next_arg++;
			}else{
				return 0;
			}

			struct private_message message;
			memset(&message,0,sizeof(struct private_message));
			strcpy(message.to, to);
			strcpy(message.message.message,next_arg);

			message.message.length = strlen(message.message.message);
			message.message.user_id = CONFIG->self.id;
			message.from = CONFIG->self.id;
			send_pm(CONFIG->self.socket,&message);
		}
		break;
		case WHOIS:
		{
			send_whois_request(CONFIG->self.socket, next_arg);
		}
		break;
		case USER_LIST:
			send_user_list_request(CONFIG->self.socket);
		break;
		case HELP:
		{
			struct message msg;
			msg.user_id = 65535;
			memset(msg.message,0,sizeof(msg.message));
			strcpy(msg.message,"[Commands: ]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			strcpy(msg.message,"[who	Show who is on the server]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			strcpy(msg.message,"[whois <user> <msg>	Get details about a user]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			strcpy(msg.message,"[pm <username>	Send a private message to a user]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			/*strcpy(msg.message,"[Commands: ]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			strcpy(msg.message,"[Commands: ]");
			msg.length = strlen(msg.message);
			add_message(&msg);
			*/
			show_messages(windows[CHAT_WIN]);
			wrefresh(windows[CHAT_WIN]);
		}
		break;
	}

	memset(buffer,0,sizeof(buffer));
	return 0;
}
Example #12
0
static notmuch_status_t
show_messages (void *ctx,
               const notmuch_show_format_t *format,
               notmuch_messages_t *messages,
               int indent,
               notmuch_show_params_t *params)
{
    notmuch_message_t *message;
    notmuch_bool_t match;
    notmuch_bool_t excluded;
    int first_set = 1;
    int next_indent;
    notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;

    if (format->message_set_start)
        fputs (format->message_set_start, stdout);

    for (;
            notmuch_messages_valid (messages);
            notmuch_messages_move_to_next (messages))
    {
        if (!first_set && format->message_set_sep)
            fputs (format->message_set_sep, stdout);
        first_set = 0;

        if (format->message_set_start)
            fputs (format->message_set_start, stdout);

        message = notmuch_messages_get (messages);

        match = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH);
        excluded = notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);

        next_indent = indent;

        if ((match && (!excluded || !params->omit_excluded)) || params->entire_thread) {
            status = show_message (ctx, format, message, indent, params);
            if (status && !res)
                res = status;
            next_indent = indent + 1;

            if (!status && format->message_set_sep)
                fputs (format->message_set_sep, stdout);
        }

        status = show_messages (ctx,
                                format,
                                notmuch_message_get_replies (message),
                                next_indent,
                                params);
        if (status && !res)
            res = status;

        notmuch_message_destroy (message);

        if (format->message_set_end)
            fputs (format->message_set_end, stdout);
    }

    if (format->message_set_end)
        fputs (format->message_set_end, stdout);

    return res;
}