Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use android Custom View to realize Gobang

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report