北京电子科技学院(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:

  1. package com.orange.block;
  2.  
  3. import android.graphics.Color;
  4. import android.graphics.Typeface;
  5. import android.os.Bundle;
  6.  
  7. import com.orange.engine.camera.ZoomCamera;
  8. import com.orange.engine.options.PixelPerfectEngineOptions;
  9. import com.orange.engine.options.PixelPerfectMode;
  10. import com.orange.engine.options.ScreenOrientation;
  11. import com.orange.res.FontRes;
  12. import com.orange.res.RegionRes;
  13. import com.orange.ui.activity.GameActivity;
  14. import com.orange.block.res.Res;
  15. import com.orange.block.scene.GameScene;
  16. import com.orange.block.util.ConstantUtil;
  17. import com.orange.block.util.LogUtil;
  18.  
  19. /**
  20. * 入口主Activity 类
  21. * @author lch<OGEngine@orangegame.cn>
  22. * @
  23. */
  24. public class MainActivity extends GameActivity {
  25. @Override
  26. protected void onCreate(Bundle pSavedInstanceState) {
  27. super.onCreate(pSavedInstanceState);
  28.  
  29. }
  30.  
  31. @Override
  32. protected PixelPerfectEngineOptions onCreatePixelPerfectEngineOptions() {
  33. PixelPerfectEngineOptions pixelPerfectEngineOptions = new PixelPerfectEngineOptions(
  34. this, ZoomCamera.class);
  35. pixelPerfectEngineOptions
  36. .setScreenOrientation(ScreenOrientation.PORTRAIT_FIXED); // 设置竖屏
  37. pixelPerfectEngineOptions
  38. .setPixelPerfectMode(PixelPerfectMode.CHANGE_HEIGHT);// 适配模式,这里设置为“保持宽度不变,改变高”
  39. pixelPerfectEngineOptions.setDesiredSize(ConstantUtil.DESIRED_SIZE);// 参考尺寸
  40.  
  41. return pixelPerfectEngineOptions;
  42. }
  43.  
  44. @Override
  45. protected void onLoadResources() {
  46. // 加载相关初始的资源等
  47. LogUtil.d("开始加载资源...");
  48. RegionRes.loadTexturesFromAssets(Res.ALL_XML);
  49. FontRes.loadFont(128, 128,
  50. Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 40, true,
  51. Color.RED, ConstantUtil.FONT_NAME_TIMER);
  52.  
  53. FontRes.loadFont(256, 512,
  54. Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 50, true,
  55. Color.BLACK, ConstantUtil.FONT_NAME_RESULT);
  56.  
  57. }
  58.  
  59. @Override
  60. protected void onLoadComplete() {
  61. // 加载资源完成后
  62. LogUtil.d("加载资源完成...");
  63. this.startScene(GameScene.class);// 启动游戏场景
  64. }
  65.  
  66. @Override
  67. protected void onPause() {
  68. super.onPause();
  69. this.getEngine().stop();
  70. }
  71.  
  72. @Override
  73. protected synchronized void onResume() {
  74. super.onResume();
  75. this.getEngine().start();
  76. }
  77.  
  78. @Override
  79. protected void onDestroy() {
  80. super.onDestroy();
  81.  
  82. android.os.Process.killProcess(android.os.Process.myPid());
  83. }
  84. }

  

  1. package com.orange.block.util;
  2.  
  3. public class ConstantUtil {
  4.  
  5. /**屏幕参考尺寸**/
  6. public static final float DESIRED_SIZE = 480;
  7.  
  8. /**标示白颜色**/
  9. public static final int COLOR_WHITE = 0;
  10. /**标示黑颜色**/
  11. public static final int COLOR_BLACK = 1;
  12.  
  13. /**游戏进行状态**/
  14. public static final int GAME_START = 1;
  15. /**游戏结束状态**/
  16. public static final int GAME_OVER = 2;
  17.  
  18. /** 游戏总共有多少行 **/
  19. public static final int LINES_LEN = 50;
  20.  
  21. /**字体颜色的 key**/
  22. public static final String FONT_NAME_TIMER = "timer";
  23. public static final String FONT_NAME_RESULT = "result";
  24. }

  

  1. package com.orange.block.util;
  2.  
  3. import android.util.Log;
  4.  
  5. /**
  6. *
  7. * @author lch
  8. *
  9. */
  10. public class LogUtil {
  11. private static boolean showLogEnabled = true;
  12. private static final String TAG = "OG";
  13.  
  14. public static void out(String msg) {
  15. if (showLogEnabled)
  16. System.out.println(msg);
  17. }
  18.  
  19. public static void d(String msg) {
  20. if (showLogEnabled)
  21. Log.d(TAG, msg);
  22. }
  23.  
  24. public static void i(String msg) {
  25. if (showLogEnabled)
  26. Log.i(TAG, msg);
  27. }
  28.  
  29. public static void v(String msg) {
  30. if (showLogEnabled)
  31. Log.v(TAG, msg);
  32. }
  33.  
  34. public static void w(String msg) {
  35. if (showLogEnabled)
  36. Log.w(TAG, msg);
  37. }
  38.  
  39. public static void e(String msg) {
  40. if (showLogEnabled)
  41. Log.e(TAG, msg);
  42. }
  43.  
  44. }

  

  1. package com.orange.block.util;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences.Editor;
  5.  
  6. /**
  7. * 保存到 SharedPreferences 的数据
  8. *
  9. * @author lch
  10. *
  11. */
  12. public class SharedUtil {
  13.  
  14. private static final String SHARED_OG = "Shared_og";
  15.  
  16. private static final String RESULT_RECORD = "result_record";
  17.  
  18. /**
  19. * 保持最新的记录
  20. * @param pContext
  21. * @param pMillisPass
  22. */
  23. public static void setRecord(Context pContext, long pMillisPass) {
  24. Editor edit = pContext.getSharedPreferences(SHARED_OG,
  25. Context.MODE_PRIVATE).edit();
  26. edit.putLong(RESULT_RECORD, pMillisPass);
  27. edit.commit();
  28. }
  29.  
  30. /**
  31. * 获取记录
  32. * @param context
  33. * @return
  34. */
  35. public static long getRecord(Context context) {
  36. return context
  37. .getSharedPreferences(SHARED_OG, Context.MODE_PRIVATE)
  38. .getLong(RESULT_RECORD, 0);
  39. }
  40.  
  41. }

  

  1. package com.orange.block.scene;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import android.view.KeyEvent;
  8.  
  9. import com.orange.content.SceneBundle;
  10. import com.orange.entity.IEntity;
  11. import com.orange.entity.modifier.ColorModifier;
  12. import com.orange.entity.modifier.DelayModifier;
  13. import com.orange.entity.modifier.IEntityModifier.IEntityModifierListener;
  14. import com.orange.entity.modifier.LoopEntityModifier;
  15. import com.orange.entity.modifier.MoveYModifier;
  16. import com.orange.entity.modifier.ScaleModifier;
  17. import com.orange.entity.modifier.SequenceEntityModifier;
  18. import com.orange.entity.primitive.DrawMode;
  19. import com.orange.entity.primitive.Mesh;
  20. import com.orange.entity.scene.Scene;
  21. import com.orange.entity.sprite.AnimatedSprite;
  22. import com.orange.entity.text.Text;
  23. import com.orange.res.FontRes;
  24. import com.orange.util.color.Color;
  25. import com.orange.util.modifier.IModifier;
  26. import com.orange.block.control.TimerTool;
  27. import com.orange.block.entity.Block;
  28. import com.orange.block.entity.FailGroup;
  29. import com.orange.block.entity.SuccGroup;
  30. import com.orange.block.res.Res;
  31. import com.orange.block.util.ConstantUtil;
  32. import com.orange.block.util.LogUtil;
  33.  
  34. /**
  35. * 游戏场景
  36. *
  37. * @author lch
  38. *
  39. */
  40. public class GameScene extends Scene {
  41. /** 块的宽 **/
  42. private float blockWidth = 0;
  43. /** 块的高 **/
  44. private float blockHight = 0;
  45. /** 用于装当前所有生成但未被删除的block **/
  46. private List<Block[]> blockList;
  47. /** 当前生成的块的行数 **/
  48. private int linesLength = 5;
  49. /** 游戏状态 **/
  50. private int gameStatus = ConstantUtil.GAME_START;
  51. /** 移动步数 **/
  52. private int moveNum = 0;
  53. /** 成功界面 **/
  54. private SuccGroup mSuccGroup;
  55. /** 失败界面 **/
  56. private FailGroup mFailGroup;
  57. /** 计时管理类 **/
  58. private TimerTool mTimerTool;
  59.  
  60. /** 显示计时的Text **/
  61. private Text timerText;
  62.  
  63. /**游戏提示语**/
  64. private AnimatedSprite game_tip;
  65.  
  66. // 用于Z索引排序
  67. private static final int pZIndex_middle = 2;
  68. private static final int pZIndex_top = 3;
  69.  
  70. public Text getTimerText() {
  71. return timerText;
  72. }
  73.  
  74. public TimerTool getmTimerTool() {
  75. return mTimerTool;
  76. }
  77.  
  78. @Override
  79. public void onSceneCreate(SceneBundle bundle) {
  80. super.onSceneCreate(bundle);
  81. // 镜头里显示的是4*4的块,所以用镜头宽的四分之一作为块宽
  82. blockWidth = this.getCameraWidth() / 4;
  83. blockHight = this.getCameraHeight() / 4;
  84.  
  85. this.blockList = new ArrayList<Block[]>();
  86. mTimerTool = new TimerTool(this);
  87. initView();
  88. }
  89.  
  90. private void initView() {
  91. // 初始化blocks
  92. initBlocks();
  93.  
  94. timerText = new Text(getCameraCenterX(), 10,
  95. FontRes.getFont(ConstantUtil.FONT_NAME_TIMER), "00.000\"",
  96. "00:00.000\"".length(), getVertexBufferObjectManager());
  97. this.attachChild(timerText);
  98. timerText.setCentrePositionX(getCameraCenterX());
  99. timerText.setZIndex(pZIndex_top);
  100.  
  101. mSuccGroup = new SuccGroup(getCameraWidth(), getCameraHeight(), this);
  102. mSuccGroup.setZIndex(pZIndex_middle);
  103. mSuccGroup.setVisible(false);
  104. this.attachChild(mSuccGroup);
  105.  
  106. mFailGroup = new FailGroup(getCameraWidth(), getCameraHeight(), this);
  107. this.attachChild(mFailGroup);
  108. mFailGroup.setZIndex(pZIndex_middle);
  109.  
  110. game_tip = new AnimatedSprite(0, 0, Res.GAME_TIP, getVertexBufferObjectManager());
  111. game_tip.setCentrePositionX(this.getCameraCenterX());
  112. game_tip.setBottomPositionY(this.getCameraBottomY()-60);
  113. this.attachChild(game_tip);
  114. game_tip.setZIndex(pZIndex_top);
  115.  
  116. }
  117.  
  118. /**
  119. * 初始化blocks
  120. */
  121. private void initBlocks() {
  122. Random mRandom = new Random();
  123.  
  124. int blackIndex = 0;
  125. // 初始blocks,先创建4*5表格,使用时候再一行行增加
  126. for (int row = 0; row < linesLength; row++) {// 行
  127. // 一行blocks
  128. Block[] rowBolcks = new Block[4];
  129. // 随机一个黑块所在位置
  130. blackIndex = mRandom.nextInt(4);
  131. for (int column = 0; column < 4; column++) {// 列
  132. rowBolcks[column] = new Block(this, row, column, blockWidth,
  133. blockHight, blackIndex, getVertexBufferObjectManager());
  134. this.attachChild(rowBolcks[column]);
  135. }
  136. blockList.add(rowBolcks);
  137. }
  138. }
  139.  
  140. /**
  141. * 重来时,重置游戏相关
  142. */
  143. public void resetGame() {
  144. gameStatus = ConstantUtil.GAME_START;
  145. linesLength = 5;
  146. moveNum = 0;
  147. mSuccGroup.showItems(false);
  148. timerText.setText("00.000\"");
  149. timerText.setVisible(true);
  150. mTimerTool.resetTimer();
  151. mSuccGroup.setVisible(false);
  152. game_tip.setVisible(true);
  153. deletBlocks();
  154. initBlocks();
  155. // 按Z索引排序一下上下层顺序
  156. this.sortChildren();
  157. }
  158.  
  159. /**
  160. * 创建添加新的一行
  161. */
  162. private void createNewRowBolcks() {
  163. // 超出屏幕没用的部分移除掉
  164. if (blockList.size() > 5) {
  165. Block[] rowBolcks = blockList.get(0);
  166. for (Block block : rowBolcks) {
  167. block.detachSelf();
  168. }
  169. blockList.remove(0);
  170. }
  171.  
  172. // 目前顶部的一行块的Y坐标
  173. float topBlocksY = blockList.get(blockList.size() - 1)[0].getY();
  174.  
  175. // 一行块
  176. Block[] rowBolcks = new Block[4];
  177. int blackIndex = new Random().nextInt(4);
  178. for (int column = 0; column < 4; column++) {
  179. // 新创建 Block
  180. rowBolcks[column] = new Block(this, column, blockWidth, blockHight,
  181. blackIndex, getVertexBufferObjectManager());
  182. // 设置Y坐标
  183. rowBolcks[column].setBottomPositionY(topBlocksY - 1);
  184. // 设置已经是第几行
  185. rowBolcks[column].setRow(linesLength);
  186. this.attachChild(rowBolcks[column]);
  187. }
  188. blockList.add(rowBolcks);
  189.  
  190. // 按Z索引排序一下上下层顺序
  191. this.sortChildren();
  192.  
  193. // 当前生成的块的行数增加
  194. linesLength++;
  195. }
  196.  
  197. /**
  198. * 最后一个移动,游戏胜利
  199. *
  200. * @param pBlock
  201. */
  202. private void gameSucc(Block pBlock) {
  203. gameStatus = ConstantUtil.GAME_OVER;
  204. // 最后一个移动,游戏胜利
  205. moveDown(pBlock, 0);
  206. // 停止计时
  207. mTimerTool.stop();
  208. // 显示游戏胜利画面
  209. mSuccGroup.showItems(true);
  210. // 隐藏显示时间的Text
  211. timerText.setVisible(false);
  212. }
  213.  
  214. /**
  215. * 点击错误后弹出红色的失败界面,游戏失败
  216. */
  217. private void gameFail() {
  218. gameStatus = ConstantUtil.GAME_OVER;
  219. // 游戏失败,停止计时
  220. mTimerTool.stop();
  221. // 隐藏显示时间的Text
  222. timerText.setVisible(false);
  223. }
  224.  
  225. /**
  226. * 游戏快到顶部时开始出现绿色的胜利界面
  227. */
  228. private void showSuccGroup() {
  229. // 目前顶部的一行块的Y坐标
  230. float topBlocksY = blockList.get(blockList.size() - 1)[0].getY();
  231. mSuccGroup.setBottomPositionY(topBlocksY);
  232. mSuccGroup.setVisible(true);
  233. }
  234.  
  235. /**
  236. * 移除剩下的block,清空blockList
  237. */
  238. private void deletBlocks() {
  239. for (Block[] rowBlocks : blockList) {
  240. for (Block block : rowBlocks) {
  241. this.detachChild(block);
  242. }
  243. }
  244.  
  245. blockList.clear();
  246. }
  247.  
  248. /**
  249. * 点击到Block时进行的逻辑处理
  250. *
  251. * @param pBlock
  252. * 所点击的block
  253. */
  254. public void touchBlock(Block pBlock) {
  255.  
  256. if (gameStatus == ConstantUtil.GAME_START) {
  257.  
  258. if (pBlock.getRow() == moveNum + 2) {// 表示是在底部往上数的倒数第三行
  259. // 判断是不是点击了该点击的黑块的上一格,如果是,我们也判定这是正确点击了,做出相应移动
  260. upBlockTouch(pBlock);
  261. } else if (pBlock.getRow() == moveNum + 1) {// 表示是在底部往上数的倒数第二行
  262. if (pBlock.getColorType() == ConstantUtil.COLOR_BLACK) {
  263. if (linesLength == moveNum + 2) {
  264. // 游戏胜利
  265. gameSucc(pBlock);
  266. } else {
  267. // 整体blocks下移
  268. moveDown(pBlock, 1);
  269. }
  270.  
  271. } else if (pBlock.getColorType() == ConstantUtil.COLOR_WHITE) {
  272. // 误点了白块,游戏失败
  273. gameFail();
  274. // 失败时pBlock的一个闪红效果
  275. LoopEntityModifier loop = failAction();
  276. // 播放效果
  277. pBlock.registerEntityModifier(loop);
  278. }
  279.  
  280. }
  281.  
  282. }
  283.  
  284. }
  285.  
  286. /**
  287. * 失败时pBlock的一个闪红效果
  288. * @return
  289. */
  290. private LoopEntityModifier failAction() {
  291. SequenceEntityModifier sequence = new SequenceEntityModifier(
  292. new ColorModifier(0.1f, Color.RED, Color.WHITE),
  293. new DelayModifier(0.07f), new ColorModifier(0.1f,
  294. Color.WHITE, Color.RED));
  295. LoopEntityModifier loop = new LoopEntityModifier(sequence,
  296. 3, new IEntityModifierListener() {
  297.  
  298. @Override
  299. public void onModifierStarted(
  300. IModifier<IEntity> pModifier,
  301. IEntity pItem) {
  302. }
  303. @Override
  304. public void onModifierFinished(
  305. IModifier<IEntity> pModifier,
  306. IEntity pItem) {
  307. //效果播放完毕,显示游戏失败界面
  308. mFailGroup.showView();
  309. }
  310. });
  311. return loop;
  312. }
  313.  
  314. /**
  315. * 判断是不是点击了该点击的黑块的上一格,如果是,我们也判定这是正确点击了,做出相应移动
  316. *
  317. * @param pBlock
  318. * 所被点击的块
  319. */
  320. private void upBlockTouch(Block pBlock) {
  321. int touchColumn = pBlock.getColumn();
  322. for (Block[] blocks : blockList) {
  323. for (Block block : blocks) {
  324. if (block.getRow() == moveNum + 1
  325. && block.getColorType() == ConstantUtil.COLOR_BLACK) {
  326. if (block.getColumn() == touchColumn) {
  327. // 整体blocks下移
  328. moveDown(block, 1);
  329. }
  330. return;
  331. }
  332. }
  333.  
  334. }
  335. }
  336.  
  337. /**
  338. * 正确点击该点击的黑块,或者上一行的块,整体向下移动、创建新的一样块,改变黑块颜色
  339. *
  340. * @param pBlock
  341. * @param stepNum
  342. * 一般为1,到最后出现绿色成功界面的最后一步为0
  343. */
  344. private void moveDown(Block pBlock, int stepNum) {
  345.  
  346. if(moveNum == 0){
  347. // 开始计时
  348. mTimerTool.start();
  349. // 隐藏提示文字
  350. game_tip.setVisible(false);
  351. }
  352.  
  353. if (moveNum < ConstantUtil.LINES_LEN) {
  354. // 创建添加新的一行
  355. createNewRowBolcks();
  356. } else if (moveNum == ConstantUtil.LINES_LEN) {
  357. // 开始显示绿色胜利界面,即将胜利,但还没有胜利
  358. showSuccGroup();
  359. }
  360.  
  361. // 被点击的黑块变灰
  362. pBlock.setColor(0.63f, 0.63f, 0.63f);
  363. pBlock.registerEntityModifier(new ScaleModifier(0.1f, 0.5f, 1.0f));
  364.  
  365. // 移动步数加1
  366. moveNum++;
  367. // 需要移动的距离
  368. float moveDistance = this.getCameraHeight() - blockHight * stepNum
  369. - pBlock.getY();
  370. for (Block[] rowBlocks : blockList) {
  371. for (Block block : rowBlocks) {
  372. // 遍历,所有block向下移动指定距离
  373. moveToY(block, moveDistance);
  374. }
  375. }
  376.  
  377. // 快到胜利出现绿色胜利界面时,胜利界面跟着移动
  378. if (mSuccGroup.isVisible()) {
  379. moveToY(mSuccGroup, moveDistance);
  380. }
  381. }
  382.  
  383. /**
  384. * 在Y轴方向上,由当前位置移动指定的距离
  385. *
  386. * @param entity
  387. * 要移动的实体
  388. * @param moveDistance
  389. * 需要移动的距离
  390. */
  391. private void moveToY(IEntity entity, float moveDistance) {
  392. float pFromY = entity.getY();
  393. float pToY = pFromY + moveDistance;
  394. entity.registerEntityModifier(new MoveYModifier(0.1f, pFromY, pToY));
  395. }
  396.  
  397. @Override
  398. public boolean onKeyUp(int keyCode, KeyEvent event) {
  399. if (keyCode == KeyEvent.KEYCODE_BACK) {
  400. this.getActivity().finish();
  401. return true;
  402. }
  403. return false;
  404. }
  405.  
  406. @Override
  407. public void onSceneResume() {
  408. super.onSceneResume();
  409. this.setIgnoreUpdate(false);
  410. }
  411.  
  412. @Override
  413. public void onScenePause() {
  414. super.onScenePause();
  415. this.setIgnoreUpdate(true);
  416. }
  417.  
  418. @Override
  419. public void onSceneDestroy() {
  420. super.onSceneDestroy();
  421.  
  422. LogUtil.d("onSceneDestroy");
  423. }
  424.  
  425. // ================================================================
  426. /**
  427. * 获取镜头的 右边 x 坐标
  428. */
  429. public float getCameraRightX() {
  430. return this.getCameraWidth();
  431. }
  432.  
  433. /**
  434. * 获取镜头的 中点 x 坐标
  435. *
  436. * @return
  437. */
  438. public float getCameraCenterX() {
  439. return this.getCameraWidth() * 0.5f;
  440. }
  441.  
  442. /**
  443. * 获取镜头底部Y坐标
  444. *
  445. * @return
  446. */
  447. public float getCameraBottomY() {
  448. return this.getCameraHeight();
  449. }
  450.  
  451. /**
  452. * 获取镜头中心Y坐标
  453. *
  454. * @return
  455. */
  456. public float getCameraCenterY() {
  457. return this.getCameraHeight() * 0.5f;
  458. }
  459.  
  460. }

  

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

blogs:www.cnblogs.com/Spr1ngxx  

codes:

  1. package com.orange.block.res;
  2.  
  3. public class Res {
  4.  
  5. public static final String XML_GFX_GAME = "gfx/game.xml";
  6.  
  7. public static final String[] ALL_XML = new String[]{
  8. Res.XML_GFX_GAME
  9. };
  10.  
  11. public static final String BTN_AGAIN = "btn_again";
  12.  
  13. public static final String BTN_BACK = "btn_back";
  14.  
  15. public static final String BTN_START = "btn_start";
  16.  
  17. public static final String GAME_MODEL = "game_model";
  18.  
  19. public static final String GAME_TIP = "game_tip";
  20.  
  21. public static final String GAME_TITEL = "game_titel";
  22.  
  23. }

  

  1. package com.orange.block.entity;
  2.  
  3. import com.orange.entity.primitive.Rectangle;
  4. import com.orange.input.touch.TouchEvent;
  5. import com.orange.opengl.vbo.VertexBufferObjectManager;
  6. import com.orange.util.color.Color;
  7. import com.orange.block.scene.GameScene;
  8. import com.orange.block.util.ConstantUtil;
  9.  
  10. /**
  11. * 单个块元素
  12. *
  13. * @author lch
  14. *
  15. */
  16. public class Block extends Rectangle {
  17. // 游戏场景
  18. private GameScene mGameScene;
  19. // 此block的颜色类型,白色还是黑色?
  20. private int colorType;
  21. // block 所在的行
  22. private int row;
  23. // block 所在的列
  24. private int column;
  25.  
  26. // ======================get&set========================
  27. public int getRow() {
  28. return row;
  29. }
  30. public void setRow(int row) {
  31. this.row = row;
  32. }
  33. public int getColumn() {
  34. return column;
  35. }
  36. public int getColorType() {
  37. return colorType;
  38. }
  39. // =====================================================
  40.  
  41. /**
  42. * 构造器1,初始化blocks时用到
  43. * @param pGameScene 游戏场景
  44. * @param row block所在的行
  45. * @param column block所在的列
  46. * @param pWidth block的宽
  47. * @param pHeight block的高
  48. * @param blackIndex 用来确定是否是黑块,如果blackIndex == column时设为黑块
  49. * @param pVertexBufferObjectManager
  50. */
  51. public Block(GameScene pGameScene, int row, int column, float pWidth,
  52. float pHeight, int blackIndex,
  53. VertexBufferObjectManager pVertexBufferObjectManager) {
  54. super(column * pWidth, (3 - row) * pHeight, pWidth - 1, pHeight - 1,
  55. pVertexBufferObjectManager);
  56. this.mGameScene = pGameScene;
  57. this.row = row;
  58. this.column = column;
  59. if (row == 0) {
  60. // 第一行设置为黄块
  61. this.setColor(Color.YELLOW);
  62. } else {
  63. // 初始化block的颜色数据,是白块还是黑块?
  64. initBlockData(column, blackIndex);
  65. }
  66. // 设置可以相应触碰事件
  67. this.setIgnoreTouch(false);
  68. }
  69.  
  70. /**
  71. * 构造器2,新增blocks时用到
  72. * @param pGameScene 游戏场景
  73. * @param column block所在的列
  74. * @param pWidth block的宽
  75. * @param pHeight block的高
  76. * @param blackIndex 来确定是否是黑块,如果blackIndex == column时设为黑块
  77. * @param pVertexBufferObjectManager
  78. */
  79. public Block(GameScene pGameScene, int column, float pWidth, float pHeight,
  80. int blackIndex, VertexBufferObjectManager pVertexBufferObjectManager) {
  81. super(column * pWidth, 0, pWidth - 1, pHeight - 1,
  82. pVertexBufferObjectManager);
  83. this.mGameScene = pGameScene;
  84. this.column = column;
  85. // 初始化block的颜色数据,是白块还是黑块?
  86. initBlockData(column, blackIndex);
  87. // 设置可以相应触碰事件
  88. this.setIgnoreTouch(false);
  89. }
  90.  
  91. /**
  92. * 初始化block的颜色数据,是白块还是黑块?
  93. * @param column
  94. * @param blackIndex
  95. */
  96. private void initBlockData(int column, int blackIndex) {
  97. if (blackIndex == column) {
  98. // 设置为黑块
  99. this.setColor(Color.BLACK);
  100. this.colorType = ConstantUtil.COLOR_BLACK;
  101. } else {
  102. // 设置为白块
  103. this.setColor(Color.WHITE);
  104. this.colorType = ConstantUtil.COLOR_WHITE;
  105. }
  106. }
  107.  
  108. @Override
  109. public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
  110. float pTouchAreaLocalX, float pTouchAreaLocalY) {
  111. // 触碰事件监听
  112. if (pSceneTouchEvent.isActionDown()) {
  113. // 点击到Block时进行的逻辑处理
  114. mGameScene.touchBlock(this);
  115. }
  116. return true;
  117. }
  118. }

  

  1. package com.orange.block.entity;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5.  
  6. import com.orange.entity.group.EntityGroup;
  7. import com.orange.entity.modifier.ScaleModifier;
  8. import com.orange.entity.primitive.Rectangle;
  9. import com.orange.entity.sprite.AnimatedSprite;
  10. import com.orange.entity.sprite.ButtonSprite;
  11. import com.orange.entity.sprite.ButtonSprite.OnClickListener;
  12. import com.orange.entity.text.Text;
  13. import com.orange.res.FontRes;
  14. import com.orange.util.color.Color;
  15. import com.orange.block.control.TimerTool;
  16. import com.orange.block.res.Res;
  17. import com.orange.block.scene.GameScene;
  18. import com.orange.block.util.ConstantUtil;
  19. import com.orange.block.util.SharedUtil;
  20.  
  21. /**
  22. * 失败界面
  23. *
  24. * @author lch
  25. *
  26. */
  27. public class FailGroup extends EntityGroup {
  28.  
  29. private GameScene mGameScene;
  30. private Rectangle bgRect;
  31.  
  32. private AnimatedSprite titelSprite;
  33. private AnimatedSprite modelSprite;
  34.  
  35. private ButtonSprite btn_back; // 返回按钮
  36. private ButtonSprite btn_again;// 重来按钮
  37.  
  38. private Text txt_big;
  39. private Text txt_small;
  40.  
  41. public FailGroup(float pWidth, float pHeight, GameScene pGameScene) {
  42. super(pWidth, pHeight, pGameScene);
  43. this.mGameScene = pGameScene;
  44. initView();
  45. }
  46.  
  47. private void initView() {
  48. // 背景
  49. bgRect = new Rectangle(0, 0, this.getWidth(), this.getHeight(),
  50. this.getVertexBufferObjectManager());
  51. this.attachChild(bgRect);
  52. bgRect.setColor(Color.RED);
  53. // 标题 “别踩白块儿”
  54. titelSprite = new AnimatedSprite(0, 10, Res.GAME_TITEL,
  55. this.getVertexBufferObjectManager());
  56. titelSprite.setRightPositionX(this.getRightX() - 10);
  57. this.attachChild(titelSprite);
  58.  
  59. // 模式 “经典模式”
  60. modelSprite = new AnimatedSprite(0, 150, Res.GAME_MODEL,
  61. this.getVertexBufferObjectManager());
  62. modelSprite.setCentrePositionX(this.getCentreX());
  63. this.attachChild(modelSprite);
  64.  
  65. // 大字
  66. txt_big = new Text(0, modelSprite.getBottomY() + 130,
  67. FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
  68. this.getVertexBufferObjectManager());
  69. this.attachChild(txt_big);
  70. txt_big.setScale(1.9f);
  71. // 小字
  72. txt_small = new Text(0, txt_big.getBottomY() + 30,
  73. FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
  74. this.getVertexBufferObjectManager());
  75. this.attachChild(txt_small);
  76. txt_small.setScale(0.7f);
  77. // 返回按钮
  78. btn_back = new ButtonSprite(80, 0, Res.BTN_BACK,
  79. this.getVertexBufferObjectManager());
  80. btn_back.setBottomPositionY(this.getBottomY() - 50);
  81. btn_back.setIgnoreTouch(false);
  82. this.attachChild(btn_back);
  83. btn_back.setOnClickListener(onClickListener);
  84. // 重来按钮
  85. btn_again = new ButtonSprite(0, 0, Res.BTN_AGAIN,
  86. this.getVertexBufferObjectManager());
  87. btn_again.setRightPositionX(this.getRightX() - 80);
  88. btn_again.setBottomPositionY(this.getBottomY() - 50);
  89. btn_again.setIgnoreTouch(false);
  90. this.attachChild(btn_again);
  91. btn_again.setOnClickListener(onClickListener);
  92.  
  93. resetView();
  94. }
  95.  
  96. public void showView() {
  97. setBtnEnable(true);
  98. this.setVisible(true);
  99. updateBigTxt("失败了!");
  100.  
  101. if (SharedUtil.getRecord(getActivity()) > 0) {
  102. TimerTool mTimerTool = mGameScene.getmTimerTool();
  103. updateSmallTxt("最佳: "
  104. + mTimerTool.millisToTimer(SharedUtil
  105. .getRecord(getActivity())));
  106. }
  107.  
  108. ScaleModifier scaleModifier = new ScaleModifier(0.2f, 0.0f, 1.0f);
  109. this.registerEntityModifier(scaleModifier);
  110.  
  111. }
  112.  
  113. private void updateBigTxt(String pText) {
  114. txt_big.setText(pText);
  115. txt_big.setCentrePositionX(this.getCentreX());
  116. }
  117.  
  118. private void updateSmallTxt(String pText) {
  119. txt_small.setText(pText);
  120. txt_small.setCentrePositionX(this.getCentreX());
  121. }
  122.  
  123. private OnClickListener onClickListener = new OnClickListener() {
  124.  
  125. @Override
  126. public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
  127. float pTouchAreaLocalY) {
  128. if (btn_back == pButtonSprite) {
  129. showDialog();
  130. } else if (btn_again == pButtonSprite) {
  131. resetView();
  132. mGameScene.resetGame();
  133. }
  134.  
  135. }
  136.  
  137. };
  138.  
  139. private void resetView(){
  140. this.setScale(0);
  141. this.setVisible(false);
  142. setBtnEnable(false);
  143. }
  144.  
  145. private void setBtnEnable(boolean isEnable) {
  146. btn_back.setEnabled(isEnable);
  147. btn_again.setEnabled(isEnable);
  148. }
  149.  
  150. /**
  151. * 退出游戏确认对话框
  152. */
  153. private void showDialog() {
  154. getActivity().runOnUiThread(new Runnable() {
  155.  
  156. @Override
  157. public void run() {
  158.  
  159. new AlertDialog.Builder(getActivity())
  160. .setTitle("退出游戏")
  161. .setMessage("是否要退出游戏!")
  162. .setPositiveButton("确定",
  163. new DialogInterface.OnClickListener() {
  164.  
  165. @Override
  166. public void onClick(DialogInterface dialog,
  167. int which) {
  168. getActivity().finish();
  169.  
  170. }
  171. }).setNegativeButton("取消", null).show();
  172. }
  173. });
  174. }
  175. }
  1. package com.orange.block.entity;
  2.  
  3. import android.app.AlertDialog;
  4. import android.content.DialogInterface;
  5.  
  6. import com.orange.entity.group.EntityGroup;
  7. import com.orange.entity.primitive.Rectangle;
  8. import com.orange.entity.sprite.AnimatedSprite;
  9. import com.orange.entity.sprite.ButtonSprite;
  10. import com.orange.entity.sprite.ButtonSprite.OnClickListener;
  11. import com.orange.entity.text.Text;
  12. import com.orange.res.FontRes;
  13. import com.orange.util.color.Color;
  14. import com.orange.block.control.TimerTool;
  15. import com.orange.block.res.Res;
  16. import com.orange.block.scene.GameScene;
  17. import com.orange.block.util.ConstantUtil;
  18. import com.orange.block.util.SharedUtil;
  19.  
  20. /**
  21. * 成功界面
  22. *
  23. * @author lch
  24. *
  25. */
  26. public class SuccGroup extends EntityGroup {
  27.  
  28. private GameScene mGameScene;
  29. private Rectangle bgRect;
  30.  
  31. private AnimatedSprite titelSprite;
  32. private AnimatedSprite modelSprite;
  33.  
  34. private ButtonSprite btn_back; // 返回按钮
  35. private ButtonSprite btn_again;// 重来按钮
  36.  
  37. private Text txt_big;
  38. private Text txt_small;
  39.  
  40. public SuccGroup(float pWidth, float pHeight, GameScene pGameScene) {
  41. super(pWidth, pHeight, pGameScene);
  42. initView();
  43. this.mGameScene = pGameScene;
  44. }
  45.  
  46. private void initView() {
  47. // 背景
  48. bgRect = new Rectangle(0, 0, this.getWidth(), this.getHeight(),
  49. this.getVertexBufferObjectManager());
  50. this.attachChild(bgRect);
  51. bgRect.setColor(Color.GREEN);
  52. // 标题 “别踩白块儿”
  53. titelSprite = new AnimatedSprite(0, 10, Res.GAME_TITEL,
  54. this.getVertexBufferObjectManager());
  55. titelSprite.setRightPositionX(this.getRightX() - 10);
  56. this.attachChild(titelSprite);
  57. titelSprite.setVisible(false);
  58.  
  59. // 模式 “经典模式”
  60. modelSprite = new AnimatedSprite(0, 150, Res.GAME_MODEL,
  61. this.getVertexBufferObjectManager());
  62. modelSprite.setCentrePositionX(this.getCentreX());
  63. this.attachChild(modelSprite);
  64. modelSprite.setVisible(false);
  65.  
  66. // 大字
  67. txt_big = new Text(0, modelSprite.getBottomY() + 100,
  68. FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
  69. this.getVertexBufferObjectManager());
  70. this.attachChild(txt_big);
  71. txt_big.setScale(1.5f);
  72. txt_big.setVisible(false);
  73. // 小字
  74. txt_small = new Text(0, txt_big.getBottomY() + 10,
  75. FontRes.getFont(ConstantUtil.FONT_NAME_RESULT), "", 15,
  76. this.getVertexBufferObjectManager());
  77. this.attachChild(txt_small);
  78. txt_small.setScale(0.7f);
  79. txt_small.setVisible(false);
  80. // 返回按钮
  81. btn_back = new ButtonSprite(80, 0, Res.BTN_BACK,
  82. this.getVertexBufferObjectManager());
  83. btn_back.setBottomPositionY(this.getBottomY() - 50);
  84. btn_back.setIgnoreTouch(false);
  85. this.attachChild(btn_back);
  86. btn_back.setOnClickListener(onClickListener);
  87. btn_back.setVisible(false);
  88. // 重来按钮
  89. btn_again = new ButtonSprite(0, 0, Res.BTN_AGAIN,
  90. this.getVertexBufferObjectManager());
  91. btn_again.setRightPositionX(this.getRightX() - 80);
  92. btn_again.setBottomPositionY(this.getBottomY() - 50);
  93. btn_again.setIgnoreTouch(false);
  94. this.attachChild(btn_again);
  95. btn_again.setOnClickListener(onClickListener);
  96. btn_again.setVisible(false);
  97. }
  98.  
  99. public void showItems(boolean pVisible) {
  100. titelSprite.setVisible(pVisible);
  101. modelSprite.setVisible(pVisible);
  102. txt_big.setVisible(pVisible);
  103. txt_small.setVisible(pVisible);
  104. btn_back.setVisible(pVisible);
  105. btn_again.setVisible(pVisible);
  106.  
  107. if (pVisible) {
  108. TimerTool mTimerTool = mGameScene.getmTimerTool();
  109. updateBigTxt(mTimerTool.millisToTimer(mTimerTool
  110. .getMillisPass()));
  111.  
  112. long mMillisPass = mTimerTool.getMillisPass();
  113.  
  114. if (mMillisPass < SharedUtil.getRecord(getActivity())
  115. || SharedUtil.getRecord(getActivity()) == 0) {
  116. // 新记录
  117. updateSmallTxt("新记录");
  118. SharedUtil.setRecord(getActivity(), mMillisPass);
  119.  
  120. } else {
  121.  
  122. updateSmallTxt("最佳: "
  123. + mTimerTool.millisToTimer(SharedUtil
  124. .getRecord(getActivity())));
  125. }
  126. }
  127.  
  128. }
  129.  
  130. public void updateBigTxt(String pText) {
  131. txt_big.setText(pText);
  132. txt_big.setCentrePositionX(this.getCentreX());
  133. }
  134.  
  135. public void updateSmallTxt(String pText) {
  136. txt_small.setText(pText);
  137. txt_small.setCentrePositionX(this.getCentreX());
  138. }
  139.  
  140. private OnClickListener onClickListener = new OnClickListener() {
  141.  
  142. @Override
  143. public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX,
  144. float pTouchAreaLocalY) {
  145. if (btn_back == pButtonSprite) {
  146. showDialog();
  147. } else if (btn_again == pButtonSprite) {
  148. mGameScene.resetGame();
  149. }
  150.  
  151. }
  152. };
  153.  
  154. /**
  155. * 退出游戏确认对话框
  156. */
  157. private void showDialog() {
  158. getActivity().runOnUiThread(new Runnable() {
  159.  
  160. @Override
  161. public void run() {
  162.  
  163. new AlertDialog.Builder(getActivity())
  164. .setTitle("退出游戏")
  165. .setMessage("是否要退出游戏!")
  166. .setPositiveButton("确定",
  167. new DialogInterface.OnClickListener() {
  168.  
  169. @Override
  170. public void onClick(DialogInterface dialog,
  171. int which) {
  172. getActivity().finish();
  173.  
  174. }
  175. }).setNegativeButton("取消", null).show();
  176. }
  177. });
  178. }
  179. }

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

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

