Computer Science Canada

Dice Game

Author:  vertdragon23 [ Thu Nov 14, 2013 9:10 pm ]
Post subject:  Dice Game

What is it you are trying to achieve?
I am trying to get it so that if sumofdice2=sumofdice then the program cls and tells you, you won.


What is the problem you are having?
I can't get the sumofdice2=sumofdice to work, ie if sumofdice= to 6 and sumofdice2=4 it still says I won...


Describe what you have tried to solve this problem
<Changing around code many times, and turing reference.>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<

process playmusic
    Music.PlayFile ("mariomusic.mp3")
end playmusic
var dice : int := Pic.FileNew ("download.jpg")
var font : int
var font2: int
var font3: int
var input: int
var font4: int
var dice1:int
var dice2:int
var dice3:int
var dice4:int
var sumofdice:int
var sumofdice2:int
var chars : string (1)
  font4:= Font.New ("serif:18")

 




 
 procedure game1
cls

colorback(47)
cls

locate (1,1)
put "Press any keyboard key to roll dice"
getch (chars)

randint(dice1, 1, 6)
randint(dice2, 1, 6)
randint(dice3, 1, 6)
randint(dice4, 1, 6)
sumofdice:= dice1+dice2
sumofdice2:=dice3+dice4
locate (5,1)
put "Your first dice landed on: " ,dice1
locate(7,1)
put "Your second dice landed on: " ,dice2
locate (9,1)
put "So the sum of your dice roll is: " ,sumofdice

if sumofdice=2 or sumofdice= 7 or sumofdice= 11
then
locate (20,19)
Draw.Text ("You Won!", 150, 340, font4, red)
delay(1000)
cls
delay(1000)
quit
delay (2000)
cls %Round 2 starts here
else
   delay (3000)    cls  put "This is round two, the sum has to equal the sum of the roll from round 1"

         locate (3,1)
put "Press any keyboard key to roll dice"
getch (chars)


sumofdice2:= dice3+dice4


locate (5,1)
put "Your first dice landed on: " ,dice3
locate(7,1)
put "Your second dice landed on: " ,dice4
locate (9,1)
     
       put "So the sum of your dice roll is: " ,sumofdice2
       if sumofdice2=sumofdice then
        quit
       end if
       put "You won"
   
end if

end game1 %Round 2 ends here




procedure help
cls


Draw.Text ("How to play the game", 200, 300, font2, red)
Draw.Text ("To win the game, you have to roll the same number you rolled in the first roll ",110, 200, font3, red)
Draw.Text ("First round: If the numbers add up to two, seven or eleven then you win!" ,110, 150, font3, red)
Draw.Text ("Second round: If you roll a 7, 11, or two 1's then you lose!" ,110, 100, font3, red)
locate (22,19)
put "Enter 1 to start game"
locate (23,19)
put "Enter 2 to go to instructions"
locate (24,19)
put "Enter 3 to exit program"
locate (25,19)
get input
if input= 1 then
game1
elsif input=2 then
help
elsif input=3 then
quit
end if
end help



cls
cls
fork playmusic
font := Font.New ("serif:25")
Draw.Text ("Welcome To Roll the dice!", 150, 370, font, red)
 Pic.Draw (dice, 220, 120, 0)

 font2 := Font.New ("serif:20")

  font3 := Font.New ("serif:12")
locate (18,19)
put "Enter 1 to start game"
locate (19,19)
put "Enter 2 to go to instructions"
locate (20,19)
put "Enter 3 to exit program"
locate (21,19)
get input
if input= 1 then
game1
elsif input=2 then
help
elsif input=3 then
quit

end if>



Please specify what version of Turing you are using
<4.1.1 (Latest)>

Author:  Raknarg [ Fri Nov 15, 2013 12:05 am ]
Post subject:  RE:Dice Game

put "So the sum of your dice roll is: " ,sumofdice2
if sumofdice2=sumofdice then
quit
end if
put "You won"

According to this piece of code, it will exit when you win, but it will only ever tell the player they lost if they don't equal eachother

Author:  vertdragon23 [ Fri Nov 15, 2013 9:20 pm ]
Post subject:  RE:Dice Game

That worked thanks.


: