Need a Logic to say Bingo
I am creating an iphone app where I have a grid view of 25 images as:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 开发者_如何学Go22 23 24
Now when any 5 consecutive images are selected it should say bingo, like if 0,6, 12, 18, 24 are selected it should say Bingo.
How will i do that, please help me.
Many Thanks for your help.
Rs iPhone Developer
----------------------------------- | 0 | 1 | 2 | 3 | 4 | 5 | ----------------------------------- | 6 | 7 | 8 | 9 | 10 | 11 | ----------------------------------- | 12 | 13 | 14 | 15 | 16 | 17 | ----------------------------------- | 18 | 19 | 20 | 21 | 22 | 23 | ----------------------------------- | 24 | -----------------------------------
Hope this is how your grid looks like.
Associate each column with an array. The array will contain the list of all neighbour elements of that column,
For example, the neighbor array of the column [ 6 ] will ollk like array(0, 7, 12), which are all the immediate neighbors of [ 6 ].
- Set counter = 0;
- Now, when someone clicks an element, increment the counter (Now counter = 1)
- When he clicks the second element, check if the element is in the neighbor list of the previous element OR the 1st element. If the element clicked is in the neighbor list, increment the counter (now counter = 2) ELSE If the element clicked is not in the neighbor array, reset the counter (counter = 0) and start over.
- Check if the value of counter = 5. If it is, Say Bingo!
The algorithm is not fully correct, but I hope you got the idea :)
精彩评论