codes:

  1. public class Test {
  2. private int fAmount;
  3. private String fCurrency;
  4.  
  5. public Test(int amount, String currency) {
  6. fAmount= amount;
  7. fCurrency= currency;
  8. }
  9.  
  10. public int amount() {
  11. return fAmount;
  12. }
  13.  
  14. public String currency() {
  15. return fCurrency;
  16. }
  17.  
  18. public Test add(Test m) {
  19. return new Test(amount()+m.amount(), currency());
  20. }
  21.  
  22. public boolean equals(Object anObject) {
  23. if (anObject instanceof Test) {
  24. Test aMoney= (Test)anObject;
  25. return aMoney.currency().equals(currency())
  26. && amount() == aMoney.amount();
  27. }
  28. return false;
  29. }
  30. }

步骤

耗时

百分比

需求分析

 20min  3.8%

设计

50min   9.6%

代码实现

300min   57.7%

测试

120min   23.1%

分析总结

 30min  5.8%

java第三次实验报告的更多相关文章

  1. 南京邮电大学java第三次实验报告

    实 验 报 告 ( 2017 / 2018学年 第2学期) 课程名称 JAVA语言程序设计 实验名称 Java集成开发环境的安装与使用. Java变量.表达式与控制结构 实验时间 2018 年 4 月 ...

  2. 20165210 Java第三次实验报告

    20165210 实验二 敏捷开发与XP实践 一.敏捷开发与XP实践-1 实验要求: http://www.cnblogs.com/rocedu/p/4795776.html, Eclipse的内容替 ...

  3. 20145320《Java程序设计》第三次实验报告

    20145320<Java程序设计>第三次实验报告 北京电子科技学院(BESTI)实验报告 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.22 15: ...

  4. 实验三《Java面向对象程序设计》实验报告

    20162308 实验三<Java面向对象程序设计>实验报告 实验内容 XP基础 XP核心实践 IDEA工具学习 密码学算法基础 实验步骤 (一)Refactor/Reformat使用 p ...

  5. 2017-2018-2 20165236 实验三《Java面向对象程序设计》实验报告

    2017-2018-2 20165236 实验三<Java面向对象程序设计>实验报告 一.实验报告封面 课程:Java程序设计            班级:1652 姓名:郭金涛     ...

  6. 2017-2018-2 20165318 实验三《Java面向对象程序设计》实验报告

    2017-2018-2 20165318 实验三<Java面向对象程序设计>实验报告 一.实验报告封面 课程:Java程序设计        班级:1653班        姓名:孙晓暄  ...

  7. 20155201 实验三《Java面向对象程序设计》实验报告

    20155201 实验三<Java面向对象程序设计>实验报告 一.实验内容 XP基础 XP核心实践 相关工具 二.实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门 ...

  8. 20155217 《Java程序设计》第三次实验报告

    20155217 <Java程序设计>第三次实验报告 实验内容 XP基础 XP核心实践 相关工具 实验要求 没有Linux基础的同学建议先学习<Linux基础入门(新版)>&l ...

  9. 20155218 《Java程序设计》实验三(Java面向对象程序设计)实验报告

    20155218 <Java程序设计>实验三(Java面向对象程序设计)实验报告 一.实验内容及步骤 (一)编码标准 在IDEA中使用工具(Code->Reformate Code) ...

