Wednesday, 28 August 2013

How to write this with less code?

How to write this with less code?

i'm trying to make a game. when a picture is displayed the user needs to
guess what it is. there are 4 possible choises only one is correct. i
don't want the correct answer to be in the same place for every photo so i
use a tween to move the buttons as if the correct aswer is elsewhere
although the buttons are the same. i need an if for every level and it's a
lot of code. Can anybody show me another method to white this in less code
lines? thx
if (level == 1) {
GAME.varianta1.text = "Ladybug";
GAME.varianta2.text = "Bee";
GAME.varianta3.text = "Beattle";
GAME.varianta4.text = "Fly";
TweenLite.to(GAME.variante.varianta_gresita1, 0, {x:1025.75, y:708.5});
TweenLite.to(GAME.variante.varianta_gresita2, 0, {x:1043.35, y:555.9});
TweenLite.to(GAME.variante.varianta_gresita3, 0, {x:834.3, y:710.9});
TweenLite.to(GAME.variante.varianta_corecta, 0, {x:835.15, y:633.7});
}
if (level == 2) {
GAME.varianta1.text = "x";
GAME.varianta2.text = "y";
GAME.varianta3.text = "z";
GAME.varianta4.text = "w";
TweenLite.to(GAME.variante.varianta_gresita1, 0, {x:1025.75, y:708.5});
TweenLite.to(GAME.variante.varianta_gresita2, 0, {x:1043.35, y:555.9});
TweenLite.to(GAME.variante.varianta_gresita3, 0, {x:834.3, y:710.9});
TweenLite.to(GAME.variante.varianta_corecta, 0, {x:835.15, y:633.7});
}
///...................\\\
if (level == 100) {
GAME.varianta1.text = "a";
GAME.varianta2.text = "b";
GAME.varianta3.text = "c";
GAME.varianta4.text = "d";
TweenLite.to(GAME.variante.varianta_gresita1, 0, {x:1025.75, y:708.5});
TweenLite.to(GAME.variante.varianta_gresita2, 0, {x:834.3, y:710.9});
TweenLite.to(GAME.variante.varianta_gresita3, 0, {x:835.15, y:633.7});
TweenLite.to(GAME.variante.varianta_corecta, 0, {x:1043.35, y:555.9});
}

No comments:

Post a Comment