Android source code download: Five-piece elimination game

Android source code download: Five-piece elimination game

Functional classification: Leisure and puzzle

Supported platforms: Android

Operating environment: Android

Development language: Java

Development tools: Ecppse

Source code size: 5.43MB

Source code download address: http://down..com/data/1975239

Source code introduction

The source code of a popular five-piece elimination game in the past. I have studied it in the early days, and I hope that friends who are interested can study and discuss it together.

Source code running screenshot

Game Splash interface

The game starts with two teams facing each other

When the game succeeds, the score is tallied and the controls disappear

Source code snippet:

  1. //Some algorithm fragments involved in the game  
  2. /**
  3. * Breadth-first search method
  4. * @param from starting point
  5. * @param to end point
  6. * @param beads beads two-dimensional array
  7. * @return
  8. */  
  9. private   boolean isLink(Point from, final Point to, Bead[][] beads) {
  10. // Step 1: Record the points you have walked through  
  11. invalidPoints.add(from);
  12. // Step 2: Get the top, right, left and bottom points.  
  13. Point[] points = {
  14. new Point(from.x, from.y - 1 ),
  15. new Point(from.x, from.y + 1 ),
  16. new Point(from.x - 1 , from.y),
  17. new Point(from.x + 1 , from.y)
  18. };
  19. // Step 3: Determine whether the four points are valid or the destination points.  
  20. List<point> temp = new ArrayList<point>();
  21. for (Point p : points){
  22. // Have we reached the destination?  
  23. if (p.equals(to)){
  24. pathPoints.add(p);
  25. return   true ;
  26. }
  27. if (isCheck(p, beads)){
  28. temp.add(p);
  29. }
  30. }
  31. // Step 4: Determine whether all valid points are occupied.  
  32. if (temp.isEmpty()) return   false ;
  33.           
  34. // Step 5: Sort the valid points by the shortest path.  
  35. Collections.sort(temp, new Comparator<point>() {
  36. @Override  
  37. public   int compare(Point p1, Point p2) {
  38. double r1 = Math.sqrt((p1.x - to.x) * (p1.x - to.x) + (p1.y - to.y) * (p1.y - to.y));
  39. double r2 = Math.sqrt((p2.x - to.x) * (p2.x - to.x) + (p2.y - to.y) * (p2.y - to.y));
  40. return r1 < r2 ? - 1 : 0 ;
  41. }
  42. });
  43. // Step 6: Recursively find valid points and search until the destination point is reached or all valid points are searched.  
  44. for (Point p : temp){
  45. boolean flag = isLink(p, to, beads);
  46. if (flag){
  47. pathPoints.add(p);
  48. return   true ;
  49. }
  50. }
  51. return   false ;
  52. }</point></point></point>

Source code download address: http://down..com/data/1975239

<<:  iOS source code download: Draw the input words with animation

>>:  Wandoujia opens up a new way to discover personalized content

Recommend

To programmers: 8 reasons why users hate your mobile app

There are tens of thousands of mobile apps on the...

How to use Luckin Coffee coupons!

Luckin Coffee ’s coupon marketing can only help i...

How to formulate a product strategy to attract new customers?

As the Internet enters the second half, the price...

E-commerce operation: a comprehensive review of promotional activities skills!

In this article, let’s take a look at the types o...

How Chinese programmers get Facebook offers

Preface In October 2014, I was fortunate enough t...

What! Wood can become as transparent as glass?

When you think of transparent things, what do you...