Exemplo n.º 1
0
void	display(char *map)
{
  int	start;
  int	nb_ply;
  int	nb_team;
  char	team_win;

  start = 0;
  while (42)
    {
      if ((nb_team = count_team(map)) == 1)
	team_win = get_last_team(map);
      nb_ply = count_player(map, 'a');
      start = (nb_ply >= NB_PLAY ? 1 : start);
      if (nb_ply < NB_PLAY && start == 0)
	wrt_str("-{ You have to put more player for start the game. }-\n");
      else
	wrt_str("-{ The Game is running ! }-\n");
      display_stat(map, nb_ply, nb_team);
      display_map(map);
      if (nb_ply == 1 && start == 1)
	{
	  printf("The team %d Win !!!!\n", team_win - '0');
	  break;
	}
    }
}
Exemplo n.º 2
0
void sm_loop(void)
{
	static unsigned long old_jiffies;


	if (old_jiffies != jiffies)
	{
		themps_update();
		uart_report();
		old_jiffies = jiffies;
		display_stat(display_state++);
		if (display_state >= DISP_LAST)
			display_state = DISP_NONE;
	}
	display_pulse();
}
Exemplo n.º 3
0
struct battle *createcombat(struct player* c1, struct player* c2)
{
    struct battle *b = malloc(sizeof(struct battle));
    
	create_stat(c1);
	create_stat(c2);
	c1->status = 1;
	c2->status = 2;
	c1->prev_id = bid;
	c2->prev_id = bid;
	c1->cur_bat = b;
	c2->cur_bat = b;
	c1->turn = 1;
	c2->turn = 0;
	
	b->battle_id = bid;
    b->status = 1;
    b->player_1 = c1;
    b->player_2 = c2;

	display_stat(b);

    return b;
}
Exemplo n.º 4
0
int handle(struct queue_list *clientlist, struct queue_list *playerlist, struct client *c)//TODO: change for new data structure
{
    char buf[256];
    char outbuf[512];
	struct player *p = c->player;

	int len = read(c->fd, buf, sizeof(buf) - 1);
    
    if (len > 256)
    {
        return -1;
    }
        
    else if (len > 0) 
    {
        buf[len - 1] = '\0';

        if (!p->name)
        {
            char * namep = malloc(len - 1);
            strncpy(namep, buf, len - 1);
            p->name = namep;
            sprintf(outbuf, "%s has joined the Arena!\r\n", namep);
            //broadcast(top, outbuf, strlen(outbuf));

        }

        if (!p->cur_bat)
        {
            int outlen = sprintf(outbuf,  "Welcome %s! Awaiting opponent...\r\n", p->name);
            write(p->fd, outbuf, outlen);

        }

        else 
        { 
            if (p->status == 0 || p->turn == 0)
            {
                printf("activity on %s, not handled\n", p->name);
                return 0;
            }
            
			struct battle *b = p->cur_bat;
            if (strcmp(buf, "a") == 0)
            {
                if ((attack(b, ATTACK)) == -1)
                {
                    printf("error in attack in battle %d\n", b->battle_id);
                    return -1;
                }

                if (display_stat(b) == -1)
                {
                    printf("display fail\n");
                }
		
            }

            else if (strcmp(buf, "p") == 0 && (p->stat->pm > 0))
            {
                if ((attack(b, PM)) == -1)
                {
                    printf("error in pm in battle %d\n", b->battle_id);
                    return -1;
                }

                if ((display_stat) == -1)
                {
                    printf("display fail\n");
                }
            }

            else if (strcmp(buf, "s") == 0)
            {
                //TODO:speak
            }
        }

        return 0;
    } 
    else if (len == 0)
    {
        // socket is closed
        printf("Disconnect from %s\n", inet_ntoa(p->client->ipaddr));
        sprintf(outbuf, "Goodbye %s\r\n", inet_ntoa(p->client->ipaddr));
        //broadcast(top, outbuf, strlen(outbuf));
        if (p->status == 1)
        {
            return 5;
        }
        return -1;
    } 
    else 
    { // shouldn't happen
        perror("read");
        return -1;
    }
}
Exemplo n.º 5
0
StatWidget::StatWidget(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
	display_stat(0,0);
}