北京电子科技学院(BESTI)

实验报告

课程:

Java程序设计

班级:

1352

姓名:

池彬宁

学号:

20135212

成绩:

指导教师:

娄嘉鹏

实验日期:

2015.6.3

实验密级:

预习程度:

实验时间:

15:20-18:00

仪器组次:

必修/选修:

选修

实验序号:

(三)

实验名称:

敏捷开发与XP实践

实验目的与要求:

1. XP基础

2. XP核心实践

3. 相关工具

 

 

 

 

 

 

 

 

 

实验仪器:

 

名称

型号

数量

PC

SONY

1

                     

一、敏捷开发与XP

二、编码标准

1.编码标准中的版式就是一个很好的例子,版式虽然不会影响程序的功能,但会影响可读性。程序的版式追求清晰、美观,是程序风格的重要因素。单击Eclipse菜单中的source->Format 或用快捷键Ctrl+Shift+F就可以按Eclipse规定的规范缩进。

2. 代码标准中很重要的一项是如何给包、类、变量、方法等标识符命名,能很好的命名可以让自己的代码立马上升一个档次。Java中的一般的命名规则有:

  • 要体现各自的含义
  • 包、类、变量用名词
  • 方法名用动宾
  • 包名全部小写,如:io,awt
  • 类名第一个字母要大写,如:HelloWorldApp
  • 变量名第一个字母要小写,如:userName
  • 方法名第一个字母要小写:setName

三、重构

重构(Refactor),就是在不改变软件外部行为的基础上,改变软件内部的结构,使其更加易于阅读、易于维护和易于变更 。

未重构前的代码中Function1与Function2的功能并未明显的体现出来,且无文字说明,对代码的使用与修改造成了不便。

重构之后的代码:

重构后的代码功能清晰明了,利于后期的开发与利用。

别踩白块:

齐岳:负责代码的实现(一)

blogs:http://www.cnblogs.com/July0207/

codes:

package com.orange.block;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle; import com.orange.engine.camera.ZoomCamera;
import com.orange.engine.options.PixelPerfectEngineOptions;
import com.orange.engine.options.PixelPerfectMode;
import com.orange.engine.options.ScreenOrientation;
import com.orange.res.FontRes;
import com.orange.res.RegionRes;
import com.orange.ui.activity.GameActivity;
import com.orange.block.res.Res;
import com.orange.block.scene.GameScene;
import com.orange.block.util.ConstantUtil;
import com.orange.block.util.LogUtil; /**
* 入口主Activity 类
* @author lch<OGEngine@orangegame.cn>
* @
*/
public class MainActivity extends GameActivity {
@Override
protected void onCreate(Bundle pSavedInstanceState) {
super.onCreate(pSavedInstanceState); } @Override
protected PixelPerfectEngineOptions onCreatePixelPerfectEngineOptions() {
PixelPerfectEngineOptions pixelPerfectEngineOptions = new PixelPerfectEngineOptions(
this, ZoomCamera.class);
pixelPerfectEngineOptions
.setScreenOrientation(ScreenOrientation.PORTRAIT_FIXED); // 设置竖屏
pixelPerfectEngineOptions
.setPixelPerfectMode(PixelPerfectMode.CHANGE_HEIGHT);// 适配模式,这里设置为“保持宽度不变,改变高”
pixelPerfectEngineOptions.setDesiredSize(ConstantUtil.DESIRED_SIZE);// 参考尺寸 return pixelPerfectEngineOptions;
} @Override
protected void onLoadResources() {
// 加载相关初始的资源等
LogUtil.d("开始加载资源...");
RegionRes.loadTexturesFromAssets(Res.ALL_XML);
FontRes.loadFont(128, 128,
Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 40, true,
Color.RED, ConstantUtil.FONT_NAME_TIMER); FontRes.loadFont(256, 512,
Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 50, true,
Color.BLACK, ConstantUtil.FONT_NAME_RESULT); } @Override
protected void onLoadComplete() {
// 加载资源完成后
LogUtil.d("加载资源完成...");
this.startScene(GameScene.class);// 启动游戏场景
} @Override
protected void onPause() {
super.onPause();
this.getEngine().stop();
} @Override
protected synchronized void onResume() {
super.onResume();
this.getEngine().start();
} @Override
protected void onDestroy() {
super.onDestroy(); android.os.Process.killProcess(android.os.Process.myPid());
}
}

  

package com.orange.block.util;

public class ConstantUtil {