随机推荐

  1. vmstat命令参数详解

    转自:https://www.cnblogs.com/ggjucheng/archive/2012/01/05/2312625.html vmstat命令是最常见的Linux/Unix监控工具,可以展 ...

  2. mysql获取随机题目、排序

    mysql排序问题(对字符串类型数据进行排序)对普通数字字符串字段排序:select * from qq ORDER BY score*1 DESC,time*1 ASC 一.在mysql操作中我们经 ...

  3. awk练习笔记

    题目数据如下: Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201Susan ...

  4. composer install 失败,无法用 unzip 解压归档、proc_open() 函数未支持

    前言 记得最近好像有不只一个朋友问过 composer install 安装依赖时出现异常,导致项目无法运行.下面简单记录一下其中 2 个比较频繁问题的解决办法. 问题 & 解决 1.unzi ...

  5. Vivado中xilinx_BRAM IP核使用

     Vivado2017.2 中BRAM版本为 Block Memory Generator Specific Features  8.3 BRAM IP核包括有5种类型: Single-port RA ...

  6. Android JS interaction

    WebView web; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInst ...

  7. 【转载】注释AFX_MSG_MAP,AFX_DATA,AFX_DATA_MAP , Afx_MSG等宏不能删除

    原文: BEGIN_MESSAGE_MAP(CMy1Dlg, CDialog) //{{AFX_MSG_MAP(CMy1Dlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON ...

  8. 【转载】COM 组件设计与应用(九)——IDispatch 接口 for VC6.0

    原文: http://vckbase.com/index.php/wv/1224.html 一.前言 终于写到了第九回,我也一直期盼着写这回的内容耶,为啥呢?因为自动化(automation)是非常常 ...

  9. 4 伪ajax:jsonp、cors 跨域请求

    一.同源策略 https://www.cnblogs.com/yuanchenqi/articles/7638956.html 同源策略(Same origin policy)是一种约定,它是浏览器最 ...

  10. 【HNOI2013】游走

    题面 题解 图上的期望大部分是\(dp\),无向图的期望大部分是高斯消元 设\(f[i]\)表示走到点\(i\)的期望,\(d[i]\)表示\(i\)的度,\(to(i)\)表示\(i\)能到达的点集 ...