Arts >> Theater >> Comedy

SpongeBob "Friend or Foe Trash Bash" Code: C++ Simulation

The following C++ code simulates the "Friend or Foe" mini-game logic:

// 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;
}

Compile and run to play. Adjust parameters (time, score threshold, character count) as desired.

Comedy

Related Categories