-
- Part 3 设计文档
- 1.设计思路
- 2 Jumper类相关成员函数的介绍
- 3.设计细节部分
- 3.1 What will a jumper do if the location in front of it is empty, but the location two cells in front contains a flower or a rock?
- 3.2 What will a jumper do if the location two cells in front of the jumper is out of the grid?
- 3.3 What will a jumper do if it is facing an edge of the grid?
- 3.4 What will a jumper do if another actor (not a flower or a rock) is in the cell that is two cells in front of the jumper?
- 3.5 What will a jumper do if it encounters another jumper in its path?
- 3.6 Are there any other tests the jumper needs to make?
- 4 设计文档总结
- Part 3 设计文档
Part 3 设计文档
注:设计细节部分基于自己的设计思路回答
1.设计思路
1.1 基本需求
由题中所给已知需求可知,我们需自行创建一个名为jumper的actor,要求这个jumper可以在grid中一次跳跃两个单元格,并且在跳跃过程中如果遇到面前是石头或者花朵时候可以越过。
1.2 自由扩展部分
1.2.1 单步move
功能陈述:
- 假设有A、B、C、D一条直线上由近及远的四个点,若此时jumper位于A点,并且有向C跳跃的趋势;
- 假设C点上有一个石头,这个石头阻碍jumper完成跳跃
- 此时jumper自身可以通过调用move功能,往前只运行一步,随后完成跳跃,跳跃到D点。
- 当jumper位于边界点时也是如此,先向前move一步,随后进行方向的变更,继续进行跳跃
1.2.2 设置标记
功能陈述:
- 为了更加直观的显示出1.2.1的功能,在jumper每次完成一次move时候,会在move之前那个方格上留下一朵花;
- 花的颜色会随jumper的运动而逐渐加深颜色,并且会被jumper覆盖。
2 Jumper类相关成员函数的介绍
2.1 构造函数
2.2 act()函数
功能:选择Jumper进行move、jump、turn且jump优先级高于move
2.3 turn()函数
功能:当Jumper无法进行jump或者move时候进行turn,转换角度
2.4 move()函数与canMove()函数
功能:
1. move()函数:Jumper往前移动一步
2. canMove()函数:判断Jumper是否可以move
2.5 jump()函数与canJump()函数
功能:
1. jump()函数:Jumper往前移动两步
2. canJump()函数:判断Jumper是否可以jump
3.设计细节部分
3.1 What will a jumper do if the location in front of it is empty, but the location two cells in front contains a flower or a rock?
当运动过程中,假设有A、B、C、三个处于同一条直线上的单元格,且假设jumper此时位于A,且B为待放置实体单元格,C为待放置实体单元格,且运动趋势为A->C:
- 如果C上放置为石头,B为空白或者花,那么jumper会先移动到B,再跳跃过C;若B为石头,则jumper更改自身运动方向,不会再向C运动;
- 如果C上放置为花或者空白,此时,不管B上放置花还是石头,jumper都会完成跳跃,向前跳跃到C;
- 如图,jumper向前移动了1+2步,1步为move,2步为jump,A点为(5,5),B点为(4,5),C点为(3,5);
3.2 What will a jumper do if the location two cells in front of the jumper is out of the grid?
如果jumper距离边界有一个单元格时,先向前move一步,并在留下一朵花作为标记显示完成了move功能,随后改变自身方向,继续完成跳跃功能。
如图示部分:
- 当jumper到达花的位置,发现两个单元格过后会出出界
- 随后,jumper先向前move一步,留下花作为标记
- 调整方向,继续进行jump
3.3 What will a jumper do if it is facing an edge of the grid?
在我的设计中,当jumper已经到达边界时候,jumper会直接通过旋转改变方向,寻求到下一个可以进行跳跃的方向;
3.4 What will a jumper do if another actor (not a flower or a rock) is in the cell that is two cells in front of the jumper?
当jumper完成下一步跳跃时候,遇到另外一个jumper,假设有一条直线上A、B、C三个点,jumper_1位于A点,jumper_2位于B点或C点:
- 当jumper_2位于B点,那么jumper_1直接完成两步的跳跃;
- 当jumper_2位于C点,那么jumper_1向前move一步,随后完成跳跃;
- 如图所示,图示为jumper_2位于C(5,5)点,jumper_1位于A(3,5)点
3.5 What will a jumper do if it encounters another jumper in its path?
设有jumper_1、jumper_2两个实体:
- 当彼此背道而行时,互不干扰,如图:
- 当彼此面对面运动时,均把彼此当做障碍物,越过后继续前行,如图:
3.6 Are there any other tests the jumper needs to make?
需要,比如当jumper遇到一个bug时候如何运动。
4 设计文档总结
总体来说,完成jumper的设计还是比较有难度的,难点第一在于学习参考资料中函数的用法,难点二在于阅读英文文献,准确把握需求。难点三在于代码的编写过程中遇到的编译错误等问题;关于eclipse软件的学习还需要进一步掌握,同时也需要承认,使用eclipse确实是解决编译问题的不二选择。