How do I get a winning picture in a slide puzzle?

94 Views Asked by At

I make a slide puzzle game. When the puzzle is solved "won" should be displayed and the timer should stop.

I hope you can help me. Thanks.

Here is a link to the web editor for my puzzle link

Here is the part of the code but it doesn´t work:

function draw() {
  if (isSolved()) {
    console.log('SOLVED');
    timerValue = 0;
    text('Won', width/2, height/2);
  }   
}

function isSolved() {
  for (let i = 0; i < plate.length - 1; i++) {
    if (plate[i] !== tiles[i].index) {
      return false;
    }
  }
return true;
}
1

There are 1 best solutions below

2
Voxel On

P5JS is saying that createImage() was expecting Integer for the second parameter, received number instead. This can be solved by changing let img = createImage(w, h); tp let img = createImage(int(w), int(h));.

I'm not entirely sure if this helps, because I don't know how your puzzle works (how it's solved) so please tell me if this doesn't work and I'll investigate further.