
-----------------------------------
deltamanx
Fri Jan 08, 2010 8:35 pm

Turing D&amp;D game
-----------------------------------
At one point in time I was working on this, then I made a mistake somewhere; was to bored to fix, and quit this.
Thus I decided to post it here; better than letting it rot in a folder. (Do files even rot?)
---
EDIT:
Here's the code as well:
[code]/*
 Mihail Kurbako
 D&D: Turing edition
 Nov, 11, 2009
 This is D&D Turing edition, version 1.1 patch E.
 */

%Variable declaration
import GUI
var monHp : int             %Monster HP
var monAc : int             %Monster AC
var monDmg : int            %Monster's damage rolls
%var enc1 : string           %Unused
var yourHealth : int        %Player health
var ac : int                %Player armor class
var attackBonus : int       %Player attack bonus
var roll : int              %Dice roll
var dmg : int               %Damage roll
var acc : int               %Armor class compatibility
var tutorial : string       %Tutorial display prompt
var race : string           %Player race
var name : string           %Player name
var charClass : string      %Player class
var story : string          %Skip the story
var wizSpell : int          %Wether player can use spells
var spellSelect : string    %Spell selction
var heal : int              %Healing after battle
var story2 : string         %Second dialogue prompt
var dead : string           %If the character is dead, quit.
var level : int             %Character level
var charExp : int           %Expirience points
%var enc2 : int              %Unused
var story3 : string         %Story line prompt 3
var monRoll : int           %Monster rolls
var winPrim : int           %Opens the primary window
var winSecn : int           %Opens the secondary window
var winMap : int            %Opens the map window
var command : string        %The game control console
var loadNum : int           %File number
var titleSelect : int       %Create new or load previous character
var charHPGain : int        %How much HP a character gains at level up

%Saving variables
var loadName : string := "CharName"
var loadClass : string := "CharClass"
var loadLevel : string := "CharLevel"
var loadRace : string := "CharRace"
var loadDead : string := "CharDead"
var loadCharExp : string := "CharExp"
var loadWizSpell : string := "CharWizSpell"
var loadAC : string := "CharAC"
var loadACC : string := "CharACC"
var loadHP : string := "CharHealth"
var loadAttackBonus : string := "CharAtkBns"

%Preset variables
dead := "1"
level := 1
charExp := 0

process charSheet
    Window.SetActive (winSecn)
    cls
    put "D&D : Character Sheet"
    put " "
    put "Dungeons and Dragons : Turing edition."
    put "By : Mihail Kurbako"
    put " "
    put "Name : ", name
    put " "
    put "Level ", level, " ", race, " ", charClass
    put "You have ", charExp, " expirience."
    put " "
    put "Items :"
    put "You have no items."
    put " "
    if wizSpell = 1 then
        put "Spell list :"
        put " "
        put "Magic Missile. (1d4 + Caster level; auto hit)"
        put "Ice Ray. (1d10 + Caster level)"
    else
        put "Spell list :"
        put " "
        put "You have no spells."
    end if
    Window.SetActive (winPrim)
end charSheet

%Window Control
winPrim := Window.Open ("position:top;right,graphics:800;450")
winSecn := Window.Open ("position:top;left,graphics:400;450")
winMap := Window.Open ("position:bottom;center,graphics:400;160")

%Quit game process
proc gameQuit
    Window.Close (winPrim)
    Window.Close (winSecn)
    Window.Close (winMap)
end gameQuit

%Game saving
process saveGame
    %Save objects
    open : loadNum, loadName, write
    write : loadNum, name
    open : loadNum, loadLevel, write
    write : loadNum, level
    open : loadNum, loadRace, write
    write : loadNum, race
    open : loadNum, loadClass, write
    write : loadNum, charClass
    open : loadNum, loadCharExp, write
    write : loadNum, charExp
    open : loadNum, loadHP, write
    write : loadNum, yourHealth
    open : loadNum, loadWizSpell, write
    write : loadNum, wizSpell
    open : loadNum, loadAC, write
    write : loadNum, ac
    open : loadNum, loadACC, write
    write : loadNum, acc
    open : loadNum, loadDead, write
    write : loadNum, dead
    open : loadNum, loadAttackBonus, write
    write : loadNum, attackBonus
    %Put objects
    put "Name : ", name
    put "Level : ", level
    put "Race : ", race
    put "Class : ", charClass
    put "HP : ", yourHealth
    put "AC : ", ac
    put "EXP : ", charExp
    put "Attack Bonus : ", attackBonus
    close : loadNum
end saveGame

process loadGame
    %Load game
    open : loadNum, loadName, seek, read
    read : loadNum, name
    open : loadNum, loadLevel, seek, read
    read : loadNum, level
    open : loadNum, loadRace, seek, read
    read : loadNum, race
    open : loadNum, loadClass, seek, read
    read : loadNum, charClass
    open : loadNum, loadCharExp, seek, read
    read : loadNum, charExp
    open : loadNum, loadHP, seek, read
    read : loadNum, yourHealth
    open : loadNum, loadWizSpell, seek, read
    read : loadNum, wizSpell
    open : loadNum, loadAC, seek, read
    read : loadNum, ac
    open : loadNum, loadACC, seek, read
    read : loadNum, acc
    open : loadNum, loadDead, seek, read
    read : loadNum, dead
    open : loadNum, loadAttackBonus, seek, read
    read : loadNum, attackBonus
    put "Name : ", name
    put "Level : ", level
    put "Race : ", race
    put "Class : ", charClass
    put "HP : ", yourHealth
    put "AC : ", ac
    put "EXP : ", charExp
    put "Attack Bonus : ", attackBonus
    close : loadNum
end loadGame

procedure save
    fork saveGame
end save

process saveButton
    % Create the button. The number returned is the ID number of the button.
    var b : int := GUI.CreateButton (100, 10, 0, "Save", save)
    var c : int := GUI.CreateButton (250, 10, 0, "Quit", gameQuit)
    % Now process events until the user aborts the program.
    loop
        exit when GUI.ProcessEvent
    end loop
end saveButton

%Game control console
process gameConsole
    loop
        fork saveButton
        get command:*
        if command = "quit" then
            gameQuit
        elsif command = "save" then
            put "Enter a slot number (1 - 99)."
            get loadNum
            put name, " has been saved under slot ", loadNum, "."
            fork saveGame
        end if
    end loop
end gameConsole

%Title screen
proc title
    fork gameConsole
    Window.SetActive (winPrim)
    put "Dungeons and Dragons: Turing Edition."
    put "By: Mihail Kurbako."
    put " "
    put "Would you like to load a game or start a new one?"
    put "Load ( 1 ) or Create ( 2 )"
    put " "
    get titleSelect
    cls
end title

%Load screen
proc loadScreen
    put "Enter the save slot number."
    get loadNum
    fork loadGame
end loadScreen


