programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
Eg, I added 4 element inside the list which are a,b,c,d.
Roll dice value from -3,-2,-1, 0, 1, 2

i will roll dice each time run the program.

if roll dice value is 2 then it will display c
else
if roll dice value is -1 then it will display b
else
if the current index is 1 and roll dice value = -3 it will return 1-3 = -2 (means that need to move backward 1 time and move ahead 2 times)
else
the roll dice value is 0, it will remain the the position.

How can i do that?

Ranch Hand
Posts: 954
4
• 1
• Number of slices to send:
Optional 'thank-you' note:
You requirment is confusing.. Could you please explain again?

alex ja
Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
At the starting point and also upon successful completion of each mission, the player will “roll dice” to determine the number of steps and direction to take to the next station he will visit.
The dice roll will generate a random number with one of the following values: -2, -1, 1, 2, or 3 (a negative number denotes that the player will move backwards to earlier stations).
er.PNG

Saloon Keeper
Posts: 14501
325
• Number of slices to send:
Optional 'thank-you' note:
If you're working with linked stations, you can call moveAhead and moveBack recursively: the base case is moveAhead(0). In this case just return this. For moveAhead(x), where x>0, call nextStation.moveAhead(x-1).

alex ja
Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
It is possible to do like this

I need to keep looping until the user reach the finish point...

Stephan van Hulst
Saloon Keeper
Posts: 14501
325
• Number of slices to send:
Optional 'thank-you' note:
Yes, that's perfectly fine, except I would negate the moveBack() argument, because it doesn't make sense to call moveBack() with a negative value. You can also directly return the invocation results:

alex ja
Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
Okay, thanks.
If I am facing any problem, can I ask you for your guidance?

Stephan van Hulst
Saloon Keeper
Posts: 14501
325
• Number of slices to send:
Optional 'thank-you' note:
If it relates to this issue, you can just continue in this thread.

If you have a different problem, start a new topic and we'll see if we can help you.

alex ja
Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
i used this method but it will return arrayindexoutofbound exception ;(

i want it works like this.
EG. Station A,Station B,Station C,Station D,Station E,Station F

if move 4 step from station A = station E
if move 3 step from station E = station D
if move -3 step from station A = station C

Stephan van Hulst
Saloon Keeper
Posts: 14501
325
• Number of slices to send:
Optional 'thank-you' note:
Surely, -3 from station A should land you on station D.

alex ja
Greenhorn
Posts: 16
• Number of slices to send:
Optional 'thank-you' note:
I want to do something like the picture show, i just wrote the code as shown above to try an error only.
1.PNG

Stephan van Hulst
Saloon Keeper
Posts: 14501
325
• Number of slices to send:
Optional 'thank-you' note:
I understand what you want, but we can't help you if you don't show us more code, and tell us exactly what's going wrong.

 I don't always make ads but when I do they're tiny the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising