void GameApplication::logicBoard() {
	eraseTileMap();
	unblockedBoard();

	if (endOfTheGame() && board.isStarted()) {
		youWin = true;
		winGames++;
		allGames++;
		award(calculateAward(calculate()));
		saveStatsFile(allGames, winGames);
		board.stop();
		timer.stop();
		winAnimation.startAnimation(50, 50);
	}
	if (availableMatches() == 0 && board.isStarted()) {
		youLose = true;
		allGames++;
		saveStatsFile(allGames, winGames);
		board.stop();
		timer.stop();
	}
}
static void
check_explode(void)
{
    register int i, l;
    register struct player *j;
    register struct torp *k;
    static struct player *killer;

    if (fl->pt_status == PTDET || fr->pt_status == PTDET ||
      fl->pt_status == PTEXPLODE || fr->pt_status == PTEXPLODE || explode) {
	if (plan_guard) {
	    restore_eye();
	    return;
	}			/* KAO */
	if (debug)
	    fprintf(stderr, "snake exploding\n");
	if (!explode) {
	    /* do once */
	    explode = s_clock;
	    tfuse = 0;
	    if (fl->pt_status == PTDET || fl->pt_status == PTEXPLODE) {
		killer = whokilledme(fl);
		if (killer)
		    award(killer);
	    }
	    if (fr->pt_status == PTDET || fr->pt_status == PTEXPLODE) {
		killer = whokilledme(fr);
		if (killer)
		    award(killer);
	    }
	}
	if (fl->pt_status != PTFREE && fl->pt_status != PTEXPLODE) {
	    fl->pt_war = FED | ROM | KLI | ORI;	/* make sure its at war when
						   it explodes */
	    fl->pt_status = PTEXPLODE;
	    fl->pt_fuse = 10;
	}
	if (fl->pt_status != PTFREE && fr->pt_status != PTEXPLODE) {
	    fl->pt_war = FED | ROM | KLI | ORI;
	    fr->pt_status = PTEXPLODE;
	    fr->pt_fuse = 10;
	}

	/*
	   now for some fancy stuff. If killer is our target and is hostile
	   or at war with our team then snake torp head makes a beeline for
	   him.  This lasts until killer dies or torps have been chasing
	   killer for 40 cycles
	*/
	if (killer  /* someone killed it */
	    && WARHOSTILE(killer)
	    && (noSmush < 1)
	    && (killer->p_status == PALIVE)
	    && tfuse < 40
	    && (killer->p_no == target || noSmush < 0)) {
	    crash_killer(killer);
	}
	else {
	    /* explode all torps in sequence, 1 per cycle until all gone */
	    for (j = perfs[0]; j; j = (j == perfs[1] ? NULL : perfs[1])) {
		for (l = (j == perfs[0]) ? 0 : length, i = j->p_no * MAXTORP, 
		     k = &torps[i]; i < j->p_no * MAXTORP + length; 
		     i++, k++, l++) {
		    if (l == explodetorps && k->t_status != TEXPLODE &&
			k->t_status != TFREE) {
			k->t_status = TEXPLODE;
			k->t_fuse = 10;
			explodetorps++;
			return;
		    }
		    else if (l == explodetorps)
			explodetorps++;
		}
	    }
	}
    }
}
Example #3
0
int main(int argc, char *argv[]){
	int n = 0, i = 0, m = 0, hours = 0, minutes = 0, ccf = 0, cfl = 0, scf = 0, fscf = 0, days = 0, P = 0, vi = 0;
	char *p = NULL, *file = NULL;
	double IFT = 0, V = 0;
	struct fulldate START, END;
	struct cf *CF;
	START.YEAR = 2001;
	START.MONTH = 1;
	START.DAY = 1;
	START.HOUR = 0;
	START.MINUTE = 0;

	END.YEAR = 2020;
	END.MONTH = 12;
	END.DAY = 31;
	END.HOUR = 23;
	END.MINUTE = 59;

	for (i = 1; i < argc - 1; i++){
		if (strcmp(argv[i], "-p") == 0){
			file = argv[i + 1];
		}
		else if (strcmp(argv[i], "-n") == 0){
			n = atoi(argv[i + 1]);
		}
		else if (strcmp(argv[i], "-s") == 0){
			p = argv[i + 1];
			START.YEAR = (atoi(p) >= 2001) ? atoi(p) : 2001;
			START.MONTH = (atoi(p + 5) >= 0 && atoi(p + 5) <= 12) ? atoi(p + 5) : 1;
			START.DAY = (atoi(p + 8) >= 0 && atoi(p + 8) <= 31) ? atoi(p + 8) : 1;
			START.HOUR = (atoi(p + 11) >= 0 && atoi(p + 11) <= 24) ? atoi(p + 11) : 0;
			START.MINUTE = (atoi(p + 14) >= 0 && atoi(p + 14) <= 59) ? atoi(p + 14) : 0;
		}
		else if (strcmp(argv[i], "-e") == 0){
			p = argv[i + 1];
			END.YEAR = (atoi(p) >= 0) ? atoi(p) : 1;
			END.MONTH = (atoi(p + 5) >= 0 && atoi(p + 5) <= 12) ? atoi(p + 5) : 1;
			END.DAY = (atoi(p + 8) >= 0 && atoi(p + 8) <= 31) ? atoi(p + 8) : 1;
			END.HOUR = (atoi(p + 11) >= 0 && atoi(p + 11) <= 24) ? atoi(p + 11) : 0;
			END.MINUTE = (atoi(p + 14) >= 0 && atoi(p + 14) <= 59) ? atoi(p + 14) : 0;
		}
		else if (strcmp(argv[i], "-r") == 0){

		}
		else if (strcmp(argv[i], "-i") == 0){
			vi = 1;
		}
		else if (strcmp(argv[i], "-v") == 0){

		}
	}

	struct flight *F;
	if ((F = read_file(file, &ccf, &cfl)) == NULL){
		if (file == NULL){
			printf("Error: No file at input!\n");
			return -1;
		}
		else{
			printf("Error: File '%s' does not exists!\n", file);
			return -1;
		}
	}
	else{
		CF = set(F, END, cfl, &scf, &fscf, &IFT, n);
		if (n > 0)
			IFT /= n;
		CF = award(CF, n, &P, &IFT, &V);
		if (vi)
			printf("V = %0.3f\n", V);
	}
	return 0;
}