package wyf.ytl;
import static wyf.ytl.ConstantUtil.CITY_INFO;
import static wyf.ytl.ConstantUtil.DICE_SIZE;
import static wyf.ytl.ConstantUtil.DICE_SPAN;
import static wyf.ytl.ConstantUtil.DICE_START_X;
import static wyf.ytl.ConstantUtil.DICE_START_Y;
import static wyf.ytl.ConstantUtil.DIGIT_SPAN;
import static wyf.ytl.ConstantUtil.GAME_VIEW_SCREEN_COLS;
import static wyf.ytl.ConstantUtil.GAME_VIEW_SCREEN_ROWS;
import static wyf.ytl.ConstantUtil.HERO_ANIMATION_FRAMES;
import static wyf.ytl.ConstantUtil.HERO_ANIMATION_SEGMENTS;
import static wyf.ytl.ConstantUtil.HERO_ARMY_DRAW_X;
import static wyf.ytl.ConstantUtil.HERO_ARMY_DRAW_Y;
import static wyf.ytl.ConstantUtil.HERO_FACE_HEIGHT;
import static wyf.ytl.ConstantUtil.HERO_FACE_START_Y;
import static wyf.ytl.ConstantUtil.HERO_FACE_WIDTH;
import static wyf.ytl.ConstantUtil.HERO_FOOD_DRAW_X;
import static wyf.ytl.ConstantUtil.HERO_FOOD_DRAW_Y;
import static wyf.ytl.ConstantUtil.HERO_HEIGHT;
import static wyf.ytl.ConstantUtil.HERO_MONEY_DRAW_X;
import static wyf.ytl.ConstantUtil.HERO_MONEY_DRAW_Y;
import static wyf.ytl.ConstantUtil.HERO_STRENGTH_DRAW_X;
import static wyf.ytl.ConstantUtil.HERO_STRENGTH_DRAW_Y;
import static wyf.ytl.ConstantUtil.HERO_WIDTH;
import static wyf.ytl.ConstantUtil.HUI_TOU_SHI_AN;
import static wyf.ytl.ConstantUtil.MAP_BUTTON_SIZE;
import static wyf.ytl.ConstantUtil.MAP_BUTTON_START_X;
import static wyf.ytl.ConstantUtil.MAP_BUTTON_START_Y;
import static wyf.ytl.ConstantUtil.MAP_COLS;
import static wyf.ytl.ConstantUtil.MAP_ROWS;
import static wyf.ytl.ConstantUtil.MINI_MAP_SPAN;
import static wyf.ytl.ConstantUtil.MINI_MAP_START_X;
import static wyf.ytl.ConstantUtil.RIGHT;
import static wyf.ytl.ConstantUtil.TILE_SIZE;
import static wyf.ytl.ConstantUtil.WU_ZHONG_SHENG_YOU;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
/**
*
* 该类为游戏的主界面
*
*/
public class GameView extends SurfaceView implements SurfaceHolder.Callback,View.OnTouchListener {
private int status = 0;//绘制时的状态,0正常游戏,1,英雄在走动,2,主菜单出现,3,选择将军出战,4,战斗动画
//5,穷死结束游戏,6,统一中国
//100-人物属性界面,99-武将情报 98-使用计谋 97-城池管理 96-天下局势
HDZGActivity activity;//activity的引用
DrawThread drawThread;//刷帧的线程
Hero hero;//英雄对象
static Bitmap dialogBack;//存放对话框背景
static Bitmap dialogButton;//存放对话框按钮
static Bitmap [][] heroAnimationSegments;//存放英雄所有动画段的图片
static Bitmap [] bmpDice;//存放骰子的图片数组
static Bitmap dashboardBitmap;//下面用于管理的图片
static Bitmap darkBitmap;//黑色外框的效果图
static Bitmap[] smallGameMenuOptions = new Bitmap[6];//装主菜单分割以后的图片
static Bitmap[] bmpDigit;//存放数码管数字的图片
static Bitmap bmpBattleFiled;//战场背景图片
static Bitmap[] bmpHero;//存放英雄的图片,分为静态和动态,代表英雄静止还是走路
int [][] notInMatrix=new int[MAP_ROWS][MAP_COLS];//存放整个大地图的不可通过矩阵
int miniMapStartX = MINI_MAP_START_X; //初始情况下缩略地图开始的X坐标
int miniMapStartY = -160; //初始情况下缩略地图开始的Y坐标
boolean showMiniMap;//是否显示迷你地图
int startRow = 0;//屏幕在大地图中的行数
int startCol = 0;//屏幕在大地图中的列数
int offsetX = 0;//屏幕定位点在大地图上的x方向偏移,用来实现无级滚屏
int offsetY = 0;//屏幕定位点在大地图上的y方向偏移,用来实现无级滚屏
LayerList layerList;//所有的层
MyMeetableDrawable [][] meetableMatrix;//存放大地图的可遇矩阵
MyMeetableDrawable currentDrawable;//记录当前碰到的可遇Drawable对象引用
MyMeetableDrawable previousDrawable;//记录上一个碰到的可遇Drawable对象引用
MeetableLayer meetableChecker;//
GameViewThread gvt;//后台修改数据的线程
BattleField battleField;
int suiXinBu=0;//记录英雄施放随心步时选择的步数
General fightingGeneral = null;//存放当前出战的将军
ArrayList<Skill> skillToLearn;//将要学习的技能
int diceCount=2;//起作用的骰子的个数,学习了骑术会增加,最大到三
int []diceValue = {1,3,5};//存放骰子的值,其实是骰子图片数组的下标,0-5代表1-6的骰子图片
int currentSteps;//记录本次掷骰子需要走几步
ManPanelView manPanelView;//人物属性窗口
WuJiangView wuJiangView;//武将情报窗口
UseSkillView useSkillView;//使用计谋窗口
CityManageView cityManageView;//城池管理窗口
SelectGeneral selectGeneral;//选中出征武将窗口
TianXiaView tianXiaView;//天下局势窗口
GameAlert currentGameAlert;//记录当前的消息提示
ArrayList<CityDrawable> allCityDrawable = new ArrayList<CityDrawable>();//存放所有敌方的城池
ArrayList<General> freeGeneral;//自由的将领,即不属于我方和敌方的
Paint paint;//画笔
public static Resources resources; //声明资源对象引用
MediaPlayer mMediaPlayer;
SoundPool soundPool;//声音
HashMap<Integer, Integer> soundPoolMap;
//构造器
public GameView(HDZGActivity activity) {
super(activity);
resources = this.getResources();
if(activity.loadingView != null){//走进度条
activity.loadingView.process += 30;
}
this.activity = activity;//activity的引用
initSounds();
mMediaPlayer = MediaPlayer.create(activity, R.raw.backsound);
mMediaPlayer.setLooping(true);
if(activity.loadingView != null){//走进度条
activity.loadingView.process += 30;
}
paint = new Paint();
paint.setColor(Color.RED);
if(activity.loadingView != null){//走进度条
activity.loadingView.process += 30;
}
getHolder().addCallback(this);
this.drawThread = new DrawThread(getHolder(), this);//初始化刷帧线程
this.gvt = new GameViewThread(this);//初始化后台数据修改线程
this.battleField = new BattleField(this);
hero = new Hero(this, 3, 3);//创建英雄
hero.initAnimationSegment(heroAnimationSegments);//为英雄初始化动画段列表
hero.setAnimationDirection(RIGHT%4);//初始化英雄朝向右,静态右
hero.startAnimation();//启动英雄动画
initMap();//初始化地图
initClass();//初始化所有用到的类
if(activity.isBackSound){
mMediaPlayer.start();
}
if(activity.loadingView != null){//走进度条
activity.loadingView.process += 40;
}
}
public void initSounds(){
soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(getContext(), R.raw.dingdong, 1));
soundPoolMap.put(2, soundPool.load(getContext(), R.raw.battle, 1));
}
public void playSound(int sound, int loop) {
AudioManager mgr = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
soundPool.play(soundPoolMap.get(sound), volume, volume, 1, loop, 1f);
}
//初始化所有用到的类
public void initClass(){
manPanelView = new ManPanelView(this);
wuJiangView = new WuJiangView(this);
useSkillView = new UseSkillView(this);
cityManageView = new CityManageView(this);
selectGeneral = new SelectGeneral(this);
tianXiaView = new TianXiaView(this);
}
//方法:初始化地图
public void initMap(){
layerList = new LayerList(getResources());
this.notInMatrix = layerList.getTotalNotIn();//得到总不可通过矩阵
this.meetableChecker = (MeetableL
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
HDZG.rar_android_android 游戏_android 游戏_game (240个子文件)
resources.ap_ 708KB
HDZG.apk 779KB
GameView.class 18KB
Hero.class 13KB
CityDrawable.class 12KB
WuJiangView.class 11KB
CityManageView.class 8KB
ConstantUtil.class 7KB
ManPanelView.class 7KB
GameData2.class 6KB
MenuView.class 6KB
SerializableGame.class 6KB
UseSkillView.class 5KB
HeroGoThread.class 5KB
HeroBackDataThread.class 5KB
SunZiDrawable.class 5KB
MoZiDrawable.class 5KB
LuBanDrawable.class 5KB
MaChangDrawable.class 5KB
TianXiaView.class 5KB
ZhanXianGuanDrawable.class 5KB
TieJangPuDrawable.class 5KB
XueTangDrawable.class 5KB
SelectGeneral.class 5KB
WarAlert.class 5KB
SoundManageView.class 5KB
WuGuanDrawable.class 5KB
VillageDrawable.class 5KB
ForestDrawable.class 4KB
FishingDrawable.class 4KB
MineDrawable.class 4KB
ScreenRollView.class 4KB
WheatDrawable.class 4KB
RiceDrawable.class 4KB
YiZhanDrawable.class 4KB
PalaceDrawable.class 4KB
BattleField.class 4KB
LoadingView.class 3KB
HelpView.class 3KB
MyMeetableDrawable.class 3KB
AboutView.class 3KB
General.class 3KB
HDZGActivity.class 3KB
HDZGActivity$1.class 3KB
FoodAlert.class 3KB
SoundView.class 3KB
GameOverAlert.class 3KB
R$drawable.class 3KB
GameFormula.class 2KB
GameData.class 2KB
PlainAlert.class 2KB
MyDrawable.class 2KB
WuZhongShengYouSkill.class 2KB
Skill.class 2KB
MeetableLayer.class 2KB
TreeDrawable.class 2KB
GameView$DrawThread.class 2KB
GameAlert.class 2KB
LoadingView$DrawThread.class 2KB
MenuView$DrawThread.class 2KB
Research.class 2KB
CityInfo.class 2KB
SoundManageView$DrawThread.class 1KB
ScreenRollThread.class 1KB
LayerList.class 1KB
HelpView$DrawThread.class 1KB
GameViewThread.class 1KB
ScreenRollView$DrawThread.class 1KB
FishingSkill.class 1KB
MiningSkill.class 1KB
LumberSkill.class 1KB
FarmingSkill.class 1KB
Layer.class 1KB
SuiXinBuSkill.class 1KB
BattleField$BattleThread.class 1KB
HDZGActivity$1$3.class 1KB
MenuViewBackgroundThread.class 1KB
HuiTouShiAnSkill.class 1KB
SoundView$1.class 932B
Hero$HeroThread.class 907B
HDZGActivity$1$2.class 861B
HDZGActivity$1$1.class 861B
R.class 456B
R$raw.class 453B
R$string.class 394B
R$layout.class 361B
R$attr.class 307B
.classpath 280B
classes.dex 152KB
GameView.java 28KB
WuJiangView.java 17KB
CityDrawable.java 14KB
Hero.java 13KB
ConstantUtil.java 12KB
CityManageView.java 11KB
MenuView.java 11KB
GameData2.java 11KB
HeroGoThread.java 10KB
ManPanelView.java 7KB
HDZGActivity.java 7KB
共 240 条
- 1
- 2
- 3
资源评论
局外狗
- 粉丝: 64
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功