sgimenez / laby

Learn programming, playing with ants and spider webs ;-)
https://sgimenez.github.io/laby/
Other
98 stars 39 forks source link

How to use "if" instructions #24

Open jokhan opened 10 years ago

jokhan commented 10 years ago

Hello I don't know how to use the conditions when I need to use "if" in level "3a",could you tell me the answer?

sgimenez commented 10 years ago

You'll have to move before one of the spider webs and test with the look() function whether it's a real web or a small one (see the help message). If it's the real web the then part will be executed (you need to go backwards and find your way around to find the exit). If it's a small web, the else part will be executed, and you can go through it.

With the ocaml language the program should look like this (for other programming languages it's similar):

right();
forward();
left();
if look() = Web
then (
  left();
  forward();
  ...
)
else (
  forward();
  forward();
  left();
  ...
)

You just need to fill the blanks (“...”). Hope this helps!

jokhan commented 10 years ago

Thank you!I like this game

------------------ 原始邮件 ------------------ 发件人: "Stéphane Gimenez";notifications@github.com; 发送时间: 2013年9月19日(星期四) 晚上8:00 收件人: "sgimenez/laby"laby@noreply.github.com; 抄送: "紫骍"1472676083@qq.com; 主题: Re: [laby] For "if" (#24)

You'll have to move before one of the spider webs and test with the look() function whether it's a real web or a small one (see the help message). If it's the real web the 'then' part will be executed (you need to go backwards and find your way around to find the exit). If it's a small web you can go through it.

With the ocaml language the program should look like this (for other programming languages it's similar): right(); forward(); left(); if look() = Web then ( left(); forward(); ... ) else ( forward(); forward(); left(); ... )
You just need to fill the blanks (“...”). Hope this helps!

— Reply to this email directly or view it on GitHub.