当前位置: 首页 > news >正文

网站关键词做排名不分免费软文网站

网站关键词做排名不分,免费软文网站,常见b2c网站有哪些,wordpress 全站https目录 题目:完成在Android平台下2个玩家分别利用2个手机连接在同一局域网下通过滑动摇杆分别使红飞机和黄飞机移动的开发。(全代码解析) 题目:完成在Android平台下2个玩家分别利用2个手机连接在同一局域网下通过滑动摇杆分别使红飞…

目录

题目:完成在Android平台下2个玩家分别利用2个手机连接在同一局域网下通过滑动摇杆分别使红飞机和黄飞机移动的开发。(全代码解析)


题目:完成在Android平台下2个玩家分别利用2个手机连接在同一局域网下通过滑动摇杆分别使红飞机和黄飞机移动的开发。(全代码解析)

用一个真机运行,连接此电脑 的模拟机进行利用2个手机连接在同一局域网下通过滑动摇杆分别使红飞机和黄飞机移动的开发

运行结果: 

模拟机:

真机:

DrawThread.java代码:
package com.example.client.thread;import com.example.clinet.view.GameView;import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.view.SurfaceHolder;public class DrawThread extends Thread
{private int SLEEP_SPAN =50;//睡眠的毫秒数private SurfaceHolder surfaceHolder;private GameView view;private boolean flag = true;public DrawThread(SurfaceHolder surfaceHolder, GameView view) {//构造器this.surfaceHolder = surfaceHolder;this.view = view;}public void setFlag(boolean flag) {//设置循环标记位this.flag = flag;}@SuppressLint("WrongCall")public void run(){Canvas c;while(flag){c = null;try{// 锁定整个画布,在内存要求比较高的情况下,建议参数不要为nullc = this.surfaceHolder.lockCanvas(null);synchronized (this.surfaceHolder){this.view.onDraw(c);}} finally{if (c != null){//更新屏幕显示内容this.surfaceHolder.unlockCanvasAndPost(c);}}try{Thread.sleep(SLEEP_SPAN);//睡眠指定毫秒数}catch(Exception e){e.printStackTrace();}}}
}

