Exemple #1
0
void sjf()
{
int time;
int i;
for(time=0;time<MAXTIME;time++)
{
int aaa=0;
    for(i=0;i<MAXNUM;i++)
    {
    if(p[i].arrivetime==time&&i!=0)
    {
        k=i;
        p[j].runtime+=1;
        is_over(time);
        aaa=1;
        printf("%d.00:\t进程%d到达\n",time,k);
        if(l==1)
        {
        j=i;
        printf("%d.00:\t进程%d开始运行\n",time,j);
        l=0;
        }else{
        if(p[i].servicetime<p[j].servicetime)
        {//抢占
 
        printf("%d.00:\t%d进程抢占,%d进程挂起\n",time,i,j);
        j=i;
        }else{
 
        }
        }
 
    }else{
        if(p[i].arrivetime==time&&i==0)//i==0
        {
        p[i].starttime=p[i].arrivetime;
        k=0;
        aaa=1;
        j=0;
        p[j].runtime+=1;
        printf("%d.00:\t进程%d开始运行\n",time,j);
        is_over(time);
        }
    }
    }
if(aaa==0&&l==0)
{
p[j].runtime+=1;
is_over(time);
}
if(aaa==0&&l==1)
{printf("%d.00:\t无进程运行\n",time);}
}
 
}
Exemple #2
0
int printStats (SDL_Surface *ecran) {
	SDL_Surface *jeu = IMG_Load("img/fond.png");
	SDL_Surface *nb0 = IMG_Load("img/nb0.png");
	SDL_Surface *nb1 = IMG_Load("img/nb1.png");
	SDL_Surface *nb2 = IMG_Load("img/nb2.png");
	SDL_Surface *nb3 = IMG_Load("img/nb3.png");
	SDL_Surface *nb4 = IMG_Load("img/nb4.png");
	SDL_Surface *nb5 = IMG_Load("img/nb5.png");
	SDL_Surface *nb6 = IMG_Load("img/nb6.png");
	SDL_Surface *nb7 = IMG_Load("img/nb7.png");
	SDL_Surface *nb8 = IMG_Load("img/nb8.png");
	SDL_Surface *nb9 = IMG_Load("img/nb9.png");
	SDL_Surface *none = IMG_Load("img/none.png");
	
	SDL_Surface *stats = IMG_Load("img/stats.png");
	SDL_Surface *menu = IMG_Load("img/menu2.png");
	SDL_Surface *menus = IMG_Load("img/menu2s.png");
	SDL_Surface *reset = IMG_Load("img/reset.png");
	SDL_Surface *resets = IMG_Load("img/resets.png");
	
	SDL_Surface *nb[10] = { nb0, nb1, nb2, nb3, nb4,
							nb5, nb6, nb7, nb8, nb9};
	
	SDL_Rect pos = {0, 0};
	SDL_Rect pos_reset = {240, 440};
	SDL_Rect pos_men = {440, 440};
	SDL_Rect pos_stats = {100, 150};
	SDL_Rect pos_s[3][5];
	
	SDL_BlitSurface(jeu, NULL, ecran, &pos);
	SDL_BlitSurface(menu, NULL, ecran, &pos_men);
	SDL_BlitSurface(reset, NULL, ecran, &pos_reset);
	SDL_BlitSurface(stats, NULL, ecran, &pos_stats);
	
	int continuer = 1;
	SDL_Event event;
	int x_m, y_m;
	int i, j;
	char data[3][6];
	
	init_pos_s (pos_s);
	
	read_stats(data);
	for (i = 0; i < 3; i++) {
		for (j = 0; data[i][j] != '\0'; j++) {
			SDL_BlitSurface(nb[data[i][j] - '0'], NULL, ecran, &pos_s[i][j]);
		}
	}
	
	SDL_Flip(ecran);
	
	while (continuer == 1) {
    	SDL_WaitEvent(&event);
        switch (event.type) {
           	case SDL_QUIT:
               	continuer = 0;
               	break;
            case SDL_MOUSEMOTION:
            	x_m = event.motion.x;
	           	y_m = event.motion.y;
           	
           		if (is_over(x_m, y_m, *menu, pos_men)) {
           			SDL_BlitSurface(menus, NULL, ecran, &pos_men);
           		} else if (is_over(x_m, y_m, *reset, pos_reset)) {
           			SDL_BlitSurface(resets, NULL, ecran, &pos_reset);
           		} else {
           			SDL_BlitSurface(menu, NULL, ecran, &pos_men);
           			SDL_BlitSurface(reset, NULL, ecran, &pos_reset);
           		}
           		break;
           	case SDL_MOUSEBUTTONUP:
            	x_m = event.button.x;
	           	y_m = event.button.y;
	           	
            	if (is_over(x_m, y_m, *menu, pos_men)) {
            		continuer = 2;
            	} else if (is_over(x_m, y_m, *reset, pos_reset)) {
            		reset_stats(data);
					for (i = 0; i < 3; i++) {
						for (j = 0; data[i][j] != '\0'; j++) {
							SDL_BlitSurface(none, NULL, ecran, &pos_s[i][j]);
						}
						SDL_BlitSurface(nb[0], NULL, ecran, &pos_s[i][0]);
					}
            	}
            	break;
            default:
            	break;
    	}
    	SDL_Flip(ecran);
    }
            	
	return continuer;
}