Arts >> Arte e intrattenimento >  >> Teatro >> Commedia

Codice SpongeBob "Friend or Foe Trash Bash": Simulazione C++

Il seguente codice C++ simula la logica del mini-gioco "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;
}

Compilate ed eseguite per giocare. Regolate parametri (tempo, soglia punteggio, numero personaggi) a piacere.

Commedia

Related Categories