当前位置:首页 » 游戏种类 » 安卓游戏源代码

安卓游戏源代码

发布时间: 2023-03-13 19:25:40

Ⅰ 求一个安卓开发小游戏源代码,临时交作业用

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;i<row;i++){
canvas.drawLine(10, 50+i*stepLength, 10+(col-1)*stepLength, 50+i*stepLength, paint);
}
for(int i=0;i<col;i++){
canvas.drawLine(10+i*stepLength,50,10+i*stepLength,50+(row-1)*stepLength, paint);
}

for(int r=0;r<row;r++){
for(int c=0;c<col;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(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 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 && 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 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,一个类文件,别把它当成一个文件了

Ⅱ 游戏源代码是什么

源代码(也称源程序),是指一系列人类可读的计算机语言指令。游戏源代码简单来说就是游戏最原始程序的代码。

Ⅲ 游戏软件怎么查看源代码

源代码是看不成的,因为游戏软件打包好做成app的话,是没法看源码的,虽然存在一些特殊情况下,我们可以推测出exe程序是用什么程序写的。但是多数情况下,我们是无法只根据一个exe程序就判断出来的。

根据exe程序我们是无法直接得到程序的源码的。虽然也有一些用于逆向工程的办法,但那不可能把已经是exe的程序反回到它原始的源码情况。而且这些工具都很难用。你可以用“反编译”搜到很多工具,但是说实话,即便是这方面的专家,要看懂反编译以后的程序也不是一件轻松的事情。

Ⅳ 安卓手机游戏中的代码如何获得

这里将向彩民朋友介绍1些竞彩足球游戏的简单投注技能。 1、首先比较两队的本 5、注意分别哪些是“豪情球队”和“危机球队”。夺冠热门球队、卫冕

Ⅳ 所有的安卓软件源代码都一样吗

这个肯定是不一样的呢,每一个软件都有自己的唯一代码的。
然后你手机上的软件最好是在应用宝里面搜索下载呢
应用宝里面的资源是最齐全的,有软件游戏等资源,应有尽有呢。
然后它上面的软件自己都是经过系统的审核,都是正式版本的软件
不会自己出现什么不兼容或者冲突的问题,下载很简单
在手机上打开应用宝软件搜索你所需要的软件或者游戏,找到下载就可以安装了。
也可以通过手机连接电脑端的应用宝软件来下载的,打开PC端的应用宝软件——手机应用。
可以通过搜索或者看软件或许游戏的分类来进行下载呢,都是很方便的。还望采纳

Ⅵ 游戏软件怎么查看源代码

游戏都是进行过编译,加密的无法看到源代码。如果你想查看的游戏是开源的,可以到游戏的开源网站进行查看。

查看APP应用的源代码的具体方法步骤如下:

1、首先在电脑内下载并安装获取网页源码app。

2、然后单击打开网页源码APP并在APP中的输入框内输入想要查看的网址,再在界面内找到GO选项单并单击。

3、单击后等待APP最后加载3秒就可以成功的获取APP源代码并查看了。

Android 系统源代码多大

是指sdk的源码,还是android操作系统的源码,不过都有10G左右,另外sdk的源码是用git管理的,一次下载后,用git check就可以切换到各个版本。

Android SDK是用于开发Android上JAVA应用程序的,另外发布Android NDK,可以添加一些C语言写的链接库,至于Linux代码,可以在Android源代码中找到(SDK程序中只有编译好的测试映像)。

应用程序开发用不到Linux代码(搞嵌入式开发才会用到,而SDK不负责底层开发)。

Ⅶ 手机游戏源代码是什么,怎么使用

不知道你玩的啥游戏,但是看样子估计是c++代码,我英文学的不好
从英文描述中我猜测这是v c++的代码,“//”在代码中表示注释,前三行是注释,其大意如下:
stdafx.cpp :源文件,包括刚才的标准单元?
fixyou.pch将是预编译的标题
stdafx.obj将包含预编译的类型信息
“cpp”明显是c++源码文件的缩写名,而最后一行是头文件。
所谓头文件预编译,就是把一个工程(Project)中使用的一些MFC标准头文件(如Windows.H、Afxwin.H)预先编译,以后该工程编译时,不再编译这部分头文件,仅仅使用预编译的结果。这样快编译速度,节省时间。

预编译头文件通过编译stdafx.cpp生成,以工程名命名,由于预编译的头文件的后缀是“pch”,所以编译结果文件是projectname.pch。

编译器通过一个头文件stdafx.h来使用预编译头文件。stdafx.h这个头文件名是可以在project的编译设置里指定的。编译器认为,所有在指令#include "stdafx.h"前的代码都是预编译的,它跳过#include "stdafx. h"指令,使用projectname.pch编译这条指令之后的所有代码。

因此,所有的CPP实现文件第一条语句都是:#include "stdafx.h"。
其实我学的pascal,所以对c++了解的少,如果你真的想学会他,还是自己找几本c++的书学一下,这样才能“使用”代码得心应手。

热点内容
绝地求生未来之役比赛为什么进不去 发布:2023-08-31 22:07:08 浏览:1353
dota2位置什么意思 发布:2023-08-31 22:00:04 浏览:793
lol电竞是什么样子 发布:2023-08-31 21:58:40 浏览:1250
绝地求生八倍镜的那个圆圈怎么弄 发布:2023-08-31 21:58:31 浏览:1324
lol龙龟一个多少金币 发布:2023-08-31 21:55:07 浏览:700
王者如何改游戏内名称 发布:2023-08-31 21:55:06 浏览:990
游戏主播打广告是什么意思 发布:2023-08-31 21:55:06 浏览:1668
绝地求生如何免费拿到ss7赛季手册 发布:2023-08-31 21:52:13 浏览:872
pgg是哪个国家的战队lol 发布:2023-08-31 21:52:07 浏览:746
一个人的时候才发现游戏很没意思 发布:2023-08-31 21:49:24 浏览:1373