so if I get that right you have 18 buttons arranged in a 3 x 6 grid
Rules:
pressing a button would light up that button and if a button is already lit in a column, it would switch off (only one button ON per column).
pressing a lit button would switch it off
if you have a match of 3 buttons being lit (one in each column) according to some rules ("Sheep" "Wool" "Gloves") then it's a win, so you show some animation / sound and then turn off all the LEDs and the game is ready to start again
You need to decide what to do if there is no winning combination (turn everything off, or just not do anything until there is a match)
So you need 18 pins for the buttons (unless you use a matrix approach), 18 pins to command the LEDs, and some other (music, voice, sound) devices. An Arduino Mega could provide enough pins for that
Using a button library would make your life easier. I like the GitHub - bricoleau/easyRun: Doing sereval things at the same time becomes so easy collection of tools.
you could think of something like this for the structure of the code:
#include <easyRun.h> // https://github.com/bricoleau/easyRun
const byte colCount = 3;
const byte rowCount = 6;
button buttons[colCount][rowCount] = {
{{ 2}, { 3}, { 4}, { 5}, { 6}, { 7}}, // left column
{{A0}, {A1}, {A2}, {A3}, {A4}, {A5}}, // center column
{{14}, {15}, {16}, {17}, {18}, {19}}, // right column
};
const byte ledsPin[colCount][rowCount] = {
{20, 21, 22, 23, 24, 25}, // left column
{26, 27, 28, 29, 30, 31}, // center column
{32, 33, 34, 35, 36, 37}, // right column
};
byte ledsState[colCount][rowCount] = {LOW};
// indexes of winning combinations (starting at 0)
const byte solutions[rowCount][colCount] = {
{0, 2, 1}, // 1st button of left col + 3rd button of center col + second button of right col
{1, 0, 2},
{2, 1, 5},
{3, 5, 0},
{4, 3, 4},
{5, 4, 3},
};
const byte solutionsCount = sizeof solutions / sizeof solutions[0];
const byte emptyAnswer = 0xFF;
byte currentAnwer[colCount] = {emptyAnswer};
void resetGame() {
for (byte r = 0; r < rowCount; r++)
for (byte c = 0; c < colCount; c++) {
ledsState[c][r] = LOW;
digitalWrite(ledsPin[c][r], LOW);
}
memset(currentAnwer, emptyAnswer, colCount);
}
void win() {
Serial.println(F("Success"));
resetGame();
}
void testButtons() {
easyRun();
for (byte r = 0; r < rowCount; r++)
for (byte c = 0; c < colCount; c++) {
if (buttons[c][r]) {
Serial.print(F("button @ ("));
Serial.print(c); Serial.write(','); Serial.print(r);
Serial.println(F(") pressed"));
// check if that button was active
if (ledsState[c][r] == HIGH) {
currentAnwer[c] = emptyAnswer;
ledsState[c][r] = LOW;
digitalWrite(ledsPin[c][r], LOW);
} else {
currentAnwer[c] = r;
ledsState[c][r] = HIGH;
digitalWrite(ledsPin[c][r], HIGH);
// check in the column c if another button has been pressed
for (byte i = 0; i < rowCount; i++) {
if ((i != r) && (ledsState[c][i] == HIGH)) {
// there was a previous button activated. Switch it off
ledsState[c][i] = LOW;
digitalWrite(ledsPin[c][i], LOW);
break; // no need to go further, there should be only one
}
}
// check if there is a winning combination
for (byte i = 0; i < solutionsCount; i++) {
if (memcmp(currentAnwer, solutions[i], colCount) == 0) {
win();
return;
}
}
}
}
}
}
void setup() {
for (byte r = 0; r < rowCount; r++)
for (byte c = 0; c < colCount; c++) {
pinMode(ledsPin[c][r], OUTPUT);
digitalWrite(ledsPin[c][r], ledsState[c][r]);
}
Serial.begin(115200); Serial.println();
}
void loop() {
testButtons();
}
(totally untested)