Computer Science Canada

Help with Proc; Gonna need to know GUI too

Author:  Flikerator [ Mon Sep 12, 2005 10:46 am ]
Post subject:  Help with Proc; Gonna need to know GUI too

code:

import GUI

View.Set ("graphics:300;200,nobuttonbar ")

type Char :
    record
        Name : string
        Pw : string
        Race : string
        Gender : string
        Lvl : int
        Xp, xp : int
        Hp, hp : int
        Vit : int
        Str : int
        Dex : int
        Int : int
        Wis : int
        Bgold, gold : int
        MstAxe, MstSwrd, MstMce, MstStf, MstAir, MstFire, MstCold, MstArc, MstArm : int
        Algn : int
        Item : array 1 .. 30 of string
        Rh, Lh, Armor, Spl1, Spl2, Acc :
            record
                Name : string
                Type : string
                Stat : int
            end record
    end record

var Player : Char
Player.Race := "0"

procedure Human
    Player.Race := "Human"
end Human

procedure Elf
    Player.Race := "Elf"
end Elf

procedure DarkElf
    Player.Race := "Dark Elf"
end DarkElf

procedure Dwarf
    Player.Race := "Dwarf"
end Dwarf

procedure Giant
    Player.Race := "Giant"
end Giant

procedure Troll
    Player.Race := "Troll"
end Troll

procedure Goblin
    Player.Race := "Goblin"
end Goblin

procedure Angel
    Player.Race := "Angel"
end Angel

procedure Gargoyle
    Player.Race := "Gargoyle"
end Gargoyle

var draw1 : int := GUI.CreateButtonFull (50, 330, 150, "Human", Human, 0, '^D', true)
var draw2 : int := GUI.CreateButtonFull (50, 290, 150, "Elf", Elf, 0, '^D', true)
var draw3 : int := GUI.CreateButtonFull (50, 250, 150, "Dark Elf", DarkElf, 0, '^D', true)
var draw4 : int := GUI.CreateButtonFull (50, 210, 150, "Dwarf", Dwarf, 0, '^D', true)
var draw5 : int := GUI.CreateButtonFull (50, 170, 150, "Giant", Giant, 0, '^D', true)
var draw6 : int := GUI.CreateButtonFull (50, 130, 150, "Troll", Troll, 0, '^D', true)
var draw7 : int := GUI.CreateButtonFull (50, 90, 150, "Goblin", Goblin, 0, '^D', true)
var draw8 : int := GUI.CreateButtonFull (50, 50, 150, "Angel", Angel, 0, '^D', true)
var draw9 : int := GUI.CreateButtonFull (50, 10, 150, "Gargoyle", Gargoyle, 0, '^D', true)

var title : int := GUI.CreateLabelFull (250, 280, "Charcter", 250, 0,
    GUI.CENTER, 0)
var textBox : int := GUI.CreateTextBoxFull (250, 10, 280, 265,
    GUI.INDENT, 0)

GUI.SetBackgroundColor (gray)

loop
    exit when GUI.ProcessEvent
    locate (1, 1)
    put Player.Race
end loop


When i do text add to the procedure of human to fill up the text box it wont letme because its before. I know i can use forward but im not exactly sure how to do it. To see what i mean add this line in the human procedure;

code:
GUI.AddLine (textBox, Player.Race)


= )

Author:  StarGateSG-1 [ Mon Sep 12, 2005 1:05 pm ]
Post subject: 

I think you are on the wrong track.

Form what I get form your code the simplest way for you to make this work is to...


-Have a Page of Buttons with all of your character choices (check)
-When the user clicks on a button it links to a procedure that can maybe tell a bit about the selected character.
-You do this by creating a textbox on the same page.
- you might also want to insert a character name area on this page
-then when this is pressed you create a "choose character button" which would link to another procedure which will set all the data that has been gather.
-each section should be in its own procedure.

If you ahve any other questions just ask!

Author:  Delos [ Mon Sep 12, 2005 1:23 pm ]
Post subject: 

I tried declaring 'textBox' before all the procs, and that worked quite well. I also noted that your keyboard handling abilities are quite, um, limited. My suggestion is for you to not use GUI, just because it doesn't really handle text boxes and other widgets well together. Text fields, yes, but not the boxes.
Develop your own if you need to, or at least create a pseudo-text box, it will make your life easier.

