Nasledujúci C++ kód simuluje logiku mini-hry „Friend or Foe“:
// Friend or Foe Trash Bash Simulation
#include
#include
#include
#include
using namespace std;
char generateCharacter() {
return (rand() % 2 == 0) ? 'F' : 'S'; // Foe or Friend
}
void playGame() {
int score = 0, timeLeft = 60;
vector chars;
for (int i = 0; i < 10; ++i) chars.push_back(generateCharacter());
while (timeLeft > 0 && score < 100) {
char c = chars[0];
cout << "Approaching: " << c << " (F=Foe, S=Friend)\nYour guess: ";
char guess; cin >> guess;
if (toupper(guess) == c) {
score += 10; cout << "Correct! +10\n";
} else {
score -= 5; cout << "Wrong! -5\n";
}
chars.erase(chars.begin()); --timeLeft;
cout << "Score: " << score << " | Time: " << timeLeft << "\n\n";
}
cout << (score >= 100 ? "You won!" : "Game over.") << endl;
}
int main() {
srand(time(0)); playGame(); return 0;
}
Kompilujte a spustite pre hranie. Upravte parametre (čas, prahová hodnota skóre, počet postáv) podľa potreby.