Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7052719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:25:04+00:00 2026-05-28T03:25:04+00:00

I’m trying to write a client for a easy game console, 1vs1. The game:

  • 0

I’m trying to write a client for a easy game console, 1vs1. The game: 1 player has to catch the other; every player is represented by a char, # and $. To manage the data, I use 3 processes:

  1. Process A. Process A gets the position of the enemy from the server, and writes it on a pipe;
  2. Process B. Process B gets the input from the keyboard,updates the position of the player, writes it on a pipe;
  3. Process C. Process C reads the pipe and displays the map with the two characters, every one representing a player.

Now, to display the characters in process C, I use the mvaddch(), provided from <curses.h>. My problem is it seems not working, but if I use mvaddch() in process B, it works… “and I can paint a snake composed of consecutive x’s”.

 ...
  initscr();
noecho();
curs_set(0);

role = position.c;

if ( pipe(filedes) == -1)   {perror("pipe() fallita");  exit(0);    }
    // process A is creaded now
switch ( pid_nemico = fork() ) {
    case -1:    perror("fork() fallita");   exit(0);
    case 0:     close(filedes[0]);
            while (1) {
                while ( recv(sock, &position, sizeof(struct pos), 0) < 1 )
                write(filedes[1], &position, sizeof(struct pos));   }   // position rappresenta la posizione del nemico
    default:    break ;         }                       // che viene mandata dal server
    //process B is created now, and within mvaddch works
switch ( pid = fork() ) {
    case -1:    perror("fork() fallita");   exit(0);
    case 0:     close(filedes[0]);
            char c;
            while (1) {
                switch(c=getch()) {
                    case SU:    if(position.y>0) {  position.y-=1;
                                write(filedes[1], &position, sizeof(struct pos));
                                send(sock, &position, sizeof(struct pos), 0);   } break;

                    case GIU:   if(position.y<MAXY-1){  position.y+=1; 
                                write(filedes[1], &position, sizeof(struct pos));
                                send(sock, &position, sizeof(struct pos), 0);   } break;

                    case SINISTRA:  if(position.x>0){   position.x-=1;
                                write(filedes[1], &position, sizeof(struct pos));
                                send(sock, &position, sizeof(struct pos), 0);   } break;

                    case DESTRA:    if(position.x<MAXX-1){  position.x+=1;
                                write(filedes[1], &position, sizeof(struct pos));
                                send(sock, &position, sizeof(struct pos), 0);   } break;
                    default: break; }
                    }
    default:    break ;         }
    // And this is the remaining Process, process C, where mvaddch does not work
close(filedes[1]);
struct pos pos_guardia = {'#', 0, 0};
struct pos pos_ladro = {'$', 0, 0};
read(filedes[0], &position, sizeof(struct pos));

    while ((position.c == '#') || (position.c == '$')) {
        switch (position.c) {
            case '#':   printf("%d\n",mvaddch(pos_guardia.y, pos_guardia.x, ' ')    );
                    mvaddch(position.y, position.x, '#');
                    pos_guardia.x = position.x;
                    pos_guardia.y = position.y;
                    break;
            case '$':   printf("%d\n",mvaddch(pos_ladro.y, pos_ladro.x, ' ')        );
                    mvaddch(position.y, position.x, '$');
                    pos_ladro.x = position.x;
                    pos_ladro.y = position.y;
                    break;
            case 'G':   if (role == '#') {  printf("Hai vinto la Partita");
                     }else{         printf("Hai perso la Partita"); }
                    break;
            case 'L':   if (role == '$') {  printf("Hai vinto la Partita");
                     }else{         printf("Hai perso la Partita"); }
                    break;
            default:    printf("Pacchetto ricevuto non interpretato");  }
        read(filedes[0], &position, sizeof(struct pos));    }
kill(pid_nemico);
kill(pid);
printf("\n-----------------------------\n");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:25:04+00:00Added an answer on May 28, 2026 at 3:25 am

    Since you never refresh() the display, there’s no occasion for the characters to move.

    The curses library only sends updates to the screen when you use refresh().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.