Biggytiny
Biggytiny

Reputation: 529

How to detect my Win Condition for an android game I am making

I am fairly new to android development and I am currently making a game which I have called "1-15 Puzzle." You may have heard of it, but basically it is a game where you have a 4x4 grid of numbers 1-15 and one blank space, and you have to arrange them in increasing order by sliding tiles around. Here is a picture of my main activity for the app:

enter image description here

This is what I would want the win condition of my game to look like, the numbers 1-15 are in increasing order with the blank space being in the bottom right hand corner. I tried hard coding it by testing for each buttons position, such as:

    x0 = blankButton.getX();
    y0 = blankButton.getY();
    x1 = oneButton.getX();
    y1 = oneButton.getY(); 

public boolean winCondition(){
    if (oneButton.getX() == x1) && (oneButton.getY() == y1) &&
       (blankButton.getX() == x0) && (blankButton.getY() == y0)){
           return true;}
    else return false;

This is just an example of a much larger function, but you get the idea. I was trying to simply test the actual button x and y coordinates, but it was not working properly. The reason I need this function is because I want to display a Victory message as well as stop the time / move counters, enabling me to keep track of high scores. Thank you for any help you can offer it is greatly appreciated.

Upvotes: 1

Views: 896

Answers (1)

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

This game is called jigsaw puzzle ... you can check game winning condition by using Images what you are using for numbers or.. any tags that you assigned to that particular slide's. Please look at this question How to check whether the jigsaw puzzle is completed or not?

Upvotes: 1

Related Questions