Computer Science Canada

simple text game

Author:  do_pete [ Wed Nov 02, 2005 2:52 pm ]
Post subject:  simple text game

i was board in my computers class so i made this.
You are the green asterick and you try to run away from the other ones.

code:
var PlayerX, PlayerY : int := 1
var AIX, AIY : array 1 .. 50 of int
var AITurn, AIAppear, AIArrayNum, ANum : int := 1
var key : array char of boolean
var YouLoose, Exit : boolean := false
var answer : char

procedure ControlPlayer
    Input.KeyDown (key)

    if key (KEY_RIGHT_ARROW) then
        PlayerX += 1
    elsif key (KEY_LEFT_ARROW) then
        PlayerX -= 1
    end if

    if key (KEY_UP_ARROW) then
        PlayerY -= 1
    elsif key (KEY_DOWN_ARROW) then
        PlayerY += 1
    end if

    if PlayerX > maxcol then
        PlayerX := maxcol
    elsif PlayerX < 1 then
        PlayerX := 1
    end if

    if PlayerY > maxrow then
        PlayerY := maxrow
    elsif PlayerY < 1 then
        PlayerY := 1
    end if
end ControlPlayer

procedure DrawPlayer (x, y : int)
    Text.Locate (y, x)
    put "*" ..
end DrawPlayer

procedure AI
    if AITurn >= 1 then
        if PlayerX > AIX (ANum) then
            AIX (ANum) += 1
        elsif PlayerX < AIX (ANum) then
            AIX (ANum) -= 1
        end if

        if PlayerY > AIY (ANum) then
            AIY (ANum) += 1
        elsif PlayerY < AIY (ANum) then
            AIY (ANum) -= 1
        end if
    end if
end AI

procedure Beginning
    Text.Locate (maxrow div 2 - 1, maxcol div 2 - 7)
    put "Peter Do's Game"
    Text.Locate (maxrow div 2, maxcol div 2 - 11)
    put "Press any key to begin"
    View.Update
    Input.Pause
    cls
    View.Update
end Beginning

View.Set ("offscreenonly,graphics:400;400,title:Peter Do's Game,nobuttonbar,position:middle;middle,nocursor")

Text.Colour (brightred)
Beginning

loop

    for i : 1 .. 50
        randint (AIX (i), 1, maxcol)
        randint (AIY (i), 1, maxrow)
    end for

    loop
        ControlPlayer
        Text.Colour (green)
        DrawPlayer (PlayerX, PlayerY)

        AITurn := (AITurn + 1) mod 2
        AIAppear := (AIAppear + 1) mod 25
        if AIAppear >= 24 then
            AIArrayNum += 1
        end if

        Text.Colour (brightred)
        for i : 1 .. AIArrayNum
            DrawPlayer (AIX (i), AIY (i))
            ANum := i

            AI

            if AIX (i) = PlayerX and AIY (i) = PlayerY then
                YouLoose := true
                exit
            end if
        end for

        View.Update
        cls
        delay (100)
        if YouLoose = true then
            exit
        end if
    end loop
    cls
    Text.Locate (maxrow div 2 - 1, maxcol div 2 - 5)
    put "You Loose!"
    Text.Locate (maxrow div 2, maxcol div 2 - 7)
    put "Your Score is ", AIArrayNum
    Text.Locate (maxrow div 2 + 1, maxcol div 2 - 17)
    put "Would you like to play again(Y/N)?"
    View.Update
    loop
        answer := getchar
        if answer = "N" or answer = "n" then
            Exit := true
            exit
        elsif answer = "Y" or answer = "y" then
            exit
        end if
    end loop
    exit when Exit = true

    PlayerX := 1
    PlayerY := 1
    AITurn := 1
    AIAppear := 1
    AIArrayNum := 1
    ANum := 1
    YouLoose := false
    Exit := false
    cls
end loop

Author:  ZeroPaladn [ Wed Nov 02, 2005 3:23 pm ]
Post subject: 

wow, very neat! you can make some of the stars go into eachother if you time it right, but, other than that, very neat tag game! GJ!

Author:  beard0 [ Wed Nov 02, 2005 4:05 pm ]
Post subject: 

Wow, more than descent - small code, yet playable. Score: 25 on second try Wink

Author:  Tony [ Wed Nov 02, 2005 4:25 pm ]
Post subject: 

you might be interested in checking out zylum's and Cervantes' games


: