Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#170 #1 #88 #89 #90 #91 #95 Lab1~9 重交。 #1006

Merged
merged 1 commit into from
Jun 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.hzu.xu.planewar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Com1314080901140 extends Activity {
private TextView mTextView;
private Button Button0;
private Button Button1;
private boolean mChanged = false;
//final Data dd=(Data) getApplication();
public int Count;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//设置窗口没有标题
setContentView(R.layout.com1314080901140activity_main);
mTextView = (TextView)findViewById(R.id.show_textview);
Button1=(Button)findViewById(R.id.button1);
Button0=(Button)findViewById(R.id.button0);


//read the mChanged is true or false
readLoadFile();
refreTextView();
initButton();
}
public void Btn1OnClick(View view){
Intent intent = new Intent();
intent.setClass(Com1314080901140.this, GameActivity.class);
startActivity(intent);
}
private void initButton()
{
Button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0) {
readLoadFile();
mChanged = true;
refreTextView();
Count=Count+2;
saveFileStorage();
}
});
}
public void refreTextView()
{
mTextView.setText("当前分数为:"+Count+"!");
}

private void readLoadFile()
{
//make the Properties

Properties properties = new Properties();

try{
FileInputStream istream = this.openFileInput("dmfile.cfg");
properties.load(istream);
}
catch(FileNotFoundException e){
return;
}
catch(IOException e){
return;
}
mChanged = Boolean.valueOf(properties.getProperty("mChanging").toString());
Count = Integer.valueOf(properties.getProperty("mButton").toString());
}

private boolean saveFileStorage()
{
Properties properties = new Properties();
properties.put("mChanging", String.valueOf(mChanged));
properties.put("mButton", String.valueOf(Count));
try{
FileOutputStream ostream = this.openFileOutput("dmfile.cfg", Context.MODE_WORLD_WRITEABLE);
properties.store(ostream, "");
}
catch(FileNotFoundException e)
{
return false;
}
catch(IOException e)
{
return false;
}
return true;
}

}




Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.hzu.xu.planewar;

import java.io.InputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

public class XuBulletHero {
// ------------ 子弹
Bitmap img_bullet;
String img_bullet_name = "bullet-3.png";;
int bullet_speed;
int bullet_x, bullet_y, bullet_w, bullet_h;

public int bullet_statu;
public static final int BULLET_MOVE = 0X0001;
public static final int BULLET_DIE = 0X0002;

// ----------- 爆炸
Bitmap img_boom;
int boom_x, boom_y, boom_w, boom_h, boom_col, boom_row;
public int boom_statu;
public static final int BOOM_POWER = 0X0001;
public static final int BOOM_DIE = 0X0002;


public BulletHero() {

}

public void setImgBulletName(String name){
this.img_bullet_name = name;
}

public void Bullet_Init() {
InputStream is = this.getImgStream(img_bullet_name);
Bitmap temp = BitmapFactory.decodeStream(is);
img_bullet = GameUtils.ZomeBitamp(temp, GameUtils.IMG_ENLARGE,
GameUtils.IMG_ENLARGE);
bullet_w = img_bullet.getWidth();
bullet_h = img_bullet.getHeight();
bullet_x = -MainGame.Screen_w;
bullet_y = -MainGame.Screen_h;
bullet_statu = BULLET_DIE;
bullet_speed = 12;
this.Boom_Init();
}

public void Deal_Bullet() {
this.Bullet_Move();
this.Deal_Boom();
}

public void Draw_Bullet(Canvas canvas) {
if (this.bullet_statu == BULLET_MOVE) {
GameUtils.Brush(canvas, img_bullet, bullet_x, bullet_y, bullet_w,
bullet_h, 0, 0);
} else if (this.bullet_statu == BULLET_DIE) {
bullet_x = -MainGame.Screen_w;
bullet_y = -MainGame.Screen_h;
}
this.Draw_Boom(canvas);
}

public void Bullet_Move() {
if (this.bullet_y + this.bullet_h > 0) {
bullet_y -= this.bullet_speed;
} else {
this.bullet_statu = BULLET_DIE;
}
}

public void Update_Bullet_Local(int x, int y) {
this.bullet_x = x;
this.bullet_y = y;
this.bullet_statu = BULLET_MOVE;
}

// ----------- 爆炸
public void Boom_Init(){
InputStream is = this.getImgStream("smallplanebom_.png");
Bitmap temp = BitmapFactory.decodeStream(is);
img_boom = GameUtils.ZomeBitamp(temp, GameUtils.IMG_ENLARGE,
GameUtils.IMG_ENLARGE);
boom_w = img_boom.getWidth();
boom_h = img_boom.getHeight()/9;
boom_x = -MainGame.Screen_w;
boom_y = -MainGame.Screen_h;
boom_col = 0;
boom_row = 0;
boom_statu = BOOM_DIE;
}

public void Deal_Boom(){
if(boom_statu == BOOM_POWER){
if(boom_row <9){
boom_row ++;
}else{
boom_row = 0;
boom_x = -MainGame.Screen_w;
boom_y = -MainGame.Screen_h;
boom_statu = BOOM_DIE;
}
}
}

public void Draw_Boom(Canvas canvas){
GameUtils.Brush(canvas, img_boom, boom_x, boom_y, boom_w, boom_h, boom_col, boom_row);
}

public InputStream getImgStream(String name){
return this.getClass().getResourceAsStream(
GameUtils.IMG_PATH+name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.hzu.xu.planewar;

import java.io.InputStream;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

public class XuBulletNpc {
// ------------ 子弹
Bitmap img_bullet;
String img_bullet_name = "bullet-7.png";;
int bullet_speed;
int bullet_x, bullet_y, bullet_w, bullet_h;

public int bullet_statu;
public static final int BULLET_MOVE = 0X0001;
public static final int BULLET_DIE = 0X0002;

// ----------- 爆炸
Bitmap img_boom;
int boom_x, boom_y, boom_w, boom_h, boom_col, boom_row;
public int boom_statu;
public static final int BOOM_POWER = 0X0001;
public static final int BOOM_DIE = 0X0002;


public BulletNpc() {

}

public void setImgBulletName(String name){
this.img_bullet_name = name;
}

public void Bullet_Init() {
InputStream is = this.getImgStream(img_bullet_name);
Bitmap temp = BitmapFactory.decodeStream(is);
img_bullet = GameUtils.ZomeBitamp(temp, GameUtils.IMG_ENLARGE,
GameUtils.IMG_ENLARGE);
bullet_w = img_bullet.getWidth();
bullet_h = img_bullet.getHeight();
bullet_x = -MainGame.Screen_w;
bullet_y = -MainGame.Screen_h;
bullet_statu = BULLET_DIE;
bullet_speed = 5;
this.Boom_Init();
}

public void Deal_Bullet() {
this.Bullet_Move();
this.Deal_Boom();
}

public void Draw_Bullet(Canvas canvas) {
if (this.bullet_statu == BULLET_MOVE) {
GameUtils.Brush(canvas, img_bullet, bullet_x, bullet_y, bullet_w,
bullet_h, 0, 0);
} else if (this.bullet_statu == BULLET_DIE) {
bullet_x = -MainGame.Screen_w;
bullet_y = -MainGame.Screen_h;
}
this.Draw_Boom(canvas);
}

public void Bullet_Move() {
if (this.bullet_y < MainGame.Screen_h) {
bullet_y += this.bullet_speed;
} else {
this.bullet_statu = BULLET_DIE;
}
}

public void Update_Bullet_Local(int x, int y) {
this.bullet_x = x;
this.bullet_y = y;
this.bullet_statu = BULLET_MOVE;
}

// ----------- 爆炸
public void Boom_Init(){
InputStream is = this.getImgStream("smallplanebom_.png");
Bitmap temp = BitmapFactory.decodeStream(is);
img_boom = GameUtils.ZomeBitamp(temp, GameUtils.IMG_ENLARGE,
GameUtils.IMG_ENLARGE);
boom_w = img_boom.getWidth();
boom_h = img_boom.getHeight()/9;
boom_x = -MainGame.Screen_w;
boom_y = -MainGame.Screen_h;
boom_col = 0;
boom_row = 0;
boom_statu = BOOM_DIE;
}

public void Deal_Boom(){
if(boom_statu == BOOM_POWER){
if(boom_row <9){
boom_row ++;
}else{
boom_row = 0;
boom_x = -MainGame.Screen_w;
boom_y = -MainGame.Screen_h;
boom_statu = BOOM_DIE;
}
}
}

public void Draw_Boom(Canvas canvas){
GameUtils.Brush(canvas, img_boom, boom_x, boom_y, boom_w, boom_h, boom_col, boom_row);
}

public InputStream getImgStream(String name){
return this.getClass().getResourceAsStream(
GameUtils.IMG_PATH+name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.hzu.xu.planewar;

import android.app.Application;

public class XuData extends Application{
public int b;



public int getNumber() {
return b;
}

public void setNumber(int number) {
this.b = number;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hzu.xu.planewar;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;

public class XuGameActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
requestWindowFeature(Window.FEATURE_NO_TITLE);//设置窗口没有标题
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏显示
Init();
}

public void Init(){
WindowManager wm = this.getWindowManager();
Display display = wm.getDefaultDisplay();
MainGame gameView = new MainGame(this, display);
gameView.setBackgroundColor(Color.BLACK);
this.setContentView(gameView);
}
}
Loading