Fun back to school challenge
Author |
Message |
The_Bean
|
Posted: Tue Aug 19, 2008 8:52 pm Post subject: Fun back to school challenge |
|
|
The basics of a game require user input in a unique way to ultimately challenge the user and have them win/lose or recieve a good/bad score.
The challenge is to make a game without using any direct comparison.
YOU CAN NOT USE:
Turing: |
if
elsif
else
end if
exit when
case
label
end case
% or any GUI
|
The game can be as basic as you want, but you must be able to win and lose.
It is possible to do, so far I have made a "mouse maze", but can't figure out how to exit without using "quit" |
|
|
|
|
|
Sponsor Sponsor
|
|
|
chrisbrown
|
Posted: Wed Aug 20, 2008 12:29 am Post subject: Re: Fun back to school challenge |
|
|
This was definitely harder than I thought it would be.
I used a single exit when, so I guess it doesn't count, officially...
but I don't care.
Turing: |
const LO_BOUNDS := 1
const HI_BOUNDS := 5
const ROUNDS := 10
var history : flexible array 1 .. 0 of boolean
forward fcn calcScore (i, s : int) : int
fcn calcScoreAlt (i, s : int) : int
var k : int := 1
for j : i .. upper (history )
k := j
exit when history (j )
result calcScore (j + 1, s )
end for
result calcScore (k + 1, s + 1)
end calcScoreAlt
body fcn calcScore (i, s : int) : int
for j : i .. upper (history )
result calcScoreAlt (j, s )
end for
result s
end calcScore
var target, guess : int
var try : string
var score := 0
put "Your basic, run-of-the-mill number guessing game\n"
put "You have ", ROUNDS, " chances to guess the number I am thinking of"
put "Note that you get one guess per turn; the number changes each round.\n"
for i : 1 .. ROUNDS
put "Round ", i
target := Rand.Int (LO_BOUNDS, HI_BOUNDS )
put "Guess a number (", LO_BOUNDS, " through ", HI_BOUNDS, ", inclusive): " ..
get try
assert strintok (try )
guess := strint (try )
put "\t\t\tThe number was: ", target
new history, upper (history ) + 1
history (upper (history )) := target = guess
score := calcScore (1, 0)
put "Your score is ", score, "\n"
end for
put "Final score: ", score, " / ", ROUNDS
put "Percentage: ", score / ROUNDS
|
|
|
|
|
|
|
The_Bean
|
Posted: Wed Aug 20, 2008 4:12 pm Post subject: Re: Fun back to school challenge |
|
|
I hate to put my own up, because of the way i figured out to do it, but here it is.
Turing: |
View.Set ("graphics:500,500,offscreenonly,title:Mouse Maze")
var xm, ym, bm, bd : int
var colours : array 0 .. 7 of procedure x ()
var position : int := 7
proc blank
end blank
proc setBlank
for i : 0 .. 7
colours (i ) := blank
end for
end setBlank
proc roomFloor
Text.Colour (0)
Text.ColourBack (7)
Draw.FillBox (0, 200, 25, 300, 1)
Draw.FillBox (475, 200, 500, 300, 2)
Draw.FillBox (0, 300, 500, 500, 7)
Draw.FillBox (0, 0, 500, 200, 7)
Draw.ThickLine (0, 200, 500, 223, 50, 7)
Draw.ThickLine (0, 300, 500, 277, 50, 7)
put "Hover over the blue to start then try and make it to the green without touching black in 3 seconds"
View.Update
end roomFloor
proc youLose
locate (position, 7)
put "You Lose"
View.Update
Text.Colour (7)
position := 20
end youLose
proc youWin
locate (position, 7)
put "You Win"
View.Update
Text.Colour (7)
position := 20
end youWin
proc game
locate (5, 7)
put "Start"
View.Update
colours (0) := blank
colours (1) := blank
colours (2) := youWin
colours (7) := youLose
for decreasing i : 3000 .. 0
Mouse.Where (xm, ym, bm )
colours (View.WhatDotColour (xm, ym ))
Time.DelaySinceLast (1)
locate (5, 20)
put i
View.Update
end for
youLose
end game
proc start
colours (0) := start
colours (1) := game
colours (2) := start
colours (7) := start
Mouse.ButtonWait ("downup", xm, ym, bm, bd )
colours (View.WhatDotColour (xm, ym ))
end start
setBlank
roomFloor
start
|
|
|
|
|
|
|
|
|