Snakes and Ladders help
Author |
Message |
Feltie
|
Posted: Wed Jun 01, 2011 7:39 pm Post subject: Snakes and Ladders help |
|
|
What is it you are trying to achieve?
I want the game piece to go to the correct number when going up a level.
What is the problem you are having?
It works fine just going across but once it hits 10, it seems to go to a random spot.
I checked my formula and it should work.
Describe what you have tried to solve this problem
I tried playing around with the order of the things and the formula
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
View.Set ("graphics:800,750")
var roll, boardnum : string
var num, num1, x, y : int
var counter, counter1, counter2, counter3, counter4, counter5, counter6, counter7, counter8, counter9 : int := 0
var font : int
font := Font.New ("serif:14")
procedure board
for i : 1 .. 770 by 70
Draw.Line (0 + i, 0, 0 + i, 700, 7)
Draw.Line (0, 0 + i, 700, 0 + i, 7)
end for
for i : 1 .. 10
boardnum := intstr (i )
Draw.Text (boardnum, 2 + counter, 55, font, black)
counter := counter + 70
end for
for k : 11 .. 20
boardnum := intstr (k )
Draw.Text (boardnum, 2 + counter1, 125, font, black)
counter1 := counter1 + 70
end for
for l : 21 .. 30
boardnum := intstr (l )
Draw.Text (boardnum, 2 + counter2, 195, font, black)
counter2 := counter2 + 70
end for
for n : 31 .. 40
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter3, 265, font, black)
counter3 := counter3 + 70
end for
for n : 41 .. 50
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter4, 335, font, black)
counter4 := counter4 + 70
end for
for n : 51 .. 60
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter5, 405, font, black)
counter5 := counter5 + 70
end for
for n : 61 .. 70
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter6, 475, font, black)
counter6 := counter6 + 70
end for
for n : 71 .. 80
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter7, 545, font, black)
counter7 := counter7 + 70
end for
for n : 81 .. 90
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter8, 615, font, black)
counter8 := counter8 + 70
end for
for n : 91 .. 100
boardnum := intstr (n )
Draw.Text (boardnum, 2 + counter9, 685, font, black)
counter9 := counter9 + 70
end for
end board
board
x := - 35
y := 35
loop
num := Rand.Int (1, 6)
num1 := num * 70
x := x + num1
if x > 665 then
y := y + 70
x := - 35 + (num1 - (665 - x ))
end if
locate (1, 1)
put "Enter R to roll."
get roll
locate (40, 92)
put "You"
locate (41, 90)
put "rolled"
locate (42, 92)
put "a ",num
if roll = "R" or roll = "r" or roll = "Roll" or roll = "roll" or roll = "ROLL" then
for i : 1 .. 770 by 70
for k : 1 .. 770 by 70
Draw.FillOval (- 35 + i, 35 + k, 15, 15, 0)
end for
end for
Draw.FillOval (x, y, 10, 10, 4)
end if
end loop
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Jun 01, 2011 11:29 pm Post subject: Re: Snakes and Ladders help |
|
|
Feltie @ Wed Jun 01, 2011 7:39 pm wrote:
It works fine just going across but once it hits 10, it seems to go to a random spot.
I checked my formula and it should work.
Most of the errors in computer programs really come down to some difference between "think it should work" and "how it actually works". The trick to solving such problems is to first find where such difference occurs, and then proceed from that point to figure out the details.
It seems that you've found a particular case ("it hits 10") when things go wrong. That's a good start. Now reproduce this case and check what all the variables (or maybe just those of special interest) values are, with put statements. Compare those values against what you would expect them to be, if everything worked correctly. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|