安卓手机游戏源代码(手游平台程序源码)
admin 发布:2022-12-19 16:12 233
今天给各位分享安卓手机游戏源代码的知识,其中也会对手游平台程序源码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
求一个安卓开发小游戏源代码,临时交作业用
package com.fiveChess;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
GameView gameView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Display display = this.getWindowManager().getDefaultDisplay();
gameView = new GameView(this,display.getWidth(),display.getHeight());
setContentView(gameView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("重新开始").setIcon(android.R.drawable.ic_menu_myplaces);
menu.add("退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getTitle().equals("重新开始")){
gameView.canPlay = true;
gameView.chess = new int[gameView.row][gameView.col];
gameView.invalidate();
}else if(item.getTitle().equals("退出")){
finish();
}
return super.onOptionsItemSelected(item);
}
}
package com.fiveChess;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
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);
this.context = context;
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.message = "黑棋先行";
row = (screenHeight-50)/stepLength+1;
col = (screenWidth-10)/stepLength+1;
chess = new int[row][col];
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, screenWidth, screenHeight, paint);//画背景
paint.setColor(Color.BLUE);
paint.setTextSize(25);
canvas.drawText(message, (screenWidth-100)/2, 30, paint);//画最顶层的字
paint.setColor(Color.BLACK);
//画棋盘
for(int i=0;irow;i++){
canvas.drawLine(10, 50+i*stepLength, 10+(col-1)*stepLength, 50+i*stepLength, paint);
}
for(int i=0;icol;i++){
canvas.drawLine(10+i*stepLength,50,10+i*stepLength,50+(row-1)*stepLength, paint);
}
for(int r=0;rrow;r++){
for(int c=0;ccol;c++){
if(chess[r][c] == 1){
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}else if(chess[r][c] == 2){
//画白棋
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(!canPlay){return false;}
float x = event.getX();
float y = event.getY();
int r = Math.round((y-50)/stepLength);
int c = Math.round((x-10)/stepLength);
if(r0 || rrow-1 || c0 || ccol-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 super.onTouchEvent(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 rrow c=0 ccol r+x=0 r+xrow c+y=0 c+ycol chess[r][c] == chess[r+x][c+y]){
count++;
if(y0){
c++;
}else if(y0){
c--;
}
if(x0){
r++;
}else if(x0){
r--;
}
}
while(a=0 arow b=0 bcol a-x=0 a-xrow b-y=0 b-ycol chess[a][b] == chess[a-x][b-y]){
count++;
if(y0){
b--;
}else if(y0){
b++;
}
if(x0){
a--;
}else if(x0){
a++;
}
}
if(count=5){
String str = "";
if(isBlack){
str = "白棋胜利";
}else{
str = "黑棋胜利";
}
new AlertDialog.Builder(context).setTitle("游戏结束").setMessage(str).setPositiveButton("重新开始", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
chess = new int[row][col];
invalidate();
}
}).setNegativeButton("观看棋局", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
canPlay = false;
}
}).show();
return true;
}
return false;
}
}
PS:五子棋,无需图片,直接在程序里画出来的。注意我发的是两个文件,一个activity,一个类文件,别把它当成一个文件了
安卓手机游戏中的代码如何获得?
您好
获取游戏源代码需要对APK进行反编译,如果APK已经加密,无法通过反编译的方法获取源代码
目前反编译的软件有很多,您可以在腾讯电脑管家中下载,推荐使用【改之理】,一款非常好用的反编译软件,傻瓜式操作,适合新手,您百度也能搜索到
希望可以帮到您,望采纳
腾讯电脑管家企业平台:
哪位大神有android的贪吃蛇游戏设计源代码
转载 Snake工程中,总共有三个文件: *TileView是基于Android的View类实现的方块图类,用来支撑上层类的调用,绘制方块图的显示界面。通过这些代码,能打之了解如何 扩展View,实现特色的界面效果。 *SnakeView调用了TileView,实现了游戏逻辑 和 具体的显示。 *Snake为主Activity类。
建议大家按照上面的顺序看三个文件,可能逻辑上更舒服一点~~
下面贴上代码和注释。
PS: 调试版本为android2.2。 其他版本应该也没问题吧,不过得用虚拟机。因为它是上下左右按键操作,现在大多数android机是没有方向键的吧。
TileView.java
package com.example.android.snake;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
/**
* TileView: a View-variant designed for handling arrays of "icons" or other
* drawables.
*
*/
public class TileView extends View {
/**
* Parameters controlling the size of the tiles and their range within view.
* Width/Height are in pixels, and Drawables will be scaled to fit to these
* dimensions. X/Y Tile Counts are the number of tiles that will be drawn.
*/
protected static int mTileSize; //每个tile的边长的像素数量
protected static int mXTileCount; //屏幕内能容纳的 X方向上方块的总数量
protected static int mYTileCount;//屏幕内能容纳的 Y方向上方块的总数量
private static int mXOffset; //原点坐标,按pixel计。
private static int mYOffset;
/**
* A hash that maps integer handles specified by the subclasser to the
* drawable that will be used for that reference
* 存储着不同种类的bitmap图。通过resetTiles,loadTile,将游戏中的方块加载到这个数组。
* 可以理解为 砖块字典
*/
private Bitmap[] mTileArray;
/**
* A two-dimensional array of integers in which the number represents the
* index of the tile that should be drawn at that locations
* 存储整个界面内每个tile位置应该绘制的tile。
* 可看作是我们直接操作的画布。
* 通过setTile、clearTile 进行图形显示的修改操作。
*
*/
private int[][] mTileGrid;
//画笔,canvas的图形绘制,需要画笔Paint实现。
private final Paint mPaint = new Paint();
public TileView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
//使用TypedArray,获取在attrs.xml中为TileView定义的新属性tileSize 。参考:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
mTileSize = a.getInt(R.styleable.TileView_tileSize, 12);
a.recycle();
}
public TileView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
mTileSize = a.getInt(R.styleable.TileView_tileSize, 12);
a.recycle();
}
/**
* Rests the internal array of Bitmaps used for drawing tiles, and
* sets the maximum index of tiles to be inserted
* 重置清零mTileArray,在游戏初始的时候使用。
* 即清空砖块字典
* @param tilecount
*/
public void resetTiles(int tilecount) {
mTileArray = new Bitmap[tilecount];
}
/*
* 当改变屏幕大小尺寸时,同时修改tile的相关计数指标。
*/
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
mXTileCount = (int) Math.floor(w / mTileSize);
mYTileCount = (int) Math.floor(h / mTileSize);
//mXOffset mYOffset是绘图的起点坐标。
mXOffset = ((w - (mTileSize * mXTileCount)) / 2);
mYOffset = ((h - (mTileSize * mYTileCount)) / 2);
mTileGrid = new int[mXTileCount][mYTileCount];
clearTiles();
}
/**
* Function to set the specified Drawable as the tile for a particular
* integer key.
* 加载具体的砖块图片 到 砖块字典。
* 即将对应的砖块的图片 对应的加载到 mTileArray数组中
* @param key
* @param tile
*/
public void loadTile(int key, Drawable tile) {
//这里做了一个 Drawable 到 bitmap 的转换。由于外部程序使用的时候是直接读取资源文件中的图片,
//是drawable格式,而我们的数组是bitmap格式,方便最终的绘制。所以,需要进行一次到 bitmap的转换。
Bitmap bitmap = Bitmap.createBitmap(mTileSize, mTileSize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
tile.setBounds(0, 0, mTileSize, mTileSize);
tile.draw(canvas);
mTileArray[key] = bitmap;
}
如何查看手机游戏的源代码
你好,首先要有X管理器然后Mobile C(编程),用X打开游戏内部,然后复制出来,再用C打开。这种方式仅限于C语言基础,若想完全弄懂可以上论坛看专帖,谢谢
腾讯电脑管家企业平台:
安卓手机游戏源代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于手游平台程序源码、安卓手机游戏源代码的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-17百度合作平台,百度合作平台如何赚钱
- 05-17整站优化seo平台,seo整站优化网首页,整站优化网论坛,整站网外包seo
- 05-17广告软文营销平台,广告软文营销平台怎么做
- 05-16无锡网络推广平台,无锡网站建设无锡网站推广
- 05-16媒介星软文平台,媒介星软文平台联系
- 05-16厦门seo培训,厦门seo外包平台
- 05-16网络推广优化平台,网络推广优化平台有哪些
- 05-16平台推广引流怎么做,平台引流推广犯法吗
- 05-15微信推广平台,微信推广平台收费标准
- 05-15免费开发软件制作平台,软件免费开发网站
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接