Part1

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

不。如果bug遇到墙壁或者岩石之类的东西就会停留在原地。

2. In which direction does the bug move?

  • 如果bug的前方没有障碍(墙壁或岩石)的话,bug将直线前进
  • 如果bug的前方有障碍,bug会多次向右旋转45度直到前方无障碍物为止。

3. What does the bug do if it does not move?

如果bug不动的话它将做向右旋转45度的运动。

4. What does a bug leave behind when it moves?

bug走过的地方都会留下一朵花。

5. 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会原地向右旋转45度。
  • 当bug不是面对边缘且前方没有障碍的话,bug会朝着面对方向移动。

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

bug会在石头的正前方停住,然后原地向右旋转45度,直到前方没有障碍。

7. Does a flower move?

花不会移动。

8. What behavior does a flower have?

花的颜色会有变化,从刚开始的红色到后来的黑色。

9. Does a rock move or have any other behavior?

岩石不会移动且没有其他的动作。

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

不可以。同一个网格内,同一时间只能有一个actor

Test the setDirection method with the following inputs and complete the table, giving the compass direction each input represents.

DegressCompass Direction
0
45东北
90
135东南
180
225西南
270西
315西北
360

1. Move a bug to a different location using the moveTo method. In which directions can you move it? How far can you move it? What happens if you try to move the bug outside the grid?

使用moveTo()方法,我可以将bug移动到网格中空的(即无障碍)的任意方向,可以移动到为空的任意位置。如果我尝试将bug移动到网格外面系统将会抛出异常。

2. Change the color of a bug, a flower, and a rock. Which method did you use?

可以用setColor()方法来改变bug,花,岩石的颜色。

3. Move a rock on top of a bug and then move the rock again. What happened to the bug?

当我们将岩石移动到bug上面之后,在网格上我们只看得到岩石,但当我们将岩石移走的时候,我们发现bug不见了,所以bug被该岩石消灭了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值