%Main game
proc charCreate
    loop
        Window.SetActive (winSecn)
        put "D&D : Character Sheet"
        put " "
        put "Dungeons and Dragons : Turing edition."
        put "By : Mihail Kurbako"
        Window.SetActive (winMap)
        locate (1, 17)
        put "Control console"
        put " "
        fork gameConsole
        Window.SetActive (winPrim)
        loop
            if dead = "1" then
                dead := "0"
                cls
                put "Welcome to: D&D Turing Edition."
                put "By Mihail Kurbako"

                put "Would you like to read the beginer's tutorial? (yes, no)"

                get tutorial
                if tutorial = "yes" then
                    put "Before we begin, you must make a charcter."
                    delay (1500)
                    put "There are 3 possible races and classes for you to choose from."
                    delay (1500)
                    put "Classes: Fighter, Wizard, Ranger."
                    delay (1500)
                    put "The Fighter excels at close quarters combat, and is a strong defensive class."
                    delay (1500)
                    put "Fighers have the most hit points (health), and highest AC (armor class)."
                    delay (1500)
                    put "Thus they are hard to hit and kill. They can dish out a moderate amount damage."
                    delay (1500)
                    put "This is the best class for beginers to start with."
                    delay (1500)
                    put " "
                    put "Wizards focus on magic to aid them in combat, they are a powerful support class."
                    delay (1500)
                    put "Wizards have the fewest hitpoints, and lowest AC, as they cannot wear armor."
                    delay (1500)
                    put "Wizards know a variety of spells and can dish out heavy damage."
                    delay (1500)
                    put "Wizards are a class for more expirienced players."
                    delay (1500)
                    put " "
                    put "The Ranger is at home in the wood and the wild, and is a good offencive class."
                    delay (1500)
                    put "Rangers have a moderate amount af hitpoints and a good AC."
                    delay (1500)
                    put "Rangers are highly proficient with bows and crossbows and other ranged weapons."
                    delay (1500)
                    put "Rangers are a fairly easy class to master."
                    delay (1500)
                    put " "
                    put "Races: Human, Elf, Dwarf."
                    delay (1500)
                    put "Humans are adaptable and can easily be any class."
                    delay (1500)
                    put "Weapon Focus (+ 1 to attack bonus)"
                    delay (1500)
                    put " "
                    put "Elves love nature and magic, and are thus good rangers and wizards."
                    delay (1500)
                    put "Dodge (+ 1 bonus to Armor Class.)"
                    delay (1500)
                    put " "
                    put "Dwarves are a hardy folk and are great fighters."
                    delay (1500)
                    put "Toughness (+ 3 bonus to Hit Points)."
                    delay (1500)
                else

                end if

                put " "
                put "Choose your class. Fighter, Wizard, or Ranger?"
                put " "
                loop
                    get charClass
                    if charClass = "Fighter" then
                        yourHealth := Rand.Int (26, 34)
                        ac := Rand.Int (15, 17)
                        attackBonus := Rand.Int (1, 4)
                        acc := 1
                        wizSpell := 0
                        put "As a fighter you have ", yourHealth, " hitpoints."
                        put "Your AC is ", ac, "."
                        put " "
                        exit
                    end if

                    if charClass = "Wizard" then
                        yourHealth := Rand.Int (15, 22)
                        ac := Rand.Int (12, 15)
                        attackBonus := Rand.Int (2, 3)
                        acc := 2
                        wizSpell := 1
                        put "As a Wizard you have ", yourHealth, " hitpoints."
                        put "Your AC is ", ac, "."
                        put " "
                        exit
                    end if

                    if charClass = "Ranger" then
                        yourHealth := Rand.Int (22, 27)
                        ac := Rand.Int (14, 16)
                        attackBonus := Rand.Int (3, 6)
                        acc := 3
                        wizSpell := 0
                        put "As a Ranger you have ", yourHealth, " hitpoints."
                        put "Your AC is ", ac, "."
                        put " "
                        exit
                    end if
                end loop

                put " "
                put "Choose your race. Human, Elf, or Dwarf?"
                put " "
                loop
                    get race
                    if race = "Human" then
                        attackBonus := attackBonus + 1
                        exit
                    end if
                    if race = "Elf" then
                        ac := ac + 1
                        exit
                    end if
                    if race = "Dwarf" then
                        yourHealth := yourHealth + 3
                        exit
                    end if
                end loop

                put " "
                put "You are now a ", race, " ", charClass, ". Your AC is ", ac, ", your attack bonus is +", attackBonus
                put "And you have ", yourHealth, " total health. Now you need a name."
                put " "
                %Name prompt
                put "Please enter your new character's name."
                get name
                delay (1000)
                put " "
                put "You are ", name, " the mighty ", race, " ", charClass, "!"
                put "Congratulations, ", name, " you are now ready to begin your journey!"
                put " "
                fork charSheet
                if wizSpell = 1 then
                    put "As a first level wizard you get theese spells."
                    put " 1 = Magic Missle (1d4 + Caster Level; auto hit)"
                    put " 2 = Ice Ray (1d10 + Caster Level)"
                    put " "
                end if
                delay (1600)
                put "Would you like to play the dialogue? (yes, no)"
                get story
                if story = "yes" then
                    put "A group of group of goblins has been harrasing the village of Curbury."
                    delay (1500)
                    put "You embark upon a voyage to this small village to offer assistance."
                    delay (1500)
                    put "Due to the long journey to the village you are exhuasted when you finally reach it."
                    delay (1500)
                    put "You and your best friend Chansan the cleric head for the local tavern."
                    delay (1500)
                    put "On your way there, you can't help but notice a poster offering a reward to who ever"
                    delay (1500)
                    put "kills the trouble some goblins."
                    delay (1500)
                    put "As you proceed to the tavern, as you book a room, you are aproached by a group of"
                    delay (1500)
                    put "adventurers, who ask for your help, for they too, strive to stop the foul goblins"
                    delay (1500)
                    put "After consulting Chansan you agree to help these adventures; tomorrow you will"
                    delay (1500)
                    put "set out to kill the goblins and save the village and it's inhabitants."
                    delay (1500)
                    put "After a good nights sleep you wake up with an early start, and together with you"
                    delay (1500)
                    put "new friends; whos names are Warrik (a paladin), Narv (the rogue), and Veronica "
                    delay (1500)
                    put "(the Monk), you set out to the lair of the goblins. However as you advance toward"
                    delay (1500)
                    put "their lair on the road roughly halfway to your destination, you are ambushed by"
                    delay (1500)
                    put "a group of five goblins one of whom rushes towards you!"
                    delay (1500)
                    exit
                else
                    exit
                end if
            end if
            exit
        end loop
        exit
    end loop
end charCreate
%Backstory
proc mainGame
    %Activate processes
    fork charSheet
    fork gameConsole
    %Tutorial Encouter
    put " "
    put "You are attacked by a goblin! Defend yourself!"
    delay (2000)
    put " "

    %Calculate monster health
    if charClass = "Fighter" then
        monHp := Rand.Int (15, 25)
        monAc := Rand.Int (9, 14)
        monDmg := Rand.Int (1, 6)
    elsif charClass = "Wizard" then
        monHp := Rand.Int (13, 20)
        monAc := Rand.Int (12, 13)
        monDmg := Rand.Int (1, 4)
    else
        monHp := Rand.Int (12, 18)
        monAc := Rand.Int (11, 14)
        monDmg := Rand.Int (1, 6)
    end if
    loop
        loop
            put "Attacking goblin"
            roll := Rand.Int (1, 20)
            monRoll := Rand.Int (1, 20)
            if charClass = "Fighter" then
                dmg := Rand.Int (2, 8)
            elsif charClass = "Ranger" then
                dmg := Rand.Int (1, 6)
            end if
            if wizSpell >= 1 then
                put "Choose a spell to cast."
                get spellSelect
                if spellSelect = "1" then
                    dmg := Rand.Int (1, 4) + level
                    play (">2b>2a2b>2a2b>2a2b2b>2a2b>2a2b>2a2b