package wyf.ytl;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GameView extends SurfaceView implements SurfaceHolder.Callback{
KLSDActivity activity;//activity的引用
int alpha = 100;//透明度
float span = (float) 1;//难度(1-10)
int status = 0 ; //0游戏中,1暂停中, 2游戏胜利, 3游戏失败
int time=0;//时间
boolean tishi;//是否提示
Bitmap background;//大背景
Bitmap small_backgroud;//背景方格
Bitmap stop;//暂停按钮
Bitmap change;//换题按钮
Bitmap drop;//放弃按钮
Bitmap help;//提示按钮
Bitmap go_on;//暂停图像
Bitmap keyDown;//选中后单元格样式
Bitmap win;//胜利
Bitmap fail;//失败
Bitmap select;//选中的单元格
Bitmap timeBitmap;//时间中间的冒号
Bitmap heart;//有提示时候画的
Bitmap exit;//是否退出图片
Bitmap key_background;//数字按键背景
Bitmap key_bitmap;//小数字键盘
Bitmap[] number_bitmap = new Bitmap[10];//默认的数字图片
Bitmap[] number_input = new Bitmap[10];//输入的数字图片
Bitmap[] time_bitmap = new Bitmap[10];//时间
Paint paint;
boolean drawkey = false;
int[][] num;//用来装生成的数字即正确答案
int[][] inputNum;//用来存放输入的数字
int[][] outputNum;//用来存放系统的数字
float scale = (float) 0.8;//数字键盘上数字缩放的比例
Bitmap[] small_number;
int r = 39;//数字键盘小圆圈的半径
int keyx;
int keyy;//数字键盘的位置
int downx;
int downy;
ShuDuSuanFa sdsf;//生成数独的算法类
TimeThread tt;//时间线程
GameViewDrawThread gameViewDrawThread;
public GameView(KLSDActivity activity) {
super(activity);
this.activity = activity;
getHolder().addCallback(this);//添加Callback接口的实现
init();
gameViewDrawThread = new GameViewDrawThread(this);
}
public void init(){
paint = new Paint();//初始化画笔
background = BitmapFactory.decodeResource(getResources(), R.drawable.background);
//初始化背景小方格图元
small_backgroud= BitmapFactory.decodeResource(getResources(), R.drawable.small_background);
//初始化下面的四个按钮
stop = BitmapFactory.decodeResource(getResources(), R.drawable.stop1);//停止
change = BitmapFactory.decodeResource(getResources(), R.drawable.change1);//换题
drop = BitmapFactory.decodeResource(getResources(), R.drawable.drop1);//放弃
help = BitmapFactory.decodeResource(getResources(), R.drawable.help1);//提示
key_background = BitmapFactory.decodeResource(getResources(), R.drawable.key_background);
number_bitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.b0);
number_bitmap[1] = BitmapFactory.decodeResource(getResources(), R.drawable.b1);
number_bitmap[2] = BitmapFactory.decodeResource(getResources(), R.drawable.b2);
number_bitmap[3] = BitmapFactory.decodeResource(getResources(), R.drawable.b3);
number_bitmap[4] = BitmapFactory.decodeResource(getResources(), R.drawable.b4);
number_bitmap[5] = BitmapFactory.decodeResource(getResources(), R.drawable.b5);
number_bitmap[6] = BitmapFactory.decodeResource(getResources(), R.drawable.b6);
number_bitmap[7] = BitmapFactory.decodeResource(getResources(), R.drawable.b7);
number_bitmap[8] = BitmapFactory.decodeResource(getResources(), R.drawable.b8);
number_bitmap[9] = BitmapFactory.decodeResource(getResources(), R.drawable.b9);
number_input[0] = BitmapFactory.decodeResource(getResources(), R.drawable.a0);
number_input[1] = BitmapFactory.decodeResource(getResources(), R.drawable.a1);
number_input[2] = BitmapFactory.decodeResource(getResources(), R.drawable.a2);
number_input[3] = BitmapFactory.decodeResource(getResources(), R.drawable.a3);
number_input[4] = BitmapFactory.decodeResource(getResources(), R.drawable.a4);
number_input[5] = BitmapFactory.decodeResource(getResources(), R.drawable.a5);
number_input[6] = BitmapFactory.decodeResource(getResources(), R.drawable.a6);
number_input[7] = BitmapFactory.decodeResource(getResources(), R.drawable.a7);
number_input[8] = BitmapFactory.decodeResource(getResources(), R.drawable.a8);
number_input[9] = BitmapFactory.decodeResource(getResources(), R.drawable.a9);
go_on = BitmapFactory.decodeResource(getResources(), R.drawable.go_on);
keyDown = BitmapFactory.decodeResource(getResources(), R.drawable.c0);
win = BitmapFactory.decodeResource(getResources(), R.drawable.win);//胜利
fail = BitmapFactory.decodeResource(getResources(), R.drawable.fail);//失败界面
select = BitmapFactory.decodeResource(getResources(), R.drawable.select);//选择
heart = BitmapFactory.decodeResource(getResources(), R.drawable.heart);//提示的红心
//时间的图片
Matrix matrix = new Matrix();
matrix.postScale((float)1.5, (float)1.5);//缩放
timeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.time);
Bitmap temp0 = BitmapFactory.decodeResource(getResources(), R.drawable.time0);
time_bitmap[0] = Bitmap.createBitmap(temp0, 0, 0, temp0.getWidth(), temp0.getHeight(), matrix, true);
for(int i=1; i<=9; i++){//循环
time_bitmap[i] = Bitmap.createBitmap(number_input[i], 0, 0, number_input[i].getWidth(), number_input[i].getHeight(), matrix, true);
}
//初始化数字键盘的图片
Matrix matrix2 = new Matrix(); //创建Matrix
matrix2.postScale(scale, scale);
small_number = new Bitmap[10];//初始化图片数组
for(int i=0; i<number_bitmap.length; i++){
small_number[i] = Bitmap.createBitmap(number_input[i], 0, 0, number_input[i].getWidth(), number_input[i].getHeight(), matrix2, true);
}
exit = BitmapFactory.decodeResource(getResources(), R.drawable.exit);//退出图片
init2();//调用其他初始化方法
}
private void init2(){
//生成数独
sdsf = new ShuDuSuanFa();
num = sdsf.getShuDu();
//初始化用于存放输入数字的数组
inputNum = new int[9][9];
for(int i=0;i<inputNum.length; i++){
for(int j=0; j<inputNum[i].length; j++){
inputNum[i][j] = 0;
}
}
outputNum = new int[9][9];
for(int i=0;i<num.length; i++){
for(int j=0; j<num[i].length; j++){
if(10*Math.random()>span){
outputNum[i][j] = num[i][j];
}else {
outputNum[i][j] = 0;
}
}
}
//启动时间线程
tt = new TimeThread(this);
tt.start();
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.BLACK);
//画背景图片
canvas.drawBitmap(background, 0, 0, paint);
//画背景小 方格
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
canvas.drawBitmap(small_backgroud, 5+104*j, 25+104*i, paint);
}
}
//画下面的四个按钮
canvas.drawBitmap(stop, 150,380, paint);
canvas.drawBitmap(change, 230,380, paint);
canvas.drawBitmap(drop, 150,420, paint);
canvas.drawBitmap(help, 230,420, paint);
if(status == 2){//游戏胜利
tt.flag = false;
canvas.drawBitmap(win, 40, 160, paint);
}else if(status == 3){//游戏失败
tt.flag = false;
canvas.drawBitmap(fail, 80, 180, paint);
}else if(status == 4){//是否退出
canvas.drawBitmap(exit, 70, 180, paint);
}else if(status == 0){//游戏中
if(tishi == true){
canvas.drawBitmap(heart, 10, 340, paint);
}
//画全部数字
tt.flag = true;
int x;
int y;
for(int i = 0;i < 9;i++){
for(int j = 0;j < 9;j++){
x = 16+28*j;
y = 35+29*i;
if(j>=3&&j<6){
x += 20;
}
if(j>=6){
x += 42;
}
if(i>=3&&i<6){
y += 18;
}
if(i>=6){
y += 34;
}
canvas.drawBitmap(number_bitmap[outputNum[i][j]], x, y, paint);
}
}
//画用户输入的数字
for(int i = 0;i < 9;i++){
for(int j = 0;j < 9;j++){
没有合适的资源?快使用搜索试试~ 我知道了~
Android小游戏数独游戏_安卓源码.zip
共119个文件
png:47个
gif:30个
class:17个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 6 浏览量
2021-09-05
19:06:45
上传
评论 2
收藏 5.01MB ZIP 举报
温馨提示
Android应用源码之数独游戏源码
资源推荐
资源详情
资源评论
收起资源包目录
Android小游戏数独游戏_安卓源码.zip (119个子文件)
resources.ap_ 1.6MB
KLSD.apk 1.61MB
GameView.class 11KB
WelcomeView.class 5KB
HelpView.class 3KB
AboutView.class 3KB
R$drawable.class 2KB
ShuDuSuanFa.class 2KB
DrawKeyThread.class 2KB
KLSDActivity.class 2KB
WelcomeViewDrawThread.class 1KB
GameViewDrawThread.class 1KB
KLSDActivity$1.class 1KB
WelcomeViewGoThread.class 1KB
TimeThread.class 736B
R.class 423B
R$string.class 394B
R$layout.class 361B
R$attr.class 307B
.classpath 280B
Thumbs.db 151KB
classes.dex 22KB
w9.gif 30KB
w13.gif 30KB
w10.gif 29KB
w8.gif 29KB
w12.gif 28KB
w14.gif 28KB
w11.gif 28KB
w7.gif 27KB
w6.gif 27KB
w5.gif 27KB
w15.gif 26KB
w16.gif 26KB
w17.gif 25KB
w4.gif 24KB
w19.gif 24KB
w22.gif 24KB
w18.gif 23KB
w27.gif 23KB
w23.gif 23KB
w21.gif 23KB
w29.gif 23KB
w28.gif 23KB
w30.gif 23KB
w24.gif 23KB
w25.gif 23KB
w20.gif 23KB
w26.gif 23KB
w3.gif 22KB
w2.gif 21KB
w1.gif 16KB
GameView.java 15KB
WelcomeView.java 4KB
R.java 4KB
ShuDuSuanFa.java 3KB
KLSDActivity.java 2KB
HelpView.java 2KB
AboutView.java 2KB
WelcomeViewDrawThread.java 1KB
GameViewDrawThread.java 1KB
DrawKeyThread.java 1KB
WelcomeViewGoThread.java 865B
TimeThread.java 452B
数独游戏示例图片3.jpg 39KB
数独游戏示例图片2.jpg 19KB
数独游戏示例图片1.jpg 13KB
about.png 293KB
help.png 285KB
background.png 195KB
key_background.png 22KB
menu.png 16KB
win.png 14KB
stop1.png 7KB
icon.png 7KB
change1.png 5KB
change2.png 4KB
fail.png 4KB
drop1.png 4KB
help1.png 4KB
stop2.png 4KB
drop2.png 4KB
heart.png 4KB
help2.png 4KB
icon.png 4KB
go_on.png 4KB
b8.png 3KB
b9.png 3KB
b3.png 3KB
b5.png 3KB
b6.png 3KB
a8.png 3KB
a2.png 3KB
a9.png 3KB
a5.png 3KB
a3.png 3KB
a6.png 3KB
b4.png 3KB
b7.png 3KB
a4.png 3KB
共 119 条
- 1
- 2
资源评论
- xifffff2022-05-31用户下载后在一定时间内未进行评价,系统默认好评。
罗漫
- 粉丝: 19
- 资源: 202
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2001~2022年上市公司数字赋能指数.dta
- 2001~2022年上市公司数字赋能指数.xlsx
- 信息办公石大在线财务管理系统(含源码)-shidacaiwu.rar
- 信息办公电信计费系统完整代码-netctossconformity.rar
- matlab实现TD-SCDMA中初始同步捕捉DwPTS下行同步导频时隙的仿真.zip
- 信息办公玉玺学生信息管理系统-webapps.rar
- 信息办公基于struts的图书管理系统-struts-ts.rar
- 管家婆分销ERP V1 V3 A8II TOP V10.0.2最新全版本通用
- 信息办公基于Ajax+J2EE的MicroERP源码下载-microerp-0.1.rar
- 信息办公双鱼林jsp人事工资系统-wagesmanagesystem.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功