Advertisement
amigojapan

problem in programming lesson for beginner

Feb 16th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. ken lesson
  2. I was playing a programming game with someone in a lesson, and he wrote something like this:
  3. while(true){
  4. if(enemy_is_close()){
  5. attack();point_to_enemy();move_towards_enemy();
  6. }
  7. }
  8. I told him he had to change it to
  9. while(true){
  10. point_to_enemy();move_towards_enemy();
  11. if(enemy_is_close()){
  12. attack();
  13. }
  14. }
  15.  
  16. the enemies were far away and they were not moving, and the player had to move towards the enemies to solve the puzzle, but the way he had it, it would not move twords the enemies cause the enemies were not close.
  17.  
  18. the only way I can think of explaining this is to step thru the program and show him the actions of the program… any ideas on how I can better explain this? the person I am teaching is a total beginner to programming….
  19.  
  20. Mistaken:
  21. repeat forever {
  22. If the distance of the enemy is close {
  23. Attack
  24. Turn a hero to the nearest enemy
  25. Hero advances forward
  26. }
  27. }
  28.  
  29. correct:
  30. repeat forever {
  31. Turn a hero to the nearest enemy
  32. Hero advances forward
  33. If the distance of the enemy is close {
  34. Attack
  35. }
  36. }
  37.  
  38. 間違ってる:
  39. ずっと繰り返す {
  40. もし、敵の距離がひと遠いならば {
  41. 攻撃する
  42. ヒーローを一番近い敵に向かせる
  43. ヒーローがひとます前に進む
  44. }
  45. }
  46.  
  47. 正しい:
  48. ずっと繰り返す {
  49. ヒーローを一番近い敵に向かせる
  50. ヒーローがひとます前に進む
  51. もし、敵の距離がひと遠いならば {
  52. 攻撃する
  53. }
  54. }
  55. KaffeeJunky123: I guess I will just put the enemies in a diagonal line so that there is use for the point to enemy command
  56. https://lichess.org/editor/1b6/8/8/8/5Q2/8/7b/8_w_KQkq_-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement