示例#1
0
/******************************* Print functions */
void World::Print()
{
	PrintBlack();
	PrintTitle();
	for (int i = 0; i < 3; i++) /*trying to reduce the image blinking*/
	{							/*without develop a char buffer*/
		PrintStars();
		PrintHero();
		PrintBullets();
		PrintEnemies();
		PrintHero();
	}
	PrintGameInfo();
}
void COMMAND_ATTACK(Unit *attacker) {
    if (!GetChanceAttack(*attacker)) {
        printf("You can't attack with this unit.\n");
        return;
    }

    Enemies enemies = GetAdjacentEnemyData(*attacker);
    if (enemies.count == 0) {
        printf("No enemy nearby.\n");
        return;
    }
    
    int index;

    printf("Please select enemy you want to attack:\n");
    PrintEnemies(enemies);
    
    do {
        printf("Select enemy you want to attack: ");
        scanf("%d", &index);
    } while (index < 1 || index > enemies.count);

    Unit *attacked = enemies.enemy[index-1].unit;
    char stringAttackedClass[11];
    UnitClassName(GetUnitClass(*attacked), stringAttackedClass);

    if (rand() % 100 < GetProbabilityExposedToAttack(*attacked)) {
        SetHealth(attacked, GetHealth(*attacked) - GetAttack(*attacker));
        printf("Enemy's %s is damaged by %d.\n", stringAttackedClass, GetAttack(*attacker));
    } else {
        printf("Enemy's %s dodges the attack.\n", stringAttackedClass);
    }

    SetMovementPoints(attacker, 0);
    SetChanceAttack(attacker, false);

    if (GetHealth(*attacked) <= 0) {
        Kill(attacked);
        printf("Enemy's %s is dead :)\n", stringAttackedClass);
    } else {
        if (enemies.enemy[index-1].canRetaliate) {
            char stringAttackerClass[11];
            UnitClassName(GetUnitClass(*attacker), stringAttackerClass);

            printf("Enemy's %s retaliates.\n", stringAttackedClass);

            if (rand() % 100 < GetProbabilityExposedToAttack(*attacker)) {
                SetHealth(attacker, GetHealth(*attacker) - GetAttack(*attacked));
                printf("Your %s is damaged by %d\n", stringAttackerClass, GetAttack(*attacked));

                if (GetHealth(*attacker) <= 0) {
                    Kill(attacker);
                    printf("Your %s is dead :(\n", stringAttackerClass);
                }
            } else {
                printf("Your %s dodges the attack.\n", stringAttackerClass);
            }
        }
    }

    printf("\n");
}