	/**屏幕参考尺寸**/
public static final float DESIRED_SIZE = 480; /**标示白颜色**/
public static final int COLOR_WHITE = 0;
/**标示黑颜色**/
public static final int COLOR_BLACK = 1; /**游戏进行状态**/
public static final int GAME_START = 1;
/**游戏结束状态**/
public static final int GAME_OVER = 2; /** 游戏总共有多少行 **/
public static final int LINES_LEN = 50; /**字体颜色的 key**/
public static final String FONT_NAME_TIMER = "timer";
public static final String FONT_NAME_RESULT = "result";
}

  

package com.orange.block.util;

import android.util.Log;

/**
*
* @author lch
*
*/
public class LogUtil {
private static boolean showLogEnabled = true;
private static final String TAG = "OG"; public static void out(String msg) {
if (showLogEnabled)
System.out.println(msg);
} public static void d(String msg) {
if (showLogEnabled)
Log.d(TAG, msg);
} public static void i(String msg) {
if (showLogEnabled)
Log.i(TAG, msg);
} public static void v(String msg) {
if (showLogEnabled)
Log.v(TAG, msg);
} public static void w(String msg) {
if (showLogEnabled)
Log.w(TAG, msg);
} public static void e(String msg) {
if (showLogEnabled)
Log.e(TAG, msg);
} }

  

package com.orange.block.util;

import android.content.Context;
import android.content.SharedPreferences.Editor; /**
* 保存到 SharedPreferences 的数据
*
* @author lch
*
*/
public class SharedUtil { private static final String SHARED_OG = "Shared_og"; private static final String RESULT_RECORD = "result_record"; /**
* 保持最新的记录
* @param pContext
* @param pMillisPass
*/
public static void setRecord(Context pContext, long pMillisPass) {
Editor edit = pContext.getSharedPreferences(SHARED_OG,
Context.MODE_PRIVATE).edit();
edit.putLong(RESULT_RECORD, pMillisPass);
edit.commit();
} /**
* 获取记录
* @param context
* @return
*/
public static long getRecord(Context context) {
return context
.getSharedPreferences(SHARED_OG, Context.MODE_PRIVATE)
.getLong(RESULT_RECORD, 0);
} }

  

package com.orange.block.scene;

