Computer Science Canada

Turing circle game

Author:  Brandit28 [ Mon Oct 29, 2018 6:09 pm ]
Post subject:  Turing circle game

I am making a game where you guess where a random circle is using given coordinates. I need help having the game two player. An example of this is by having out player go then the next and it will output either "player 1 wins" or "player 2 " wins. This is what i have...


setscreen ("graphics:max,max")
buttonchoose ("multibutton") %allows for right click
var circleX : int := 0 % Secret circle
var circleY : int := 0
var guessX : int := 0 %Players Guess
var guessY : int := 0
var distance_amount : int := 0 % Unused at this point
var mousex, mousey, mouseb : int := 0 % Mouse Variables
var answer : real
var intfont : int
var text : string
var playagain : string (1)

process DoMusic
loop
Music.PlayFile ("background.mp3")
end loop
end DoMusic


drawfillbox (0, 0, maxx, maxy, black)
colourback (black)


intfont := Font.New ("Times New Roman:30")
Font.Draw (" *****************************************************", 400, 800, intfont, yellow)
Font.Draw (" Welcome To GUESS THE CIRCLE ", 400, 700, intfont, yellow)
Font.Draw (" Objective: Follow the coordinates and guess where ", 400, 500, intfont, yellow)
Font.Draw (" the other circle is ", 400, 400, intfont, yellow)
Font.Draw (" Press 1 Then Enter To Begin ", 400, 300, intfont, yellow)
Font.Draw (" *****************************************************", 400, 200, intfont, yellow)

get answer
cls
View.Update
intfont := Font.New ("Times New Roman:50")
Font.Draw ("LOADING...", 750, 500, intfont, white)
for i : 0 .. maxx
drawbox (i, 0, 0, 70, white)
delay (3)
end for
%%%%%%%This function determines the distance between 2 points
cls
setscreen ("offscreenonly") %helps with flicker
drawfillbox (0, 0, maxx, maxy, black)
colourback (black)
colour (white)

fork DoMusic

function distance (x1, y1, x2, y2 : real) : real
result round (sqrt ((x2 - x1) ** 2 + (y2 - y1) ** 2))
end distance

loop
circleX := Rand.Int (100, maxx - 100)
circleY := Rand.Int (100, maxy - 100)
loop
mousewhere (mousex, mousey, mouseb) % allows the mouse to become active - you need this in every loop
locate (1, 1)

put "Try and find:(", circleX, ",", circleY, ")"
put "Left click to guess - Right Click when you are ready"

if mouseb = 1 then % User left clicks to guess
cls %Clears the screen
drawfilloval (mousex, mousey, 10, 10, red) %Draws the circle where the player guesses
guessX := mousex %keeps track of player guess
guessY := mousey
end if
exit when mouseb = 100 % right click when player is ready
View.Update % Stops the flicker

end loop
loop
cls
locate (1, 1)
drawfilloval (guessX, guessY, 10, 10, red) %Draws players guess
drawfilloval (circleX, circleY, 10, 10, green) %Reveals answer
put "The distance was:", distance (guessX, guessY, circleX, circleY) %shows the distance



put "Enter y to restart game and any other key to exit"
View.Update
getch (playagain)

exit

end loop

if playagain not= "y" then

end if

end loop

Author:  Srlancelot39 [ Wed Oct 31, 2018 7:46 am ]
Post subject:  RE:Turing circle game

The Turing Submissions section is for completed work. When requesting help, please post in the Turing Help section.

Additionally, please format your code using the code tag.


: