
-----------------------------------
Angafroness
Mon May 30, 2011 6:45 pm

Windows help
-----------------------------------
%Declaration Section
var mainWindow := Window.Open ("position:300;300, graphics:400;400")
%This global variable is the user input to the guessing game.
var guess : int
%This global variable is the answer to the guessing game it is a random number.
var answer : int
%This global variable is the ammount of tries can be utiized.
var tries : int := 0
%This global variable is for the main menu, it is the choice on the menu screen
var choice : string (1)


%Program title
proc title
    cls
    locate (1, 33)
    put "Guessing game"
    put ""
end title

%Random number
proc randNum
    randint (answer, 25, 75)
end randNum

%Pause program
%This will pause the program when run.
proc pauseProgram
    %This variable is to create the pause in pauseProgram
    var reply : string (1)
    put "Press any key to continue..." ..
    getch (reply)
end pauseProgram

%Program Introduction
proc introduction
    title
    locate (3, 1)
    put "See if you can guess a number between 25 and 75 in three tries!"
    randNum
    pauseProgram
end introduction


%Procedure main menu
proc mainMenu %(changeWindow)
    title
    locate (3, 20)
    put "Enter one of the three options below."
    put "To start a New game press 1 "
    put ""
    put "To continue a game press 2 "
    put ""
    put "To exit press 3 "
    put ""
    put "Enter your choice here: " ..
    get choice
end mainMenu

proc drawWindow2
    var windowID2 := Window.Open ("position:200;200, graphics:200;100")
    Window.Hide (mainWindow)
    Window.Show (windowID2)
    Window.SetActive (windowID2)
    put "You pressed an invalid key. Press any key to continue..." ..
    loop
        exit when hasch
    end loop
    Window.Show (mainWindow)
    Window.SetActive (mainWindow)
    Window.Close (windowID2)
end drawWindow2

proc drawWindow1
    mainMenu
    if choice not= "1" and choice not= "2" and choice not= "3" then
        mainMenu
    else
        if choice = "1" or (choice = "2" and tries = 3) then
            randNum
            tries := 0
        end if
    end if
end drawWindow1
%This procedure will display the main menu

%UserInput
proc userInput
    title
    locate (5, 1)
    put "Enter a number between 25 and 75: " ..
    get guess
    %If the guess is less than 25 and greater then 75 an error message will display.
    if guess < 25 or guess > 75 then
        put ""
        put "Error number out of range! Enter a number between 25 and 75!"
        pauseProgram
        userInput
    end if
end userInput

%Output and processing
proc display
    title
    %This will seperate the result displays
    if guess < answer then
        put "You guessed: ", guess
        put ""
        put "Way down there?"
        put ""
    elsif guess > answer then
        put "You guessed: ", guess
        put ""
        put "Come down"
        put ""
    else
        put "Good job! You guessed the number!"
    end if
    tries := tries + 1         %Only 3 tries.
    pauseProgram
end display

%This is the final screen.
proc goodBye
    %POSSIBLE CREATE ANOTHER WINDOW IF NECESSASY TO 'CLOSE' THE GOODBYE
    title
    if choice = "3" then
        put "Thank you for playing this game."
    elsif guess = answer then
        put "Congradulations you guessed right!"
    else
        put "You didnt guess the magical number try again!"
        put "The number was: ", answer
    end if
    locate (20, 40)
    put "Creator: Angelo Fousteris"
end goodBye

%Main program
introduction
%This loop is done to exit the program after three tries and display a goodbye message.
loop
    mainMenu
    exit when choice = "3"
    userInput
    display
end loop
goodBye
%End program

-----------------------------------
apython1992
Mon May 30, 2011 6:46 pm

RE:Windows help
-----------------------------------
So what's the question?

-----------------------------------
Angafroness
Mon May 30, 2011 6:50 pm

RE:Windows help
-----------------------------------
how do i create windows that will appear when the user inputs something incorrect
like on the main menu if they enter choice 6 (it doesnt exist)

-----------------------------------
Zren
Mon May 30, 2011 8:00 pm

RE:Windows help
-----------------------------------
Make your code pretty.




proc error (msg : string)
    var msgWindow : int % Declare on a seperate line otherwise Turing opens it up early
    msgWindow := Window.Open ("graphics")
    put msg
    loop
        input
        exit when keyDown (KEY_ENTER)
    end loop
    Window.Close (msgWindow)
end error

