Awesome! The next step is oneliner or code golf
I’m loving these concept levels, there such good levels, wow! I got the 6 second bonus (just) I love the things Pender says when she hits ( should I say
attacks()) the ball. Great level it’s really satisfying the way she just gets to the ball to hit it on both sides. Wonderful level Catsync.
Is it meant to be Ping Pong instead of Pong Pong, just wondering, I’m from England so maybe It’s different? I just wanted to say in case it was a typo.
Nope it’s not a typo. Ping - the first player hits the ball, Pong - the second, Ping - the first. So in our case it’s just Pong Pong Pong …
Ohhhhh, cool sorry. (((20cjhatafjcherssj)0)
I did it in 2 lines.
I used one line. (20 char)
never mind, I found out how to do it in 1 line.
I use this code: 30 lines code or less
Is it OK?
enemy = hero.findNearestEnemy()
Can you show how you do it?
no, but here’s what you could do. when you say to move right or left, instead of repeating it, add the number of times you want it to happen in the parenthesis. Also, say “fetch” before the while loop. and, you don’t need to find if the enemy exists, cause really, this is a dungeon level. you don’t need to find if the enemy exists.
tips for those who want to make it with less lines
- moveRight can take number as parameter(same for other move functions)
hero.moveRight() hero.moveRight() hero.moveRight()
is the same as
2) moveRight() can take negative number as parameter
is the same aas
And one more tip.
Are you sure you need while cycle? Maybe for cycle is better?
You can complete the level in “one line” if you seriously abuse a for-loop. Whatever it is that counts the lines only counts a for-loop declaration as one line, and you can do a theoretically infinite number of things inside of a for-loop declaration.
Consider the first statement in a for-loop. This statement is executed once before the body of the loop. That’s usually used to declare an iteration variable, but you can use it here to say fetch.
The second statement is a condition, just like in a while loop, and it’s evaluated before every iteration of the loop. This condition is usually used to test the value of an iteration variable, but you can just set it to true.
The third statement is executed at the end of every iteration. Usually this is used to increment an iteration variable, but you can use it here to run the body of your code. Condensing this to one line might take some effort, but through the creative use of ternary expressions and logical operators, you should be able to do pretty much anything.
I’d post my working code here, but I’m pretty sure that’s against the rules.