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

Foods containing aluminum: I won’t take the blame for Alzheimer’s disease!

Will eating foods containing aluminum cause Alzhe...

JavaScript Pretend Guide

This article adheres to If you don't understa...

Tibetan Fox: I'm so square! I did it on purpose

The Tibetan fox , with its confused and world-wea...

How does Station B operate?

Traffic is becoming more and more expensive and i...

Can brand promotion still involve spending money?

New brands are firmly rooted in the sub-segments ...

What is the difference between WeChat Phonebook and VoLTE?

WeChat Phonebook is now online! How big of an imp...

Using Clang Address Sanitizer directly on Xcode 7

[[143029]] At WWDC 2015, in addition to Swift 2.0...