# Pong Game: Trying to make 4 different messages for when a different player wins: "You won", "bot won", "player 1 won" and "player 2 won". Could only make 2: "Player 1 won" and "Player 2 or Bot won"

**URL:** https://discourse.processing.org/t/pong-game-trying-to-make-4-different-messages-for-when-a-different-player-wins-you-won-bot-won-player-1-won-and-player-2-won-could-only-make-2-player-1-won-and-player-2-or-bot-won/41310
**Category:** Coding Questions
**Created:** [March 16, 2023, 2:41am UTC](https://discourse.processing.org/t/pong-game-trying-to-make-4-different-messages-for-when-a-different-player-wins-you-won-bot-won-player-1-won-and-player-2-won-could-only-make-2-player-1-won-and-player-2-or-bot-won/41310 "2023-03-16T02:41:47Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sabisiiuuu](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sabisiiuuu](https://discourse.processing.org/u/sabisiiuuu)
#### Post date: [March 16, 2023, 2:41am UTC](https://discourse.processing.org/t/pong-game-trying-to-make-4-different-messages-for-when-a-different-player-wins-you-won-bot-won-player-1-won-and-player-2-won-could-only-make-2-player-1-won-and-player-2-or-bot-won/41310/1 "2023-03-16T02:41:47Z")

</div>

Hello everyone!

Basically the question. I am making a Pong Game and it is actually finished, but I just want to make it more perfect. I am only lacking these particular messages for when a winner has to be announced. I could only make “Player 1 won” and “Player 2 or Bot won”. But I would actually like the _winnerAnnouncer()_ function to recognize which play mode was being played: if the _onePlayer()_ or the _twoPlayers()_.

So here is part of my code:

```auto
int gameState = 0; // 0: home menu, 1: one player, 2: two players, 3: instructions, 4: winnerAnnouncer
int player1Score = 0;
int player2Score = 0;
int winningScore = 3;

boolean gameStarted = false;
boolean showInstructions = false;
boolean isSinglePlayer = true;

Paddle player1, player2;
Ball ball;

void setup() {
  size(600, 400);
  rectMode(CENTER);
  player1 = new Paddle(20, height/2);
  player2 = new Paddle(width-20, height/2);
  ball = new Ball();
  
}

void draw() {
  background(0);
  if (gameState == 0) {
    homeMenu();
  } else if (gameState == 1) {
    onePlayer();
  } else if (gameState == 2) {
    twoPlayers();
  } else if (gameState == 3) {
    instructions();
  } else if (gameState == 4) {
    winnerAnnouncer();
  }
}

void homeMenu() {
  textAlign(CENTER);
  textSize(64);
  fill(255);
  text("Pong", width/2, height/2-40);
  textSize(32);
  text("Press 1 for single player \n Press 2 for multiplayer \n Press 3 for instructions", width/2, height/2);
}

void onePlayer() {
  if (!gameStarted) {
    textAlign(CENTER);
    textSize(48);
    fill(255);
    text("SINGLE PLAYER", width/2, height/2 - 20);
    
    textSize(32);
    text("Press any key to start.", width/2, height/2 + 20);
  } else {
    if (isSinglePlayer) {
      player2.aiMove(ball);
    }
    updateGame();
  }
}

void twoPlayers() {
  if (!gameStarted) {
    textAlign(CENTER);
    textSize(48);
    fill(255);
    text("MULTIPLAYER", width/2, height/2 - 20);
    
    textSize(32);
    text("Press any key to start.", width/2, height/2 + 20);
  } else {
    updateGame();
  }
}

void winnerAnnouncer() {
  textAlign(CENTER);
  fill(255);
  textSize(48);
  if (player1Score == winningScore) {
    text("PLAYER 1 WON", width/2, height/2 - 20);
  } else {
    text("PLAYER 2 or BOT WON", width/2, height/2 - 20);
  }
  
  /*
  if (isOnePlayerMode) {
    if (player1Score == winningScore) {
      text("YOU WON!", width/2, height/2 - 20);
    } else if (player2Score == winningScore) {
      text("BOT WON!", width/2, height/2 - 20);
    }
  } else {
    if (player1Score == winningScore) {
      text("PLAYER 1 WON!", width/2, height/2 - 20);
    } else if (player2Score == winningScore) {
      text("PLAYER 2 WON!", width/2, height/2 - 20);
    }
  }
  */
  
  textSize(26);
  text("Press any key to return to the HOME MENU.", width/2, height/2 + 20);
}

```

I only sent the relevant code functions, but tell me if it is necessary for me to send the whole thing, as I believe it is not runnable.

Thank you in advance!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [March 16, 2023, 8:58am UTC](https://discourse.processing.org/t/pong-game-trying-to-make-4-different-messages-for-when-a-different-player-wins-you-won-bot-won-player-1-won-and-player-2-won-could-only-make-2-player-1-won-and-player-2-or-bot-won/41310/2 "2023-03-16T08:58:28Z")

</div>

> [@sabisiiuuu](#):
>
> to recognize which play mode was being played: if the _onePlayer()_ or the _twoPlayers()_.

I think in the menu you evaluate a keyPressed: because you say:

> [@sabisiiuuu](#):
>
> ```auto
> text("Press 1 for single player \n Press 2 for multiplayer \n Press 3 for instructions", width/2, height/2);
> }
> 
> ```

- so in keyPressed set a variable numOfPlayers to 1 or 2 in keyPressed()

- before setup() say `int numOfPlayers = 1;`

- Now we have stored the number of players in a clean way.

**The next step**

The next step is to evaluate numOfPlayers:

Your code:

> [@sabisiiuuu](#):
>
> ```auto
> void winnerAnnouncer() {
> textAlign(CENTER);
> fill(255);
> textSize(48);
> if (player1Score == winningScore) {
> text("PLAYER 1 WON", width/2, height/2 - 20);
> } else {
> text("PLAYER 2 or BOT WON", width/2, height/2 - 20);
> }
> 
> ```

is to change

```auto
void winnerAnnouncer() {
  textAlign(CENTER);
  fill(255);
  textSize(48);

  if (numOfPlayers == 1) {
    // numOfPlayers == 1 (human vs. bot)

    if (player1Score == winningScore) {
      text("YOU WON", width/2, height/2 - 20);
    } else {
      text("THE BOT WON", width/2, height/2 - 20);
    }

  }
  //---------------------
  else {
    // numOfPlayers == 2

    if (player1Score == winningScore) {
      text("PLAYER 1 WON", width/2, height/2 - 20);
    } else {
      text("PLAYER 2 WON", width/2, height/2 - 20);
    }//else 

  }//else 

```
