安卓如何实现获取网页源代码

安卓如何实现获取网页源代码,第1张

public class GetHtmlCodeActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

superonCreate(savedInstanceState);

setContentView(Rlayoutmain);

TextView textView = (TextView)thisfindViewById(Ridpicture_textview);

try {

textViewsetText(getPictureData(">

你好,要读懂安卓游戏源代码,必须懂得Java语言以及相关的类库,所以,入手的话建议:

1、找一本Java语言通用教材学习

2、然后学习Java类库,安卓游戏主要用到J2ME

掌握这两个就可以读懂源码了,但是需要时间!

有其他问题欢迎到电脑管家企业平台咨询,我们将竭诚为您服务!

腾讯电脑管家企业平台:>

package comfiveChess;

import androidappActivity;

import androidosBundle;

import androidviewDisplay;

import androidviewMenu;

import androidviewMenuItem;

import androidviewWindow;

import androidviewWindowManager;

public class MainActivity extends Activity {

GameView gameView = null;

@Override

public void onCreate(Bundle savedInstanceState) {

superonCreate(savedInstanceState);

thisgetWindow()requestFeature(WindowFEATURE_NO_TITLE);

thisgetWindow()setFlags(WindowManagerLayoutParamsFLAG_FULLSCREEN,WindowManagerLayoutParamsFLAG_FULLSCREEN);

Display display = thisgetWindowManager()getDefaultDisplay();

gameView = new GameView(this,displaygetWidth(),displaygetHeight());

setContentView(gameView);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

menuadd("重新开始")setIcon(androidRdrawableic_menu_myplaces);

menuadd("退出");

return superonCreateOptionsMenu(menu);

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

if(itemgetTitle()equals("重新开始")){

gameViewcanPlay = true;

gameViewchess = new int[gameViewrow][gameViewcol];

gameViewinvalidate();

}else if(itemgetTitle()equals("退出")){

finish();

}

return superonOptionsItemSelected(item);

}

}

package comfiveChess;

import androidappAlertDialog;

import androidcontentContext;

import androidcontentDialogInterface;

import androidgraphicsCanvas;

import androidgraphicsColor;

import androidgraphicsPaint;

import androidgraphicsPaintStyle;

import androidviewMotionEvent;

import androidviewView;

public class GameView extends View {

Context context = null;

int screenWidth,screenHeight;

String message = "";//提示轮到哪个玩家

int row,col; //划线的行数和列数

int stepLength = 30;//棋盘每格间距

int[][] chess = null;//0代表没有棋子,1代表是黑棋,2代表白旗

boolean isBlack = true;

boolean canPlay = true;

public GameView(Context context,int screenWidth,int screenHeight) {

super(context);

thiscontext = context;

thisscreenWidth = screenWidth;

thisscreenHeight = screenHeight;

thismessage = "黑棋先行";

row = (screenHeight-50)/stepLength+1;

col = (screenWidth-10)/stepLength+1;

chess = new int[row][col];

}

@Override

protected void onDraw(Canvas canvas) {

superonDraw(canvas);

Paint paint = new Paint();

paintsetColor(ColorWHITE);

canvasdrawRect(0, 0, screenWidth, screenHeight, paint);//画背景

paintsetColor(ColorBLUE);

paintsetTextSize(25);

canvasdrawText(message, (screenWidth-100)/2, 30, paint);//画最顶层的字

paintsetColor(ColorBLACK);

//画棋盘

for(int i=0;i<row;i++){

canvasdrawLine(10, 50+istepLength, 10+(col-1)stepLength, 50+istepLength, paint);

}

for(int i=0;i<col;i++){

canvasdrawLine(10+istepLength,50,10+istepLength,50+(row-1)stepLength, paint);

}

for(int r=0;r<row;r++){

for(int c=0;c<col;c++){

if(chess[r][c] == 1){

paintsetColor(ColorBLACK);

paintsetStyle(StyleFILL);

canvasdrawCircle(10+cstepLength, 50+rstepLength, 10, paint);

}else if(chess[r][c] == 2){

//画白棋

paintsetColor(ColorWHITE);

paintsetStyle(StyleFILL);

canvasdrawCircle(10+cstepLength, 50+rstepLength, 10, paint);

paintsetColor(ColorBLACK);

paintsetStyle(StyleSTROKE);

canvasdrawCircle(10+cstepLength, 50+rstepLength, 10, paint);

}

}

}

}

@Override

public boolean onTouchEvent(MotionEvent event) {

if(!canPlay){return false;}

float x = eventgetX();

float y = eventgetY();

int r = Mathround((y-50)/stepLength);

int c = Mathround((x-10)/stepLength);

if(r<0 || r>row-1 || c<0 || c>col-1){return false;}

if(chess[r][c]!=0){return false;}//若有棋子则不再画棋子了

if(isBlack){

chess[r][c] = 1;

isBlack = false;

message = "轮到白棋";

}else{

chess[r][c] = 2;

isBlack = true;

message = "轮到黑棋";

}

invalidate();

if(judge(r, c,0,1)) return false;

if(judge(r, c,1,0)) return false ;

if(judge(r, c,1,1)) return false;

if(judge(r, c,1,-1)) return false;

return superonTouchEvent(event);

}

private boolean judge(int r, int c,int x,int y) {//r,c表示行和列,x表示在y方向上的偏移,y表示在x方向上的偏移

int count = 1;

int a = r;

int b = c;

while(r>=0 && r<row && c>=0 && c<col && r+x>=0 && r+x<row && c+y>=0 && c+y<col && chess[r][c] == chess[r+x][c+y]){

count++;

if(y>0){

c++;

}else if(y<0){

c--;

}

if(x>0){

r++;

}else if(x<0){

r--;

}

}

while(a>=0 && a<row && b>=0 && b<col && a-x>=0 && a-x<row && b-y>=0 && b-y<col && chess[a][b] == chess[a-x][b-y]){

count++;

if(y>0){

b--;

}else if(y<0){

b++;

}

if(x>0){

a--;

}else if(x<0){

a++;

}

}

if(count>=5){

String str = "";

if(isBlack){

str = "白棋胜利";

}else{

str = "黑棋胜利";

}

new AlertDialogBuilder(context)setTitle("游戏结束")setMessage(str)setPositiveButton("重新开始", new DialogInterfaceOnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

chess = new int[row][col];

invalidate();

}

})setNegativeButton("观看棋局", new DialogInterfaceOnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

canPlay = false;

}

})show();

return true;

}

return false;

}

}

PS:五子棋,无需,直接在程序里画出来的。注意我发的是两个文件,一个activity,一个类文件,别把它当成一个文件了

以上就是关于安卓如何实现获取网页源代码全部的内容,包括:安卓如何实现获取网页源代码、怎样获得一个游戏的源程序文件、想要看懂一个安卓游戏的源码该从哪里开始看,从哪里入手等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/10154553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存