예제 #1
0
int main () {
	PP_Open(); /* open the Prog&Play API */
	PP_Unit u = PP_GetUnitAt(MY_COALITION, 0);
	PP_Pos p = PP_Unit_GetPosition(u);
	p.x += 927;
	p.y -= 513;
	PP_Unit_ActionOnPosition(u, MOVE, p);
	/* close the Prog&Play API */
	PP_Close();
	return 0;
}
예제 #2
0
// faire progresser un groupe en ligne droite d'une certaine distance
void progresser (Groupe g, float distance){
	int i;
	PP_Pos pos;
	
	for (i = 0 ; i < g.nbMembres ; i++){
		pos = PP_Unit_GetPosition(g.membres[i]);
		pos.x = pos.x + distance;
		if (pos.x < 0)
			pos.x = 10;
		if (pos.x > PP_GetMapSize().x)
			pos.x = PP_GetMapSize().x - 10;
		PP_Unit_ActionOnPosition(g.membres[i], MOVE, pos);
	}
}
예제 #3
0
// déplacer toutes les unités à une coordonnée précise
int main (){
	int i; // compteur de boucle
	PP_Unit u; // unité courante
	// définition de al cible
	PP_Pos pos;
	pos.x = 256.0;
	pos.y = 1024.0;
	// ouverture du jeu
	PP_Open();
	// parcourir toutes les unités
	i = 0;
	while (i < PP_GetNumUnits(MY_COALITION)){
		// récupérer l'unité courante
		u = PP_GetUnitAt(MY_COALITION, i);
		// donner l'ordre de déplacement
		PP_Unit_ActionOnPosition(u, MOVE, pos);
		i++;
	}
	// fermer le jeu
	PP_Close();
}
예제 #4
0
int main (){
	int i, j, sens, distance;
	PP_Pos pos;
	PP_Unit u;
	Groupe armee;
	Groupe groupes [NB_GROUPES];
	bool premierLancement, enFuite;
	
	// ouverture du jeu
	PP_Open();
	// initialisation de l'armée
	initialiseBytes(&armee);
	
	// determination de la direction de l'attaque
	if (PP_GetStartPosition().x < PP_GetMapSize().x/2)
		sens = 1;
	else
		sens = -1;
	
	// lancer l'attaquer
	premierLancement = true;
	while (!PP_IsGameOver()){
		traiterUnitesDetruites(&armee);
		printf("  Taille armee : %d\n", armee.nbMembres);
		// restructurer les groupes
		trierSelon(&armee, Y);
		affecterGroupes(armee, groupes, 8);
		printf("  Affichage des groupes : \n");
		for (i = 0 ; i < NB_GROUPES ; i++)
			printf("    groupe %d : %d\n", i, groupes[i].nbMembres);
		
		if (PP_GetNumUnits(ENEMY_COALITION) == 0){
			// rechercher l'adversaire
			if (premierLancement){
				// si premier lancement, avancer en formation
				printf("  Lancer la marche\n");
				distance = sens*PP_GetMapSize().x;
				progresser(armee, distance);
				premierLancement = false;
				// attendre que l'armée ai commence a bouger (rester vigilant quand à la
				// présence de l'ennemie)
				while (PP_GetNumUnits(ENEMY_COALITION) == 0 && !mobile(armee))
					printf("Attente depart armee\n");
			}
			else{
				// rechercher aléatoirement l'adversaire
				for (i = 0 ; i < NB_GROUPES ; i++){
					if (!mobile(groupes[i])){
						pos.x = rand() % (int)PP_GetMapSize().x + 1;
						pos.y = rand() % (int)PP_GetMapSize().y + 1;
						for (j = 0 ; j < groupes[i].nbMembres ; j++)
							PP_Unit_ActionOnPosition(groupes[i].membres[j], MOVE, pos);
					}
				}
			}
		}
		else{
			// Affecter une cible à chaque groupes
			for (i = 0 ; i < NB_GROUPES ; i++){
				u = determinerCible(groupes[i]);
				printf("  Cible pour le groupe %d : %d\n", i, u);
				// pour chaque membre du groupe, donner l'ordre d'attaque si necessaire
				for (j = 0 ; j < groupes[i].nbMembres ; j++)
					if (!enAttaque(groupes[i].membres[j], u))
						PP_Unit_ActionOnUnit(groupes[i].membres[j], ATTACK, u);
			}
		}
	}
	
	// fermer le jeu
	PP_Close();
	return 0;
}
예제 #5
0
int main (){
	int i, j, sens;
	PP_Pos pos;
	PP_Unit u, select, tmp;
	bool attaque;
	float distance, dx, dy;
	PP_PendingCommands cmd;
	
	// ouverture du jeu
	PP_Open();
	
	// determination de la direction de l'attaque
	if (PP_GetStartPosition().x < PP_GetMapSize().x/2)
		sens = 1;
	else
		sens = -1;
	
	// lancer la marche
	for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
		pos = PP_Unit_GetPosition(PP_GetUnitAt(MY_COALITION, i));
		if (sens == -1)
			pos.x = 10;
		else
			pos.x = PP_GetMapSize().x - 10;
		PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos);
	}
	// attendre le départ de l'armée
	while (!mobile())
		printf("Attente depart armee\n");
	
	// ordonner d'attaquer les bytes ennemis
	while (!PP_IsGameOver()){
		if (PP_GetNumUnits(ENEMY_COALITION) == 0){
			// faire une recherche aléatoire
			for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
				u = PP_GetUnitAt(MY_COALITION, i);
				if (PP_Unit_GetPendingCommands(u, &cmd) != -1){
					if (cmd.nbCmds == 0){
						pos.x = rand() % (int)PP_GetMapSize().x + 1;
						pos.y = rand() % (int)PP_GetMapSize().y + 1;
						PP_Unit_ActionOnPosition(PP_GetUnitAt(MY_COALITION, i), MOVE, pos);
					}
				}
			}
		}
		else{
			// ordonner aux unités qui n'attaquent pas de cibler l'unité ennemie la plus proche d'elle
			for (i = 0 ; i < PP_GetNumUnits(MY_COALITION) ; i++){
				printf(" %d", i);
				u = PP_GetUnitAt(MY_COALITION, i);
				if (PP_Unit_GetPendingCommands(u, &cmd) != -1){
					attaque = false;
					if (cmd.nbCmds == 0)
						attaque = true;
					else if (cmd.nbCmds > 0)
						if (cmd.cmd[0].code != ATTACK)
							attaque = true;
					if (attaque){
						pos = PP_Unit_GetPosition(u);
						// calcul de la distance max pour cette carte
						distance = PP_GetMapSize().x*PP_GetMapSize().x+PP_GetMapSize().y*PP_GetMapSize().y;
						select = -1;
						for (j = 0 ; j < PP_GetNumUnits(ENEMY_COALITION) ; j++){
							tmp = PP_GetUnitAt(ENEMY_COALITION, j);
							dx = pos.x - PP_Unit_GetPosition(tmp).x;
							dy = pos.y - PP_Unit_GetPosition(tmp).y;
							if (dx*dx+dy*dy < distance){
								distance = dx*dx+dy*dy;
								select = tmp;
							}
						}
						if (select != -1)
							PP_Unit_ActionOnUnit(u, ATTACK, select);
					}
				}
				else{
					printf("%s", PP_GetError());
				}
			}
			printf("\n");
		}
	}
	// fermer le jeu
	PP_Close();
	return 0;
}