Grid 1 Part 1

-  Does the bug always move to a new location? Explain. 

  不能。调用 bug 的 `canMove` 方法返回一个当前 bug 能否移动到新位置的布尔值。当有 rock 对象或 bug 对象位于 bug 的下一前进位置时,`canMove` 方法返回 `false` ,bug 只能选择执行 `turn` 方法转向;当 bug 的八邻域都有 rock 对象或 bug 对象时,bug 不能移动到新位置。

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110191943075.png" alt="image-20191110191943075" style="zoom:67%;" />

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110192009397.png" alt="image-20191110192009397" style="zoom:67%;" />

  ![image-20191110193326797](C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193326797.png)

  

- In which direction does the bug move?

  当 bug 触角方向上的最近一格没有 rock 对象或 bug 对象时,bug 沿触角方向前进;

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193418279.png" alt="image-20191110193418279" style="zoom:67%;" />

  当 bug 触角方向上的最近一格有 rock 对象或 bug 对象时,bug 沿顺时针方向旋转 45 度,寻找没有障碍物的方向,沿该方向移动。

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193432041.png" alt="image-20191110193432041" style="zoom:67%;" />

  

- What does the bug do if it does not move?

  当不能移动时,bug 每次沿顺时针旋转 45 度。

  

- What does a bug leave behind when it moves?

  当 bug 离开时,前一位置生成一个 Flower 对象。

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193456412.png" alt="image-20191110193456412" style="zoom:67%;" />

  

- What happens when the bug is at an edge of the grid? (Consider whether the bug is facing the edge as well as whether the bug is facing some other direction when answering this question.)

  当 bug 位于边缘且触角方向朝向边缘时, bug 调用 `turn` 方法沿顺时针旋转45度,直至 bug 的触角方向朝向 grid 后,正常移动;

  当 bug 位于边缘但触角方向不朝向边缘时,若 bug 的触角方向没有障碍物, bug 沿触角方向正常移动,反之旋转。

  

- What happens when a bug has a rock in the location immediately in front of it?

  当 bug 触角方向上的最近一格有 rock 对象或 bug 对象时,bug 沿顺时针方向旋转 45 度。

  

- Does a flower move?

  点击 Step 或 Run 时 Flower 对象不移动,但可以通过点击 Flower 对象,调用 `moveTo` 方法,输入参数 (x,y),将该 Flower 对象移动到 (x,y) 位置。

  

- What behavior does a flower have?

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110191141370.png" alt="image-20191110191141370" style="zoom: 67%;" />

  `getColor` 方法返回 Flower 对象的颜色;

  `getDirection` 方法返回 Flower 对象的方向;

  `getGrid` 方法返回 Flower 对象 Grid 属性值;

  `getLocation` 方法返回 Flower 对象当前的位置坐标;

  `moveTo` 方法输入参数 (x,y) 将 Flower 对象移动到 (x,y) 位置;

  `removeSelfFromGrid` 方法移除 Flower 对象;

  `setColor` 方法设置 Flower 对象的颜色;

  `setDirection` 方法输入角度设置 Flower 对象的方向;

  `toString` 方法输出 Flower 对象的属性于字符串。

  

- Does a rock move or have any other behavior?

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193548184.png" alt="image-20191110193548184" style="zoom:67%;" />

  `getColor` 方法返回 Rock 对象的颜色;

  `getDirection` 方法返回 Rock 对象的方向;

  `getGrid` 方法返回 Rock 对象 Grid 属性值;

  `getLocation` 方法返回 Rock 对象当前的位置坐标;

  `moveTo` 方法输入参数 (x,y) 将 Rock 对象移动到 (x,y) 位置;

  `removeSelfFromGrid` 方法移除 Rock 对象;

  `setColor` 方法设置 Rock 对象的颜色;

  `setDirection` 方法输入角度设置 Rock 对象的方向;

  `toString` 方法输出 Rock 对象的属性于字符串。

  

- Can more than one actor (bug, flower, rock) be in the same location in the grid at the same time?

  不能有多于一个 actor 同时位于同一 grid。当 bug 前进到有 Flower 对象的 grid 时,Flower 对象被移除后 bug 移动到该 grid;当 bug 的前进方向上有 bug 对象或 rock 对象时,bug 不能前进,而是转向;只有在 grid 为空时,才能在该 grid 生成一个 actor 对象。

  <img src="C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193742900.png" alt="image-20191110193742900" style="zoom:67%;" />

  ![image-20191110193811743](C:\Users\DELL\AppData\Roaming\Typora\typora-user-images\image-20191110193811743.png)

  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值