Author:  Flikerator [ Mon Sep 12, 2005 2:12 pm ]
Post subject: 

Depending on what you mean by keyboard handling im very good. The point of this project is to learn GUI. There are far simpler and less complex ways to do it, and GUI saves me from using or making pictures (using turing or importing pics).

The text box was the first thing that I found (to display text Razz) and i put that in. What the "text" area will have is all the information that race provides before you permenantly choose that race. I learned the farward stuff in english (XD).

Thanks for the help...

EDIT - Also I don't know WHY View.Set is in my program, its not even done correctly Confused

Author:  Delos [ Mon Sep 12, 2005 3:27 pm ]
Post subject: 

What I did not mean was that you're a terrible porter.

I meant that when you run the proggie, and press any key on the Keyboard it will crash due to a 'defered subroutine' not having been 'resolved', or something to that effect.
A problem with Turing, nonetheless.

GUI's not worth learning, not with its limitations. I'm not bashing (this time at least), I'm just telling you that Turing's inability to create objects and widgets in satisfactory ways really puts it at a disadvantage. Cervantes (man, I should really start calling him Clevernuts Laughing) was raving about it a while back...something he picked up from Ruby methinks.

Author:  StarGateSG-1 [ Mon Sep 12, 2005 3:28 pm ]
Post subject: 

Is this a class exercise if not drop GUI, I was just coming on to add that and I got beaten to it but I might as well support Delos.

Author:  Flikerator [ Mon Sep 12, 2005 4:20 pm ]
Post subject: 

Class assignment? No way. I was hoping for something more challenging this year, cause grade 11, but no. So far its 100% the same as last year. We have over half the class who has never programmed before so its the same as last year :/

We arn't even starting C++ or C# this year. I program on my own now and learn stuff (however difficult or useless).

Author:  [Gandalf] [ Mon Sep 12, 2005 4:41 pm ]
Post subject: 

I never learned the Turing GUI. The most I ever did with it is create a text box that showed two different things based on the button you pressed Laughing. You can do anything you will need with just custom click-boxes, etc. If you are planning on doing graphical stuff, I suggest you look into other options.

I have yet to hear of a school where they teach C++ at grade 11. I'm sure that's about to be changed Wink.

Author:  Flikerator [ Tue Sep 13, 2005 7:14 am ]
Post subject: 

[Gandalf] wrote:
I never learned the Turing GUI. The most I ever did with it is create a text box that showed two different things based on the button you pressed Laughing. You can do anything you will need with just custom click-boxes, etc. If you are planning on doing graphical stuff, I suggest you look into other options.

I have yet to hear of a school where they teach C++ at grade 11. I'm sure that's about to be changed Wink.


Lolz well I started to learn C++ and started a remake project for an online game. I was talking to the creator and he told me about C#. So im going to check that out and see if its any good. He says it relativly new so I dunno. Has anyone heard of it?

Author:  StarGateSG-1 [ Tue Sep 13, 2005 9:13 am ]
Post subject: 

Just a hint, if you want an online game you should use Java, because then you can store in an applet, C++ or C# games require your own server or you can rent one, but you have to write the parts yourself. On last thing C# is not for games, that is as palin as I can say it. If you ask any gamer they use C++ or Python or a game creator with a scripting language.

Author:  Flikerator [ Tue Sep 13, 2005 10:25 am ]
Post subject: 

The game was is text based thats probably why he suggested it. Anyways ill just submit the code I got now. GUI isn't that overly complex, but for turing I guess it is. Click on human to see a part of what it will be like;

code:
import GUI

View.Set ("graphics:300;200,nobuttonbar ")

type Char :
    record
        Name : string
        Pw : string
        Race : string
        Gender : string
        Lvl : int
        Xp, xp : int
        Hp, hp : int
        Vit : int
        Str : int
        Dex : int
        Int : int
        Wis : int
        Bgold, gold : int
        MstAxe, MstSwrd, MstMce, MstStf, MstAir, MstFire, MstCold, MstArc, MstArm : int
        Algn : int
        Item : array 1 .. 30 of string
        Rh, Lh, Armor, Spl1, Spl2, Acc :
            record
                Name : string
                Type : string
                Stat : int
            end record
    end record

