# Matching memory Game

**URL:** https://discourse.processing.org/t/matching-memory-game/15076
**Category:** Project Guidance
**Created:** [October 31, 2019, 12:28pm UTC](https://discourse.processing.org/t/matching-memory-game/15076 "2019-10-31T12:28:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![filmon](https://avatars.discourse-cdn.com/v4/letter/f/b782af/32.png) [@filmon](https://discourse.processing.org/u/filmon)
#### Post date: [October 31, 2019, 12:28pm UTC](https://discourse.processing.org/t/matching-memory-game/15076/1 "2019-10-31T12:28:54Z")

</div>

i want two players but i dont know how it works

---

<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: [October 31, 2019, 1:25pm UTC](https://discourse.processing.org/t/matching-memory-game/15076/2 "2019-10-31T13:25:12Z")

</div>

Hello and welcome to the forum!

Nice to have you here.

> [@filmon](#):
>
> I want two players

You could make an integer variable **situation** that indicates whose move it is: Player 1 or Player 2.

Each move has two clicks, for the 1st and 2nd memory CARD.

So :

- situation 0 means Player 1, Card 1
- situation 1 means Player 1, Card 2 (then check if they match or not!! When they do add 1 to the score of Player 1)
- situation 2 means Player 2, Card 1
- situation 3 means Player 2, Card 2 (then check if they match or not!! When they do add 1 to the score of Player 2)

(This is similar to the variable _state_ (for different screens of the game) that you often see here in the forum but different.)

- The function showSituationText() shows whose move it is (and which Card) depending on the `situation`.

- The function mousePressed() registers mouse pressings depending on the `situation`.

Of course, now you need a grid with the _memory game_ with the images and data which are the pairs and which cards are open or closed and so on.

Regards, Chrisir

Example for two players:

```auto

// current situation 
int situation = 0;

// String with data of mouse pressings 
String text=""; 

// -------------------------------------------------

void setup() {
  // init (runs only once)
  size(800, 600);
  background(111);
} // func 

void draw() { 
  // draw() runs on and on 

  background(111); 

  // Show String with data of mouse pressings 
  fill(0); 
  text(text, width-210, 30); 

  // text whose move it is
  showSituationText(); 
  //
} // func 

// ------------------------------------------------

void showSituationText() {
  switch (situation) {

  case 0: 
    // 
    fill(255, 0, 0); 
    text("Player 1 make your 1st move", 67, 67); 
    break; 

  case 1:
    //
    fill(255, 0, 0); 
    text("Player 1 make your 2nd move", 67, 67);
    break;

  case 2: 
    // 
    fill(0, 0, 255); 
    text("Player 2 make your 1st move", 67, 67); 
    break; 

  case 3:
    //
    fill(0, 0, 255);
    text("Player 2 make your 2nd move", 67, 67);
    break;

  default:
    // error
    println("Error number 939; unknown situation : " 
      + situation + ".");
    exit();
    break;
  } // switch
}

// ------------------------------------------------

void mousePressed() {

  switch (situation) {

  case 0: 
    // 
    text+="Player 1: "+ mouseX+","+mouseY+" and "; 
    situation++; 
    break; 

  case 1:
    //
    text+=mouseX+","+mouseY+"\n"; 
    situation++;
    break;

  case 2: 
    // 
    text+="Player 2: "+ mouseX+","+mouseY+" and "; 
    situation++; 
    break; 

  case 3:
    // 
    text+=mouseX+","+mouseY+"\n"; 
    situation = 0; // reset 
    break;

  default:
    // error
    println("Error number 940; unknown situation : " 
      + situation + ".");
    exit();
    break;
  } // switch
  //
}//func 
// ------------------------------------------------

```