import java.util.ArrayList;
import java.util.List;
import java.util.Random; import android.view.KeyEvent; import com.orange.content.SceneBundle;
import com.orange.entity.IEntity;
import com.orange.entity.modifier.ColorModifier;
import com.orange.entity.modifier.DelayModifier;
import com.orange.entity.modifier.IEntityModifier.IEntityModifierListener;
import com.orange.entity.modifier.LoopEntityModifier;
import com.orange.entity.modifier.MoveYModifier;
import com.orange.entity.modifier.ScaleModifier;
import com.orange.entity.modifier.SequenceEntityModifier;
import com.orange.entity.primitive.DrawMode;
import com.orange.entity.primitive.Mesh;
import com.orange.entity.scene.Scene;
import com.orange.entity.sprite.AnimatedSprite;
import com.orange.entity.text.Text;
import com.orange.res.FontRes;
import com.orange.util.color.Color;
import com.orange.util.modifier.IModifier;
import com.orange.block.control.TimerTool;
import com.orange.block.entity.Block;
import com.orange.block.entity.FailGroup;
import com.orange.block.entity.SuccGroup;
import com.orange.block.res.Res;
import com.orange.block.util.ConstantUtil;
import com.orange.block.util.LogUtil; /**
* 游戏场景
*
* @author lch
*
*/
public class GameScene extends Scene {
/** 块的宽 **/
private float blockWidth = 0;
/** 块的高 **/
private float blockHight = 0;
/** 用于装当前所有生成但未被删除的block **/
private List<Block[]> blockList;
/** 当前生成的块的行数 **/
private int linesLength = 5;
/** 游戏状态 **/
private int gameStatus = ConstantUtil.GAME_START;
/** 移动步数 **/
private int moveNum = 0;
/** 成功界面 **/
private SuccGroup mSuccGroup;
/** 失败界面 **/
private FailGroup mFailGroup;
/** 计时管理类 **/
private TimerTool mTimerTool; /** 显示计时的Text **/
private Text timerText; /**游戏提示语**/
private AnimatedSprite game_tip; // 用于Z索引排序
private static final int pZIndex_middle = 2;
private static final int pZIndex_top = 3; public Text getTimerText() {
return timerText;
} public TimerTool getmTimerTool() {
return mTimerTool;
} @Override
public void onSceneCreate(SceneBundle bundle) {
super.onSceneCreate(bundle);
// 镜头里显示的是4*4的块,所以用镜头宽的四分之一作为块宽
blockWidth = this.getCameraWidth() / 4;
blockHight = this.getCameraHeight() / 4; this.blockList = new ArrayList<Block[]>();
mTimerTool = new TimerTool(this);
initView();
} private void initView() {
// 初始化blocks
initBlocks(); timerText = new Text(getCameraCenterX(), 10,
FontRes.getFont(ConstantUtil.FONT_NAME_TIMER), "00.000\"",
"00:00.000\"".length(), getVertexBufferObjectManager());
this.attachChild(timerText);
timerText.setCentrePositionX(getCameraCenterX());
timerText.setZIndex(pZIndex_top); mSuccGroup = new SuccGroup(getCameraWidth(), getCameraHeight(), this);
mSuccGroup.setZIndex(pZIndex_middle);
mSuccGroup.setVisible(false);
this.attachChild(mSuccGroup); mFailGroup = new FailGroup(getCameraWidth(), getCameraHeight(), this);
this.attachChild(mFailGroup);
mFailGroup.setZIndex(pZIndex_middle); game_tip = new AnimatedSprite(0, 0, Res.GAME_TIP, getVertexBufferObjectManager());
game_tip.setCentrePositionX(this.getCameraCenterX());
game_tip.setBottomPositionY(this.getCameraBottomY()-60);
this.attachChild(game_tip);
game_tip.setZIndex(pZIndex_top); } /**
* 初始化blocks
*/
private void initBlocks() {
Random mRandom = new Random(); int blackIndex = 0;
// 初始blocks,先创建4*5表格,使用时候再一行行增加
for (int row = 0; row < linesLength; row++) {// 行
// 一行blocks
Block[] rowBolcks = new Block[4];
// 随机一个黑块所在位置
blackIndex = mRandom.nextInt(4);
for (int column = 0; column < 4; column++) {// 列
rowBolcks[column] = new Block(this, row, column, blockWidth,
blockHight, blackIndex, getVertexBufferObjectManager());
this.attachChild(rowBolcks[column]);
}
blockList.add(rowBolcks);
}
} /**
* 重来时,重置游戏相关
*/
public void resetGame() {
gameStatus = ConstantUtil.GAME_START;
linesLength = 5;
moveNum = 0;
mSuccGroup.showItems(false);
timerText.setText("00.000\"");
timerText.setVisible(true);
mTimerTool.resetTimer();
mSuccGroup.setVisible(false);
game_tip.setVisible(true);
deletBlocks();
initBlocks();
// 按Z索引排序一下上下层顺序
this.sortChildren();
} /**
* 创建添加新的一行
*/
private void createNewRowBolcks() {
// 超出屏幕没用的部分移除掉
if (blockList.size() > 5) {
Block[] rowBolcks = blockList.get(0);
for (Block block : rowBolcks) {
block.detachSelf();
}
blockList.remove(0);
} // 目前顶部的一行块的Y坐标
float topBlocksY = blockList.get(blockList.size() - 1)[0].getY(); // 一行块
Block[] rowBolcks = new Block[4];
int blackIndex = new Random().nextInt(4);
for (int column = 0; column < 4; column++) {
// 新创建 Block
rowBolcks[column] = new Block(this, column, blockWidth, blockHight,
blackIndex, getVertexBufferObjectManager());
// 设置Y坐标
rowBolcks[column].setBottomPositionY(topBlocksY - 1);
// 设置已经是第几行
rowBolcks[column].setRow(linesLength);
this.attachChild(rowBolcks[column]);
}
blockList.add(rowBolcks); // 按Z索引排序一下上下层顺序
this.sortChildren(); // 当前生成的块的行数增加
linesLength++;
} /**
* 最后一个移动,游戏胜利
*
* @param pBlock
*/
private void gameSucc(Block pBlock) {
gameStatus = ConstantUtil.GAME_OVER;
// 最后一个移动,游戏胜利
moveDown(pBlock, 0);
// 停止计时
mTimerTool.stop();
// 显示游戏胜利画面
mSuccGroup.showItems(true);
// 隐藏显示时间的Text
timerText.setVisible(false);
} /**
* 点击错误后弹出红色的失败界面,游戏失败
*/
private void gameFail() {
gameStatus = ConstantUtil.GAME_OVER;
// 游戏失败,停止计时
mTimerTool.stop();
// 隐藏显示时间的Text
timerText.setVisible(false);
} /**
* 游戏快到顶部时开始出现绿色的胜利界面
*/
private void showSuccGroup() {
// 目前顶部的一行块的Y坐标
float topBlocksY = blockList.get(blockList.size() - 1)[0].getY();
mSuccGroup.setBottomPositionY(topBlocksY);
mSuccGroup.setVisible(true);
} /**
* 移除剩下的block,清空blockList
*/
private void deletBlocks() {
for (Block[] rowBlocks : blockList) {
for (Block block : rowBlocks) {
this.detachChild(block);
}
} blockList.clear();
} /**
* 点击到Block时进行的逻辑处理
*
* @param pBlock
* 所点击的block
*/
public void touchBlock(Block pBlock) { if (gameStatus == ConstantUtil.GAME_START) { if (pBlock.getRow() == moveNum + 2) {// 表示是在底部往上数的倒数第三行
// 判断是不是点击了该点击的黑块的上一格,如果是,我们也判定这是正确点击了,做出相应移动
upBlockTouch(pBlock);
} else if (pBlock.getRow() == moveNum + 1) {// 表示是在底部往上数的倒数第二行
if (pBlock.getColorType() == ConstantUtil.COLOR_BLACK) {
if (linesLength == moveNum + 2) {
// 游戏胜利
gameSucc(pBlock);
} else {
// 整体blocks下移
moveDown(pBlock, 1);
} } else if (pBlock.getColorType() == ConstantUtil.COLOR_WHITE) {
// 误点了白块,游戏失败
gameFail();
// 失败时pBlock的一个闪红效果
LoopEntityModifier loop = failAction();
// 播放效果
pBlock.registerEntityModifier(loop);
} } } } /**
* 失败时pBlock的一个闪红效果
* @return
*/
private LoopEntityModifier failAction() {
SequenceEntityModifier sequence = new SequenceEntityModifier(
new ColorModifier(0.1f, Color.RED, Color.WHITE),
new DelayModifier(0.07f), new ColorModifier(0.1f,
Color.WHITE, Color.RED));
LoopEntityModifier loop = new LoopEntityModifier(sequence,
3, new IEntityModifierListener() { @Override
public void onModifierStarted(
IModifier<IEntity> pModifier,
IEntity pItem) {
}
@Override
public void onModifierFinished(
IModifier<IEntity> pModifier,
IEntity pItem) {
//效果播放完毕,显示游戏失败界面
mFailGroup.showView();
}
});
return loop;
} /**
* 判断是不是点击了该点击的黑块的上一格,如果是,我们也判定这是正确点击了,做出相应移动
*
* @param pBlock
* 所被点击的块
*/
private void upBlockTouch(Block pBlock) {
int touchColumn = pBlock.getColumn();
for (Block[] blocks : blockList) {
for (Block block : blocks) {
if (block.getRow() == moveNum + 1
&& block.getColorType() == ConstantUtil.COLOR_BLACK) {
if (block.getColumn() == touchColumn) {
// 整体blocks下移
moveDown(block, 1);
}
return;
}
} }
} /**
* 正确点击该点击的黑块,或者上一行的块,整体向下移动、创建新的一样块,改变黑块颜色
*
* @param pBlock
* @param stepNum
* 一般为1,到最后出现绿色成功界面的最后一步为0
*/
private void moveDown(Block pBlock, int stepNum) { if(moveNum == 0){
// 开始计时
mTimerTool.start();
// 隐藏提示文字
game_tip.setVisible(false);
} if (moveNum < ConstantUtil.LINES_LEN) {
// 创建添加新的一行
createNewRowBolcks();
} else if (moveNum == ConstantUtil.LINES_LEN) {
// 开始显示绿色胜利界面,即将胜利,但还没有胜利
showSuccGroup();
} // 被点击的黑块变灰
pBlock.setColor(0.63f, 0.63f, 0.63f);
pBlock.registerEntityModifier(new ScaleModifier(0.1f, 0.5f, 1.0f)); // 移动步数加1
moveNum++;
// 需要移动的距离
float moveDistance = this.getCameraHeight() - blockHight * stepNum
- pBlock.getY();
for (Block[] rowBlocks : blockList) {
for (Block block : rowBlocks) {
// 遍历,所有block向下移动指定距离
moveToY(block, moveDistance);
}
} // 快到胜利出现绿色胜利界面时,胜利界面跟着移动
if (mSuccGroup.isVisible()) {
moveToY(mSuccGroup, moveDistance);
}
} /**
* 在Y轴方向上,由当前位置移动指定的距离
*
* @param entity
* 要移动的实体
* @param moveDistance
* 需要移动的距离
*/
private void moveToY(IEntity entity, float moveDistance) {
float pFromY = entity.getY();
float pToY = pFromY + moveDistance;
entity.registerEntityModifier(new MoveYModifier(0.1f, pFromY, pToY));
} @Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
this.getActivity().finish();
return true;
}
return false;
} @Override
public void onSceneResume() {
super.onSceneResume();
this.setIgnoreUpdate(false);
} @Override
public void onScenePause() {
super.onScenePause();
this.setIgnoreUpdate(true);
} @Override
public void onSceneDestroy() {
super.onSceneDestroy(); LogUtil.d("onSceneDestroy");
} // ================================================================
/**
* 获取镜头的 右边 x 坐标
*/
public float getCameraRightX() {
return this.getCameraWidth();
} /**
* 获取镜头的 中点 x 坐标
*
* @return
*/
public float getCameraCenterX() {
return this.getCameraWidth() * 0.5f;
} /**
* 获取镜头底部Y坐标
*
* @return
*/
public float getCameraBottomY() {
return this.getCameraHeight();
} /**
* 获取镜头中心Y坐标
*
* @return
*/
public float getCameraCenterY() {
return this.getCameraHeight() * 0.5f;
} }

  

