Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with creating the Lights Out game using Processing: Link1 (for below):

ID: 3818765 • Letter: N

Question

Need help with creating the Lights Out game using Processing:

Link1 (for below): http://www.neok12.com/games/lights-out/lights-out.htm

Link 2 (for below): https://www.jaapsch.net/puzzles/lights.htm

Description: You will implementing the Lights Out Game in processing. Here is a link(s) to the description and playable version of the game. Link1 Link2. You will have a lot of room to the design and build this game the way you wish but you do need to follow the rules below. Requirements: You MUST to implement the following classes and features to the game Light Class o Description Square on screen that has 2 states: on and off On/off states should display 2 different colors. Clickable Player can click a light which flips it to its opposite state o Also flips its neighbor to opposite state o Properties x, y position width, height Boolean on Represents its on/off state. Color c Color of the light (changes when clicked) Board class o Description Creates, contains and updates 25 light objects on screen. Creates the starting configuration for the player to solve.

Explanation / Answer

Code For Lights Out Game Using Processing is here :

int n;
int start_number;
boolean[][] init_init_data;

void setup()
{
size(700, 700);
n = 5;
start_number = 1;
init_data = new boolean[n][n];
Board();
}

void draw()
{
Light();
}

void Board()
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
init_data[i][j] = false;
}
}

int a = 0;
while (a < start_number)
{
int i = int(random(n));
int j = int(random(n));
if (! init_data[i][j])
{
init_data[i][j] = true;
a++;
}
}
}

void keyPressed()
{
if (key == '1')
{
start_number = 1;
}
if (key == '2')
{
start_number = 2;
}
if (key == '3')
{
start_number = 3;
}
if (key == '4')
{
start_number = 4;
}
if (key == '5')
{
start_number = 5;
}
if (key == '6')
{
start_number = 6;
}
if (key == '7')
{
start_number = 7;
}
if (key == '8')
{
start_number = 6;
}
if (key == '9')
{
start_number = 7;
}

Board();
}
void mouseClicked()
{
float x = mouseX;
float y = mouseY;

int i = int(x / width * n);
int j = int(y / height * n);

swap_tiles(i, j);
swap_tiles(i+1, j);
swap_tiles(i-1, j);
swap_tiles(i, j+1);
swap_tiles(i, j-1);
}


void swap_tiles(int i, int j)
{
if (i >= 0 && i < n && j >= 0 && j < n)
{
if (init_data[i][j])
{
init_data[i][j] = false;
} else
{
init_data[i][j] = true;
}
}
}


void Light()
{
stroke(255);
strokeWeight(3);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (init_data[i][j])
{
fill(251, 49, 38);
} else
{
fill(21, 181, 180);
}
float w = width / n;
rect(w * i, w * j, w, w);
}
}
}

Thank You.