KeyThread.java代码:
package com.example.client.thread;import com.example.client.MainActivity;
import com.example.util.GameData;public class KeyThread extends Thread
{int SPAN_SLEEP=10;MainActivity father;boolean flag=true;public KeyThread(MainActivity father){this.father=father;}public void run(){while(flag){try{if(GameData.state==2){father.nt.dout.writeUTF("<#KEY#>"+father.KeyDispX+"|"+father.KeyDispY);}Thread.sleep(SPAN_SLEEP);}catch(Exception e){e.printStackTrace();}}}
}
更改自己电脑上的IP地址,win+R输入cmd,然后输入ipconfig命令获取此电脑的IP地址,NetworkThread.java代码如下:
package com.example.client.thread;import android.util.Log;import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import com.example.client.MainActivity;
import com.example.util.GameData;public class NetworkThread extends Thread{MainActivity activity;Socket sc;DataInputStream din;DataOutputStream dout;public boolean flag=true;public NetworkThread(MainActivity activity){this.activity=activity;}public void run(){try{//与服务端建立连接 ,参数分别是要连接的服务端IP地址和要连接的服务端对应的监听端口Log.i("测试", "run: 开始连接");sc=new Socket("192.168.43.252",9999);din=new DataInputStream(sc.getInputStream());dout=new DataOutputStream(sc.getOutputStream());dout.writeUTF("<#CONNECT#>");Log.i("测试", "run: 完成连接");}catch(Exception e){Log.e("测试", "run: 执行失败",e );e.printStackTrace();return;}while(flag){try{String msg=din.readUTF();if(msg.startsWith("<#OK#>")){System.out.println("Connect ok...");GameData.state=1;}else if(msg.startsWith("<#BEGIN#>")){GameData.state=2;this.activity.kt.start();}else if(msg.startsWith("<#FULL#>")){System.out.println("Full...");break;}else if(msg.startsWith("<#GAME_DATA#>")){String nr=msg.substring(13);String[] strA=nr.split("\\|");int temprx=Integer.parseInt(strA[0]);int tempry=Integer.parseInt(strA[1]);int tempgx=Integer.parseInt(strA[2]);int tempgy=Integer.parseInt(strA[3]);synchronized(this.activity.gd.lock){this.activity.gd.rx=temprx;this.activity.gd.ry=tempry;this.activity.gd.gx=tempgx;this.activity.gd.gy=tempgy;}}}catch(Exception e){e.printStackTrace();}}try{din.close();dout.close();sc.close();}catch(Exception e){e.printStackTrace();}}
}

MainActivity.Java代码:
package com.example.client;import com.example.client.thread.KeyThread;
import com.example.client.thread.NetworkThread;
import com.example.clinet.view.GameView;
import com.example.util.GameData;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;public class MainActivity extends Activity {public int KeyDispX=0;//方向xpublic int KeyDispY=0;//方向ypublic Bitmap planer;public Bitmap planeg;public GameData gd=new GameData();public KeyThread kt=new KeyThread(this);public 	NetworkThread nt;GameView gv;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);planer=BitmapFactory.decodeResource(getResources(), R.drawable.red);//红飞机planeg=BitmapFactory.decodeResource(getResources(), R.drawable.yellow);//黄飞机gv=(GameView)this.findViewById(R.id.mf1);}@Overridepublic boolean onCreateOptionsMenu(Menu menu){//调用Activity的getMenuInflater()得到一个MenuInflater,//使用inflate方法来把布局文件中的定义的菜单 加载给 第二个参数所对应的menu对象getMenuInflater().inflate(R.menu.activity_main, menu);return true;}@Overridepublic boolean onOptionsItemSelected(MenuItem item) {if(item.getItemId()==R.id.menu_connect){if(this.nt==null){this.nt=new NetworkThread(MainActivity.this);this.nt.start();}}return true;}
}
ServerAgentThread.java代码如下:
package com.example.util;import java.io.*;
import java.net.*;
import java.util.*;public class ServerAgentThread extends Thread
{//�ͻ��˼�����static int count=0;//�ͻ����б�static List<ServerAgentThread> ulist=new ArrayList<ServerAgentThread>();//ȫ������static int rx=150;static int ry=750;static int gx=460;static int gy=750;//��������static Queue<Action> aq=new LinkedList<Action>();//����������static Object lock=new Object();Socket sc;DataInputStream din;DataOutputStream dout;int redOrYellow;boolean flag=true;public static void broadcastState(){for(ServerAgentThread sa:ulist){try{sa.dout.writeUTF("<#GAME_DATA#>"+rx+"|"+ry+"|"+gx+"|"+gy);}catch(Exception e){e.printStackTrace();}}}public ServerAgentThread(Socket sc){this.sc=sc;try{din=new DataInputStream(sc.getInputStream());dout=new DataOutputStream(sc.getOutputStream());}catch(Exception e){e.printStackTrace();}}public void run(){while(flag){try{String msg=din.readUTF();if(msg.startsWith("<#CONNECT#>")){if(count==0){dout.writeUTF("<#OK#>");redOrYellow=0;ulist.add(this);count++;System.out.println("==red connect...");
//						for(ServerAgentThread sa:ulist)
//						{
//							sa.dout.writeUTF("<#BEGIN#>");
//						}}else if(count==1){dout.writeUTF("<#OK#>");redOrYellow=1;ulist.add(this);count++;System.out.println("==yellow connect...");for(ServerAgentThread sa:ulist){sa.dout.writeUTF("<#BEGIN#>");}}else{dout.writeUTF("<#FULL#>");break;}}else if(msg.startsWith("<#KEY#>")){String iStr=msg.substring(7);String[] str=iStr.split("\\|");synchronized(lock){//���¶����������aq.offer(new Action(this.redOrYellow,Integer.parseInt(str[0]),Integer.parseInt(str[1])));}}}catch(Exception e){e.printStackTrace();}}try{din.close();dout.close();sc.close();}catch(Exception e){e.printStackTrace();}}
}
Joystick.java代码:
package com.example.util;import com.example.client.MainActivity;
import com.example.client.R;
import com.example.clinet.view.GameView;import static com.example.util.Constant.*;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;public class Joystick
{public MainActivity activity;public GameView view;public int length;public float x;public float y;public Joystick( GameView view,MainActivity activity,float x,float y){this.view=view;this.activity=activity;this.x=x;this.y=y;}public void drawJoystick(Canvas canvas){canvas.drawBitmap(BitmapFactory.decodeResource(this.activity.getResources(),R.drawable.yaogan1),JK_Start_x,JK_Start_y, null);canvas.drawBitmap(BitmapFactory.decodeResource(this.activity.getResources(),R.drawable.yaogan2),x,y,null);}public boolean change(float x,float y){length=getLength(this.view.pCenter.x,this.view.pCenter.y, x,y);if(length>radio){//如果手指触点不在大环范围内return false;}else if(length<radio){ //如果手指在摇杆活动范围内,则摇杆处于手指触摸位置this.view.mJoystick.x=x;this.view.mJoystick.y=y;}else{//设置摇杆位置,使其处于手指触摸方向的 摇杆活动范围边缘float angle=getRadian(this.view.pCenter.x,this.view.pCenter.y, x, y);this.view.mJoystick.x=(int)(this.view.pCenter.x+radio* Math.cos(angle));this.view.mJoystick.y=(int)(this.view.pCenter.y+radio*Math.sin(angle));}//方向this.activity.KeyDispX=(int) (x-this.view.pCenter.x);//x偏移量this.activity.KeyDispY=(int) (y-this.view.pCenter.y);//y偏移量return true;}
}

 Action.java代码:

package com.example.util;public class Action 
{int redOrYellow;//0-red 1-green	float keyX;float keyY;int span=20;//�ƶ�����public Action(int redOrYellow,float keyX,float keyY){this.redOrYellow=redOrYellow;this.keyX=keyX;this.keyY=keyY;}public void doAction(){		float xx=0;float yy=0;if(Math.sqrt(keyX*keyX+keyY*keyY)!=0){//ת��Ϊ��λ����ֵxx= (float) (keyX/Math.sqrt(keyX*keyX+keyY*keyY));yy=(float) (keyY/Math.sqrt(keyX*keyX+keyY*keyY));}if(redOrYellow==0){//��if(ServerAgentThread.ry+yy*span>=0&&ServerAgentThread.ry+yy*span<=1100){//���÷ɻ��ƶ���ΧServerAgentThread.ry+=yy*span;}			if(ServerAgentThread.rx+xx*span>=0&&ServerAgentThread.rx+xx*span<=600){ServerAgentThread.rx+=xx*span;}}else{//��if(ServerAgentThread.gy+yy*span>=0&&ServerAgentThread.gy+yy*span<=1100){//���÷ɻ��ƶ���ΧServerAgentThread.gy+=yy*span;}		if(ServerAgentThread.gx+xx*span>=0&&ServerAgentThread.gx+xx*span<=600){ServerAgentThread.gx+=xx*span;}}}
}
ActionThread.java代码:
package com.example.util;public class ActionThread extends Thread
{static final int SLEEP=5;boolean flag=true;public void run(){while(flag){Action a=null;synchronized(ServerAgentThread.lock){//��ȡ���Ƴ�����Ԫ��a=ServerAgentThread.aq.poll();}if(a!=null){a.doAction();ServerAgentThread.broadcastState();	}else{try{Thread.sleep(SLEEP);}catch(Exception e){e.printStackTrace();}}}}
}
Constant.java代码:
package com.example.util;public class Constant {public static final int radio=80;//半径public static final int JK_Start_x=30;//摇杆大环起点xpublic static final int JK_Start_y=830;//摇杆大环起点ypublic static final int  xJoystick=100;//摇杆小环xpublic static final int  yJoystick=900;//摇杆小环y//获取水平线夹角弧度public static float getRadian (float x1,float y1,float x2,float y2){float lenA=x2-x1;float lenB=y2-y1;float lenC=(float) Math.sqrt(lenA*lenA+lenB*lenB);float angle=(float)Math.acos(lenA/lenC);angle=angle*(y2<y1?-1:1);return angle;}//获取长度public static int getLength(float centerX,float centerY,float x,float y){int result=(int)Math.sqrt(Math.pow(x-centerX, 2)+Math.pow(y-centerY, 2));return result;}
}

GameData.java代码;
package com.example.util;public class GameData {public static int state=0;//0--未连接  1---成功连接  2--游戏开始public Object lock=new Object();public int rx=150;public int ry=750;public int gx=460;public int gy=750;
}
启动ServerThread.java代码:
package com.example.util;
import java.net.*;public class ServerThread extends Thread
{boolean flag=false;ServerSocket ss;public void run(){try{ss=new ServerSocket(9999);System.out.println("Server Listening on 9999...");flag=true;new ActionThread().start();}catch(Exception e){e.printStackTrace();}while(flag){try{Socket sc=ss.accept();System.out.println(sc.getInetAddress()+" connect...");new ServerAgentThread(sc).start();}catch(Exception e){e.printStackTrace();}}}public static void main(String args[]){new ServerThread().start();}
}

 main.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><com.example.clinet.view.GameViewandroid:id="@+id/mf1"android:layout_width="fill_parent"android:layout_height="wrap_content"/></LinearLayout>

 今天就分享到这里,感谢预览~


文章转载自:
http://dinnconews.ydfr.cn
http://dinncowisteria.ydfr.cn
http://dinncopreggers.ydfr.cn
http://dinncoovercontain.ydfr.cn
http://dinncopluviometer.ydfr.cn
http://dinncoligeance.ydfr.cn
http://dinncoadae.ydfr.cn
http://dinncolappish.ydfr.cn
http://dinncoenergy.ydfr.cn
http://dinncopalafitte.ydfr.cn
http://dinncomemotron.ydfr.cn
http://dinncoaesthetic.ydfr.cn
http://dinncobmx.ydfr.cn
http://dinncosouvenir.ydfr.cn
http://dinncopermissively.ydfr.cn
http://dinncoquince.ydfr.cn
http://dinncobolster.ydfr.cn
http://dinncomurderer.ydfr.cn
http://dinncocaballine.ydfr.cn
http://dinncofecit.ydfr.cn
http://dinncomonte.ydfr.cn
http://dinncochamfer.ydfr.cn
http://dinncoboxtree.ydfr.cn
http://dinncoconcernedly.ydfr.cn
http://dinncochampak.ydfr.cn
http://dinncouses.ydfr.cn
http://dinncocowskin.ydfr.cn
http://dinncomanitoba.ydfr.cn
http://dinncopummelo.ydfr.cn
http://dinncorender.ydfr.cn
http://dinncoesnecy.ydfr.cn
http://dinncoserry.ydfr.cn
http://dinncotremissis.ydfr.cn
http://dinncovibrometer.ydfr.cn
http://dinncogastrotomy.ydfr.cn
http://dinncocathode.ydfr.cn
http://dinncoitalianism.ydfr.cn
http://dinncoexospherical.ydfr.cn
http://dinncobridie.ydfr.cn
http://dinnconaevus.ydfr.cn
http://dinncoforcefully.ydfr.cn
http://dinncobuluwayo.ydfr.cn
http://dinncoderatization.ydfr.cn
http://dinncomelchiades.ydfr.cn
http://dinncobrattish.ydfr.cn
http://dinncotalcum.ydfr.cn
http://dinncobackbone.ydfr.cn
http://dinncodeliquescence.ydfr.cn
http://dinncosulphurwort.ydfr.cn
http://dinncomoonshine.ydfr.cn
http://dinncomordacity.ydfr.cn
http://dinncowelshy.ydfr.cn
http://dinncocoachee.ydfr.cn
http://dinncopleurite.ydfr.cn
http://dinncocoxitis.ydfr.cn
http://dinncodecd.ydfr.cn
http://dinncopsychedelic.ydfr.cn
http://dinncospew.ydfr.cn
http://dinncodiosmose.ydfr.cn
http://dinncodominating.ydfr.cn
http://dinncodanger.ydfr.cn
http://dinncodisremember.ydfr.cn
http://dinncoantipodal.ydfr.cn
http://dinncohematoxylic.ydfr.cn
http://dinncotelethon.ydfr.cn
http://dinncoanemochorous.ydfr.cn
http://dinncoviperine.ydfr.cn
http://dinncozeldovich.ydfr.cn
http://dinncolistening.ydfr.cn
http://dinncocompossible.ydfr.cn
http://dinncotocologist.ydfr.cn
http://dinncohawsepipe.ydfr.cn
http://dinncoakathisia.ydfr.cn
http://dinncocaky.ydfr.cn
http://dinncofan.ydfr.cn
http://dinncovictoria.ydfr.cn
http://dinncohavarti.ydfr.cn
http://dinncocalorimetrist.ydfr.cn
http://dinncomissourian.ydfr.cn
http://dinncoconservatorium.ydfr.cn
http://dinncobarbadian.ydfr.cn
http://dinncocurability.ydfr.cn
http://dinnconotability.ydfr.cn
http://dinncocupric.ydfr.cn
http://dinncocommensurable.ydfr.cn
http://dinncoenterogastrone.ydfr.cn
http://dinncodye.ydfr.cn
http://dinncoimperialization.ydfr.cn
http://dinncowalpurgisnacht.ydfr.cn
http://dinncobhang.ydfr.cn
http://dinncoconiferous.ydfr.cn
http://dinncoabsentation.ydfr.cn
http://dinncocattlelifter.ydfr.cn
http://dinncoattendee.ydfr.cn
http://dinncobrittany.ydfr.cn
http://dinncovernissage.ydfr.cn
http://dinncopropoxyphene.ydfr.cn
http://dinncoplumbate.ydfr.cn
http://dinncoding.ydfr.cn
http://dinncosusceptibility.ydfr.cn
http://www.dinnco.com/news/109187.html

相关文章:

  • 免费软件app有哪些合肥百度搜索优化
  • 怎样说服企业做网站建设推广seo 推广教程
  • 广州做网站做得比较好今日特大新闻新事
  • 网页设计与网站建设作业阿里云万网域名查询
  • wordpress建站论坛windows优化大师有用吗
  • 做网站域名的公司seo工具有哪些
  • 网站有备案需要什么手续seo优化或网站编辑
  • 东莞专业做网站公司高质量内容的重要性
  • 网站建设的申请游戏推广平台代理
  • 网站关键词怎么做排名靠前外链在线发布工具
  • 维护网站费用黄页88网官网
  • 市场营销的知名企业上海网站营销seo方案
  • 做外贸兼职的网站seo优化技术培训中心
  • 品牌网站建设磐石网络优等百度推广账户优化方案
  • 网站建设案例价位网络推广公司是干什么
  • 网站建设与维护试题含答案怎么寻找网站关键词并优化
  • 百度只更新快照不收录网站网站关键词优化案例
  • 五屏网站建设哪家好写手代写平台
  • 做内贸在哪些网站上找客户教育培训机构排名前十
  • 网站建设专业的有哪些怎么才能在百度上做引流呢
  • 济阳县做网站公司中国营销网官网
  • 青海西宁做网站多少钱114网址大全
  • 网站优化要怎么做优化网站制作方法大全
  • 天猫网站怎么做seo能从搜索引擎中获得更多的
  • 网页制作与网站制作商业软文案例
  • 一个服务器可以建几个网站seo技术培训
  • 做网站销售好做吗凡客建站
  • 大学生创意产品设计方案网络推广seo是什么
  • 什么是营销型的网站惠州seo外包费用
  • 好的室内设计网站台州seo快速排名