var Player : Char
Player.Race := "0"
Player.Bgold := 0
Player.gold := 0
Player.Lvl := 1

var title : int := GUI.CreateLabelFull (210, 280, "Charcter", 250, 0,
    GUI.CENTER, 0)
var textBox : int := GUI.CreateTextBoxFull (210, 10, 280, 265,
    GUI.INDENT, 0)

var Exit : boolean := false
procedure Agree
    if Player.Race ~= "0" then
        Exit := true
    end if
end Agree

var vit, str, dex, Int, wis : string

proc text
    vit := "Vit:   " + intstr (Player.Vit)
    str := "Str:   " + intstr (Player.Str)
    dex := "Dex:  " + intstr (Player.Dex)
    Int := "Int:    " + intstr (Player.Int)
    wis := "Wis:   " + intstr (Player.Wis)
end text

procedure Human
    GUI.ClearText (textBox)
    Player.Race := "Human"
    Player.Vit := 20
    Player.Str := 20
    Player.Dex := 20
    Player.Int := 20
    Player.Wis := 20
    text
    GUI.AddLine (textBox, Player.Race)
    GUI.AddLine (textBox, vit)
    GUI.AddLine (textBox, str)
    GUI.AddLine (textBox, dex)
    GUI.AddLine (textBox, Int)
    GUI.AddLine (textBox, wis)
end Human

procedure Elf
    Player.Race := "Elf"
end Elf

procedure DarkElf
    Player.Race := "Dark Elf"
end DarkElf

procedure Dwarf
    Player.Race := "Dwarf"
end Dwarf

procedure Giant
    Player.Race := "Giant"
end Giant

procedure Troll
    Player.Race := "Troll"
end Troll

procedure Goblin
    Player.Race := "Goblin"
end Goblin

procedure Angel
    Player.Race := "Angel"
end Angel

procedure Gargoyle
    Player.Race := "Gargoyle"
end Gargoyle

var draw1 : int := GUI.CreateButtonFull (50, 330, 150, "Human", Human, 0, '^D', true)
var draw2 : int := GUI.CreateButtonFull (50, 290, 150, "Elf", Elf, 0, '^D', true)
var draw3 : int := GUI.CreateButtonFull (50, 250, 150, "Dark Elf", DarkElf, 0, '^D', true)
var draw4 : int := GUI.CreateButtonFull (50, 210, 150, "Dwarf", Dwarf, 0, '^D', true)
var draw5 : int := GUI.CreateButtonFull (50, 170, 150, "Giant", Giant, 0, '^D', true)
var draw6 : int := GUI.CreateButtonFull (50, 130, 150, "Troll", Troll, 0, '^D', true)
var draw7 : int := GUI.CreateButtonFull (50, 90, 150, "Goblin", Goblin, 0, '^D', true)
var draw8 : int := GUI.CreateButtonFull (50, 50, 150, "Angel", Angel, 0, '^D', true)
var draw9 : int := GUI.CreateButtonFull (50, 10, 150, "Gargoyle", Gargoyle, 0, '^D', true)
var draw10 : int := GUI.CreateButtonFull (500, 120, 0, "I Choose This Race", Agree, 75, '^D', true)

GUI.SetBackgroundColor (gray)

loop
    exit when GUI.ProcessEvent
    if Exit = true then
        exit
    end if
    locate (1, 1)
    put Player.Race
end loop

cls

Author:  StarGateSG-1 [ Tue Sep 13, 2005 11:07 am ]
Post subject: 

not bad do you kno0w how to read from a text file, I would use that instead and then you can use a for loop and just add each line = less code
you don't need to set the character values right now wait till after they choose their character.

code:

var line : string
        var fileNumber : int
        open : fileNumber, Dir.Current + "FILENAME", get
        loop
            exit when eof (fileNumber)
            get : fileNumber, line : *
            GUI.AddLine (textBox,line)
        end loop


Then you would write the Text file

Quote:

Human
20
20
20
20
20
The Human is a ...


other than that it is good.

By the way are you planing to chnage the programing language fopr your game. If so I will offer my assitance in anyway you need.


: