Re: Where dose the code go?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Alvin,

Here's an amended version of your program which might help.  In general,
code goes into procedures or functions, placed somewhere before the last
main loop statement, and before the event handler which invokes them.

Dan Moyer

-- begin code

-- A simple Windows dice game


include win32lib.ew

without warning

------------------------------------------

-- CONTROLS:


constant WinDice =

create( Window, "Win Dice!", 0, Default, Default, 400, 200, 0 )


-- create a control in the window

constant Throw_Button =

create( PushButton, "&Throw Dice", WinDice, 100, 30, 80, 40, 0 )

----------------------------------------------

-- ACTIONS (things to do when initiating events occur):


-- action to take when the window opens

global procedure onPaint_WinDice( integer x1, integer y1, integer x2,
integer y2 )

setPosition(WinDice,1,1) -- sets initial position for text

wPuts( WinDice, "WinDice Version 1.0 Click the Throw dice button to play" )

end procedure

-- action to take when roll dice button pressed:

procedure RollDice()

integer d1,d2

d1 = rand( 6 ) -- get dice values

d2 = rand( 6 )

repaintWindow(WinDice) -- clears screen so new numbers don't overwrite old

setPosition(WinDice,1,20) --sets position of first number

wPrint(WinDice,d1)

setPosition(WinDice,20,20)-- sets position of second number

wPrint(WinDice,d2)

end procedure


-----------------------------------------------

-- EVENTS (tell Windows when to do an action & what action to do):

onPaint[WinDice] = routine_id( "onPaint_WinDice" )

onClick[Throw_Button]=routine_id("RollDice")

-----------------------------------------------

-- MAIN LOOP:


-- hand control over to Windows

WinMain( WinDice, Normal )



-- end code



    -----Original Message-----
    From: A.R.S. Alvin Koffman <ka9qlq at HOTMAIL.COM>
    To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
    Date: Tuesday, July 18, 2000 5:23 PM
    Subject: Where dose the code go?


    I spliced two of Dave Coney's winlib examples and got this working then
it dawned on me. WHERE DO YOU PUT THE $#@*! CODE TO DO STUFF WITH!!!!!! Dang
you jump from DOS out the Windows, and your in a different world, even with
Dave's winlib. That dice game I cobbled up in May and posted for review in
June was clunky but it worked, this I don't know. I did the dice game with
BASIC experience that's ten years old (code something, try it, add more).
Crude true but it worked. Sorry to blab, but had to get it off my chest
(wheeeezzzzz). I'm going to read Dave's connect 4 code and hope a light
comes on.

    -- A simple Windows dice game

    include win32lib.ew
    without warning

    constant WinDice =
        create( Window, "Win Dice!", 0, Default, Default, 400, 200, 0 )

    -- create a control in the window
    constant Throw_Button =
        create( PushButton, "&Throw Dice", WinDice, 100, 30, 80, 40, 0 )

    -- action to take when the window opens
    global procedure onPaint_WinDice( integer x1, integer y1, integer x2,
integer y2 )
        wPuts( WinDice, "WinDice Version 1.0 Click the Throw dice button to
play" )
    end procedure


    -- tell Windows when to do the action
        onPaint[WinDice] = routine_id( "onPaint_WinDice" )

    -- hand control over to Windows
        WinMain( WinDice, Normal )


    http://ka9qlq.tripod.com/

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu