forked from hzuapps/android-labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…apps#95 Lab1~9 重交。 Lab1~9 重交。之前代码冲突。期末统计那里没我的学号。
Showing
22 changed files
with
1,045 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/Com1314080901140.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
116 changes: 116 additions & 0 deletions
116
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/XuBulletHero.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/XuBulletNpc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/XuData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901140/XuGameActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.