How to use android Custom View to realize Gobang
This article will explain in detail how to use android custom View to achieve Gobang. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
The details are as follows
Code:
* protected void onDraw (Canvas canvas) {super.onDraw (canvas); RectF rectF; for (int I = pandingx; I
< pandingx*7 ; i+=size){ for(int z= pandingy ; z < pandingy*30 ; z+=size){ rectF = new RectF(i , z , i+size , z +size); canvas.drawRoundRect(rectF , 1 ,1 ,paint); } } for(int i = 0 ; i =30){ if(event.getRawX()>Xx&&JudgeRight () = = true) {x + = size; xx = event.getRawX (); yy = event.getRawY ();} else if (JudgeLeft () = = true) {x-= size; xx = event.getRawX (); yy = event.getRawY ();} invalidate () } if (abs (event.getRawY ()-yy) > = 30) {if (event.getRawY () > yy&&JudgeButtom () = = true) {y + = size; xx = event.getRawX (); yy = event.getRawY ();} else if (JudgeTop () = = true) {y-= size; xx = event.getRawX (); yy = event.getRawY () } invalidate ();} break; case MotionEvent.ACTION_UP:// release int i; for (I = 0; I < list.size ()) {if (x = = (int) list.get (I) .get ("x") & & y = = (int) list.get (I) .get ("y")) {toast.repice (); break }} if (I = = list.size ()) {Map map = new HashMap (); map.put ("x", x); map.put ("y", y); map.put ("flag", flag); list.add (map); flag = (flag + 1) 2 If (deal.setPiont ((x-pandingx) / size, (y-pandingy) / size, flag+1)! = 0) {if (deal.setPiont ((x-pandingx) / size, (y-pandingy) / size, flag+1) = = 1) {toast.winblack ();} if (deal.setPiont ((x-pandingx) / size, (y-pandingy) / size, flag+1) = = 2) {toast.winwhite () } list.clear (); init ();} x =-100; y =-100; invalidate ();} break;} return true;}
It's probably just like this, realizing the monitoring of falling, sliding, and lifting movements of fingers. It looks a little messy, but that's probably what it means. The deal class is that I put the pieces I have already played into a two-dimensional array and deal with them separately to judge whether they have five beads in the end. Well, that's probably all!
On "how to use android custom View to achieve Gobang" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.