All pastes #25736 Raw Edit

D'OC Racin' 0.2

public text v1 · immutable
#25736 ·published 2005-10-17 11:25 UTC
rendered paste body
View.Set ("graphics:600,300;position:center,center;nocursor")
randomize

var lgTahoma : int := Font.New ("tahoma:16")
var smTahoma : int := Font.New ("tahoma:10")
var chars : array char of boolean

proc Intro (var players : int)
    drawfill (0, 0, green, green)
    Font.Draw ("Welcome to the D'OC Racetrack!", 170, 275, lgTahoma, yellow)
    loop
        exit when hasch
        delay (50)
    end loop
    Input.Flush
    locate (5, 1)
    colorback (green)
    color (yellow)
    loop
        put "How many players?"
        get players
        exit when players <= 4 and players >= 1
        if players > 4 then
            put "4 players maximum."
        elsif players <= 0 then
            put "Must have at least one player"
        end if
    end loop
    cls
end Intro

proc updateHUD (money : array 1 .. * of int)
    drawfillbox (10, 250, 120, 280, green)
    for i : 1 .. upper (money)
        Font.Draw ("Player " + intstr (i) + ": $" + intstr (money (i)), 10, 260 - (i * 15), smTahoma, yellow)
    end for
end updateHUD

proc newRace (var money : array 1 .. * of int, horses : array 1 .. 6 of int, var betAmount : array 1 .. * of int, var horseNum : array 1 .. * of int)
    var temp : char (1)
    Font.Draw ("The D'OC Racetrack", 180, 275, lgTahoma, yellow)
    updateHUD (money)
    for i : 1 .. 6
        drawfillbox (375, 100 + (i * 24), 400, 100 + (i * 24) + 25, i)
        drawbox (374, 100 + (i * 24) - 1, 401, 100 + (i * 24) + 26, black)
        Font.Draw (intstr (i), 385, 107 + (i * 24), smTahoma, white)
    end for
    for i : 1 .. upper (money)
        drawfillbox (420, 245, 500, 265, green)
        Font.Draw ("Player " + intstr (i) + ", choose a horse:", 420, 250, smTahoma, yellow)

        % This detects for each player's bets!
        loop
            Input.KeyDown (chars)
            if chars ('1') then
                horseNum (i) := 1
            elsif chars ('2') then
                horseNum (i) := 2
            elsif chars ('3') then
                horseNum (i) := 3
            elsif chars ('4') then
                horseNum (i) := 4
            elsif chars ('5') then
                horseNum (i) := 5
            elsif chars ('6') then
                horseNum (i) := 6
            end if
            delay (100)

            if horseNum (i) > 0 then
                drawfillbox (420, 245, 600, 265, green)
                loop
                    locate (13, 28)
                    Font.Draw ("What is your bet? $", 20, 95, smTahoma, yellow)
                    get betAmount (i)
                    if betAmount (i) <= money (i) then
                        Font.Draw ("Player " + intstr (i) + " bets on horse #" + intstr (horseNum (i)) + " with $" + intstr (betAmount (i)), 350, 100 - (i * 15), smTahoma, yellow)
                        drawfillbox (20, 90, 250, 120, green)
                        exit
                    else
                        locate (15, 15)
                        betAmount (i) := 0
                        put "You do not have enough money."
                    end if
                    drawfillbox (20, 90, 280, 120, green)
                end loop
                exit
            end if
        end loop
    end for
end newRace

function runRace (horses : array 1 .. * of int) : int
    var temp : int := 0
    var horsesX : array 1 .. 6 of int := init (0, 0, 0, 0, 0, 0)
    drawfillbox (0, 0, maxx, maxy, green)
    Font.Draw ("Welcome to the D'OC Racetrack!", 170, 275, lgTahoma, yellow)

    for i : 1 .. 6
        drawfillbox (100 + (i * 24), 200, 125 + (i * 24), 225, i)
        drawbox (99 + (i * 24), 199, 126 + (i * 24), 226, black)
        Font.Draw (intstr (i), 108 + (i * 24), 208, smTahoma, white)
    end for

    loop
        randint (temp, 1, 6)
        horsesX (temp) += 2
        for i : 1 .. 6
            drawfillbox (0, 20 + (i * 21), horsesX (i), 40 + (i * 21), i)
            drawbox (0, 20 + (i * 21), horsesX (i), 41 + (i * 21), black)
            if horsesX (i) = 600 then                           % Is a 'horse' done the race?
                Font.Draw (intstr (i), 108 + (i * 24), 208, smTahoma, yellow)
                result i
            end if
        end for
        delay (10)
    end loop
end runRace


% ------------------------------ MAIN PROGRAM LOOP ----------------------------
var racing : boolean := false
var players : int
var horses : array 1 .. 6 of int := init (1, 2, 3, 4, 5, 6)

Intro (players)

var money : array 1 .. players of int
var bet, horseChoice : array 1 .. players of int

for i : 1 .. upper (money)
    bet (i) := 0
    horseChoice (i) := 0
    locate (5, 1)
    colorback (green)
    color (yellow)
    put "How much money does player ", i, " have? $" ..
    get money (i)
    cls
end for
newRace (money, horses, bet, horseChoice)
put runRace (horses)