池彬宁:负责代码的实现(二)

blogs:www.cnblogs.com/Spr1ngxx  

codes:

package com.orange.block.res;

public class Res {

	public static final String XML_GFX_GAME = "gfx/game.xml";

	public static final String[] ALL_XML = new String[]{
Res.XML_GFX_GAME
}; public static final String BTN_AGAIN = "btn_again"; public static final String BTN_BACK = "btn_back"; public static final String BTN_START = "btn_start"; public static final String GAME_MODEL = "game_model"; public static final String GAME_TIP = "game_tip"; public static final String GAME_TITEL = "game_titel"; }

  

package com.orange.block.entity;

import com.orange.entity.primitive.Rectangle;
import com.orange.input.touch.TouchEvent;
import com.orange.opengl.vbo.VertexBufferObjectManager;
import com.orange.util.color.Color;
import com.orange.block.scene.GameScene;
import com.orange.block.util.ConstantUtil; /**
* 单个块元素
*
* @author lch
*
*/
public class Block extends Rectangle {
// 游戏场景
private GameScene mGameScene;
// 此block的颜色类型,白色还是黑色?
private int colorType;
// block 所在的行
private int row;
// block 所在的列
private int column; // ======================get&set========================
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public int getColumn() {
return column;
}
public int getColorType() {
return colorType;
}
// ===================================================== /**
* 构造器1,初始化blocks时用到
* @param pGameScene 游戏场景
* @param row block所在的行
* @param column block所在的列
* @param pWidth block的宽
* @param pHeight block的高
* @param blackIndex 用来确定是否是黑块,如果blackIndex == column时设为黑块
* @param pVertexBufferObjectManager
*/
public Block(GameScene pGameScene, int row, int column, float pWidth,
float pHeight, int blackIndex,
VertexBufferObjectManager pVertexBufferObjectManager) {
super(column * pWidth, (3 - row) * pHeight, pWidth - 1, pHeight - 1,
pVertexBufferObjectManager);
this.mGameScene = pGameScene;
this.row = row;
this.column = column;
if (row == 0) {
// 第一行设置为黄块
this.setColor(Color.YELLOW);
} else {
// 初始化block的颜色数据,是白块还是黑块?
initBlockData(column, blackIndex);
}
// 设置可以相应触碰事件
this.setIgnoreTouch(false);
} /**
* 构造器2,新增blocks时用到
* @param pGameScene 游戏场景
* @param column block所在的列
* @param pWidth block的宽
* @param pHeight block的高
* @param blackIndex 来确定是否是黑块,如果blackIndex == column时设为黑块
* @param pVertexBufferObjectManager
*/
public Block(GameScene pGameScene, int column, float pWidth, float pHeight,
int blackIndex, VertexBufferObjectManager pVertexBufferObjectManager) {
super(column * pWidth, 0, pWidth - 1, pHeight - 1,
pVertexBufferObjectManager);
this.mGameScene = pGameScene;
this.column = column;
// 初始化block的颜色数据,是白块还是黑块?
initBlockData(column, blackIndex);
// 设置可以相应触碰事件
this.setIgnoreTouch(false);
} /**
* 初始化block的颜色数据,是白块还是黑块?
* @param column
* @param blackIndex
*/
private void initBlockData(int column, int blackIndex) {
if (blackIndex == column) {
// 设置为黑块
this.setColor(Color.BLACK);
this.colorType = ConstantUtil.COLOR_BLACK;
} else {
// 设置为白块
this.setColor(Color.WHITE);
this.colorType = ConstantUtil.COLOR_WHITE;
}
} @Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
// 触碰事件监听
if (pSceneTouchEvent.isActionDown()) {
// 点击到Block时进行的逻辑处理
mGameScene.touchBlock(this);
}
return true;
}
}

  

package com.orange.block.entity;

import android.app.AlertDialog;
import android.content.DialogInterface; import com.orange.entity.group.EntityGroup;
import com.orange.entity.modifier.ScaleModifier;
import com.orange.entity.primitive.Rectangle;
import com.orange.entity.sprite.AnimatedSprite;
import com.orange.entity.sprite.ButtonSprite;
import com.orange.entity.sprite.ButtonSprite.OnClickListener;
import com.orange.entity.text.Text;
import com.orange.res.FontRes;
import com.orange.util.color.Color;
import com.orange.block.control.TimerTool;
import com.orange.block.res.Res;
import com.orange.block.scene.GameScene;
import com.orange.block.util.ConstantUtil;
import com.orange.block.util.SharedUtil; /**
* 失败界面
*
* @author lch
*
*/
public class FailGroup extends EntityGroup { private GameScene mGameScene;
private Rectangle bgRect; private AnimatedSprite titelSprite;
private AnimatedSprite modelSprite; private ButtonSprite btn_back; // 返回按钮
private ButtonSprite btn_again;// 重来按钮 private Text txt_big;
private Text txt_small; public FailGroup(float pWidth, float pHeight, GameScene pGameScene) {
super(pWidth, pHeight, pGameScene);
this.mGameScene = pGameScene;
initView();
} private void initView() {
// 背景
bgRect = new Rectangle(0, 0, this.getWidth(), this.getHeight(),
this.getVertexBufferObjectManager());
this.attachChild(bgRect);
bgRect.setColor(Color.RED);
// 标题 “别踩白块儿”
titelSprite = new AnimatedSprite(0, 10, Res.GAME_TITEL,
this.getVertexBufferObjectManager());
titelSprite.setRightPositionX(this.getRightX() - 10);
this.attachChild(titelSprite); // 模式 “经典模式”
modelSprite = new AnimatedSprite(0, 150, Res.GAME_MODEL,
this.getVertexBufferObjectManager());
modelSprite.setCentrePositionX(this.getCentreX());
this.attachChild(modelSprite); // 大字
txt_big = new Text(0, modelSprite.getBottomY() + 130,
FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
this.getVertexBufferObjectManager());
this.attachChild(txt_big);
txt_big.setScale(1.9f);
// 小字
txt_small = new Text(0, txt_big.getBottomY() + 30,
FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
this.getVertexBufferObjectManager());
this.attachChild(txt_small);
txt_small.setScale(0.7f);
// 返回按钮
btn_back = new ButtonSprite(80, 0, Res.BTN_BACK,
this.getVertexBufferObjectManager());
btn_back.setBottomPositionY(this.getBottomY() - 50);
btn_back.setIgnoreTouch(false);
this.attachChild(btn_back);
btn_back.setOnClickListener(onClickListener);
// 重来按钮
btn_again = new ButtonSprite(0, 0, Res.BTN_AGAIN,
this.getVertexBufferObjectManager());
btn_again.setRightPositionX(this.getRightX() - 80);
btn_again.setBottomPositionY(this.getBottomY() - 50);
btn_again.setIgnoreTouch(false);
this.attachChild(btn_again);
btn_again.setOnClickListener(onClickListener); resetView();
} public void showView() {
setBtnEnable(true);
this.setVisible(true);
updateBigTxt("失败了!"); if (SharedUtil.getRecord(getActivity()) > 0) {
TimerTool mTimerTool = mGameScene.getmTimerTool();
updateSmallTxt("最佳: "
+ mTimerTool.millisToTimer(SharedUtil
.getRecord(getActivity())));
} ScaleModifier scaleModifier = new ScaleModifier(0.2f, 0.0f, 1.0f);
this.registerEntityModifier(scaleModifier); } private void updateBigTxt(String pText) {
txt_big.setText(pText);
txt_big.setCentrePositionX(this.getCentreX());
} private void updateSmallTxt(String pText) {
txt_small.setText(pText);
txt_small.setCentrePositionX(this.getCentreX());
} private OnClickListener onClickListener = new OnClickListener() { @Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
float pTouchAreaLocalY) {
if (btn_back == pButtonSprite) {
showDialog();
} else if (btn_again == pButtonSprite) {
resetView();
mGameScene.resetGame();
} } }; private void resetView(){
this.setScale(0);
this.setVisible(false);
setBtnEnable(false);
} private void setBtnEnable(boolean isEnable) {
btn_back.setEnabled(isEnable);
btn_again.setEnabled(isEnable);
} /**
* 退出游戏确认对话框
*/
private void showDialog() {
getActivity().runOnUiThread(new Runnable() { @Override
public void run() { new AlertDialog.Builder(getActivity())
.setTitle("退出游戏")
.setMessage("是否要退出游戏!")
.setPositiveButton("确定",
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog,
int which) {
getActivity().finish(); }
}).setNegativeButton("取消", null).show();
}
});
}
}
package com.orange.block.entity;

import android.app.AlertDialog;
import android.content.DialogInterface; import com.orange.entity.group.EntityGroup;
import com.orange.entity.primitive.Rectangle;
import com.orange.entity.sprite.AnimatedSprite;
import com.orange.entity.sprite.ButtonSprite;
import com.orange.entity.sprite.ButtonSprite.OnClickListener;
import com.orange.entity.text.Text;
import com.orange.res.FontRes;
import com.orange.util.color.Color;
import com.orange.block.control.TimerTool;
import com.orange.block.res.Res;
import com.orange.block.scene.GameScene;
import com.orange.block.util.ConstantUtil;
import com.orange.block.util.SharedUtil; /**
* 成功界面
*
* @author lch
*
*/
public class SuccGroup extends EntityGroup { private GameScene mGameScene;
private Rectangle bgRect; private AnimatedSprite titelSprite;
private AnimatedSprite modelSprite; private ButtonSprite btn_back; // 返回按钮
private ButtonSprite btn_again;// 重来按钮 private Text txt_big;
private Text txt_small; public SuccGroup(float pWidth, float pHeight, GameScene pGameScene) {
super(pWidth, pHeight, pGameScene);
initView();
this.mGameScene = pGameScene;
} private void initView() {
// 背景
bgRect = new Rectangle(0, 0, this.getWidth(), this.getHeight(),
this.getVertexBufferObjectManager());
this.attachChild(bgRect);
bgRect.setColor(Color.GREEN);
// 标题 “别踩白块儿”
titelSprite = new AnimatedSprite(0, 10, Res.GAME_TITEL,
this.getVertexBufferObjectManager());
titelSprite.setRightPositionX(this.getRightX() - 10);
this.attachChild(titelSprite);
titelSprite.setVisible(false); // 模式 “经典模式”
modelSprite = new AnimatedSprite(0, 150, Res.GAME_MODEL,
this.getVertexBufferObjectManager());
modelSprite.setCentrePositionX(this.getCentreX());
this.attachChild(modelSprite);
modelSprite.setVisible(false); // 大字
txt_big = new Text(0, modelSprite.getBottomY() + 100,
FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
this.getVertexBufferObjectManager());
this.attachChild(txt_big);
txt_big.setScale(1.5f);
txt_big.setVisible(false);
// 小字
txt_small = new Text(0, txt_big.getBottomY() + 10,
FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
this.getVertexBufferObjectManager());
this.attachChild(txt_small);
txt_small.setScale(0.7f);
txt_small.setVisible(false);
// 返回按钮
btn_back = new ButtonSprite(80, 0, Res.BTN_BACK,
this.getVertexBufferObjectManager());
btn_back.setBottomPositionY(this.getBottomY() - 50);
btn_back.setIgnoreTouch(false);
this.attachChild(btn_back);
btn_back.setOnClickListener(onClickListener);
btn_back.setVisible(false);
// 重来按钮
btn_again = new ButtonSprite(0, 0, Res.BTN_AGAIN,
this.getVertexBufferObjectManager());
btn_again.setRightPositionX(this.getRightX() - 80);
btn_again.setBottomPositionY(this.getBottomY() - 50);
btn_again.setIgnoreTouch(false);
this.attachChild(btn_again);
btn_again.setOnClickListener(onClickListener);
btn_again.setVisible(false);
} public void showItems(boolean pVisible) {
titelSprite.setVisible(pVisible);
modelSprite.setVisible(pVisible);
txt_big.setVisible(pVisible);
txt_small.setVisible(pVisible);
btn_back.setVisible(pVisible);
btn_again.setVisible(pVisible); if (pVisible) {
TimerTool mTimerTool = mGameScene.getmTimerTool();
updateBigTxt(mTimerTool.millisToTimer(mTimerTool
.getMillisPass())); long mMillisPass = mTimerTool.getMillisPass(); if (mMillisPass < SharedUtil.getRecord(getActivity())
|| SharedUtil.getRecord(getActivity()) == 0) {
// 新记录
updateSmallTxt("新记录");
SharedUtil.setRecord(getActivity(), mMillisPass); } else { updateSmallTxt("最佳: "
+ mTimerTool.millisToTimer(SharedUtil
.getRecord(getActivity())));
}
} } public void updateBigTxt(String pText) {
txt_big.setText(pText);
txt_big.setCentrePositionX(this.getCentreX());
} public void updateSmallTxt(String pText) {
txt_small.setText(pText);
txt_small.setCentrePositionX(this.getCentreX());
} private OnClickListener onClickListener = new OnClickListener() { @Override
public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
float pTouchAreaLocalY) {
if (btn_back == pButtonSprite) {
showDialog();
} else if (btn_again == pButtonSprite) {
mGameScene.resetGame();
} }
}; /**
* 退出游戏确认对话框
*/
private void showDialog() {
getActivity().runOnUiThread(new Runnable() { @Override
public void run() { new AlertDialog.Builder(getActivity())
.setTitle("退出游戏")
.setMessage("是否要退出游戏!")
.setPositiveButton("确定",
new DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog,
int which) {
getActivity().finish(); }
}).setNegativeButton("取消", null).show();
}
});
}
}

贺邦:负责代码的调试与测试

blogs:http://www.cnblogs.com/L1nke/

codes:

 public class Test {
private int fAmount;
private String fCurrency; public Test(int amount, String currency) {
fAmount= amount;
fCurrency= currency;
} public int amount() {
return fAmount;
} public String currency() {
return fCurrency;
} public Test add(Test m) {
return new Test(amount()+m.amount(), currency());
} public boolean equals(Object anObject) {
if (anObject instanceof Test) {
Test aMoney= (Test)anObject;
return aMoney.currency().equals(currency())
&& amount() == aMoney.amount();
}
return false;
}
}

步骤

耗时

百分比

需求分析

 20min  3.8%

设计

50min   9.6%

代码实现

300min   57.7%

测试

120min   23.1%

分析总结

 30min  5.8%

最新文章

  1. Javascript写入txt和读取txt文件的方法
  2. Access批量操作
  3. 使用kerl安装erlang遇到的问题及解决办法
  4. python的exec、eval详解
  5. Android Studio IDE 所遇问题汇总
  6. HDU 1385 Minimum Transport Cost 最短路径题解
  7. 字符串ID转换成字符串名字
  8. mysql的登录和备份
  9. Swift Runtime ?
  10. js关于new Date() 日期格式
  11. editormd实现文章详情页面预览
  12. 《DSP using MATLAB》Problem 7.4
  13. JavaScript获取、修改CSS样式合辑
  14. SQL SERVER利用BCP命令在命令行下导出数据到csv文件中
  15. three.js - 添加材质 灯光 阴影
  16. 跟我一起学习vue2(使用命令行搭建单页应用)[二]
  17. [django]django权限简单实验
  18. rem是如何实现自适应布局的
  19. printf()详解之终极无惑
  20. Intelligent Factorial Factorization LightOJ - 1035(水题)

热门文章

  1. KMP算法之从懵逼到入门
  2. zdump 命令查看时区和夏令时
  3. 底部带突出按钮的tabbar
  4. hadoop环境搭建-伪分布模式
  5. 6.Exceptions-异常(Dart中文文档)
  6. 传统神经网络ANN训练算法总结
  7. GBDT+LR算法解析及Python实现
  8. cogs 1330 [HNOI2008]玩具装箱toy
  9. python之GIL(Global Interpreter Lock)
  10. CSS快速入门-定位布局(九宫格)