package com.gameview;
public class GameData{
private int stage;
private int life;
private int score;
public GameData(int stage,int life,int score){
this.stage = stage;
this.life = life;
this.score = score;
}
public int getLife(){
return this.life;
}
public int getStage(){
return this.stage;
}
public int getScore(){
return this.score;
}
}
package com.gameview;
import java.util.Iterator;
import java.util.Map.Entry;
import xieyan.DataInterface;
import xieyan.Direction;
import xieyan.Point;
import xieyan.unit.Debris;
import xieyan.unit.Enemy;
import xieyan.unit.MyBoat;
import xieyan.unit.Obstacle;
import xieyan.unit.Unit;
import com.data.Data;
import com.testshipboat.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;
@SuppressLint("DrawAllocation")
public class GameOne extends View {
private int width,height;
//手机的屏目缩放大小
private int phone_width_suo;
private int phone_height_suo;
private int gap_width;
private int gap_height;
private int a,b,c,d,k;
private int phone_x_off,phone_y_off;
private int game_start_x,game_start_y;
public GameOne(Context context){
super(context);
}
public void setWidth(int width){
this.width = width;
}
public void setHeight(int height){
this.height = height;
}
//行,列
private int[] getXYPosition(int arrow,int column){
int a[] = new int[2];
a[1] = width/Data.stage_1_arrow*(arrow-1);
a[0] = height/Data.stage_1_arrow*(column-1);
return a;
}
//计算各种数据
public void calcuate(int gapWidth,int gapHeight,int x_off,int y_off){
k = (width*height)*(Data.game_two_width*Data.game_two_height)/(Data.stage_size*Data.stage_1_arrow)/(Data.stage_size*Data.stage_1_arrow);
//游戏一区的宽
a = k*Data.game_two_width/(Data.game_two_height+Data.game_two_width);
//游戏一区的高
b = k*Data.game_two_height/(Data.game_two_width+Data.game_two_height);
phone_width_suo = (int)a;
phone_height_suo = (int)b;
gap_width = width-phone_width_suo;
gap_height = height-phone_height_suo;
c = gap_width*x_off/gapWidth;
d = gap_height*y_off/gapHeight;
phone_x_off = (int)c;
phone_y_off = (int)d;
game_start_x = (gap_width)/2+phone_x_off;
game_start_y = (gap_height)/2+phone_y_off;
invalidate();
}
public GameOne(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
//画出我的位置敌人的位置还有障碍物
private void drawTuOne(Canvas canvas){
Paint paint = new Paint();
DataInterface data=new DataInterface();
Iterator<Entry<Point, Unit>> iter =
data.getUnitRegistry().entrySet().iterator();
//int widthOne = width/Data.stage_1_arrow;
//int heightOne = height/Data.stage_1_arrow;
while (iter.hasNext()) {
Entry<Point, Unit> entry = (Entry<Point, Unit>) iter.next();
Point point = entry.getKey();
Unit u = entry.getValue();
if(u instanceof MyBoat){
paint.setColor(Color.BLUE);
int a[] = getXYPosition(point.getRow(), point.getColumn());
canvas.drawRect(a[0], a[1], a[0]+15, a[1]+15, paint);
}else if(u instanceof Enemy){
paint.setColor(Color.RED);
int a[] = getXYPosition(point.getRow(), point.getColumn());
canvas.drawRect(a[0], a[1], a[0]+15, a[1]+15, paint);
}else if(u instanceof Obstacle){
paint.setColor(Color.YELLOW);
int a[] = getXYPosition(point.getRow(), point.getColumn());
canvas.drawRect(a[0], a[1], a[0]+15, a[1]+15, paint);
}else if(u instanceof Debris){
paint.setColor(Color.BLACK);
int a[] = getXYPosition(point.getRow(), point.getColumn());
canvas.drawRect(a[0], a[1], a[0]+15, a[1]+15, paint);
}
}
}
private void drawTu(Canvas canvas){
Paint paint = new Paint();
paint.setStyle(Style.STROKE);
paint.setColor(Color.RED);
canvas.drawRect(game_start_x, game_start_y, game_start_x+phone_width_suo, game_start_y+phone_height_suo, paint);
}
protected void onDraw(Canvas canvas){
drawTuOne(canvas);
drawTu(canvas);
}
@Override
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
{
//这里面是原始的大小,需要重新计算可以修改本行
setMeasuredDimension(width,height);
}
}
|
|