Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Counting steps (http://www.alice.org/community/showthread.php?t=6763)

Laur07 06-14-2011 07:59 PM

Counting steps
 
I am having difficulty with the "increment" function. So for my project :[B]Your program must also count the number of steps it took for the wolf to catch the bunny. If it took more than 10 steps, the wolf should say "That was tough, but this bunny was worth it!" or something similar, after it eats the bunny, otherwise the wolf should say "That was too easy, give me a challenge next time!" [/B]
I created a new variable in the "world properties" called steps because i need to be able to count how many steps the wolf takes but i don't really know the next steps to make it actually count and in order to make the "IF" statement in the end .... Anyone have an idea how this works? I really appreciate all the help i have been getting!

legolizard 06-14-2011 08:35 PM

Well in in your walking method at the very end of the method(after the wolf has taken a step) you would increment the variable you have created. Next you would put an if statment that checked to see:

[CODE]
if(world.steps==some number)
{
//That was easy.
}
else if(world.steps==some [B]other[/B] number)
{
//That was easy.
}
else
{
//do nothing.
}[/CODE]

You would also have to change the number of times the bunny steps so the wolf could catch it; I don't know if you already know what your going to do for that.:)


All times are GMT -5. The time now is 10:27 PM.

Copyright ©2017, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.