Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Battle Test
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Planet_Fall




PostPosted: Sat Dec 28, 2013 11:11 pm   Post subject: Battle Test

What is it you are trying to achieve?
I'm trying to achieve a fighting system where the one with the highest SPD moves first and damage is calculated like this.
- To You: Enemy Attack - Your Defense (If < 0 it does 0 damage)
- To Enemy: Your Attack - Enemy Defense (If < 0 it does 0 damage)
- Where if you a Wizard you can cast magic
- If your not a Wizard you can't use magic
- And a RUN procedure with a 50/50 chance

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

Turing:


%   Call Variables
var E_name, name, p_class, choice : string
var enemy_names : array 0 .. 9 of string := init ("THEIF", "ZOMBIE", "SLIME", "ORC", "DEMON", "GHOST", "VAMPIRE", "BARBARIAN WARRIOR", "BARBARIAN ARCHER", "BARBARIAN LEADER")
var HP, ATK, DEF, M_ATK, M_DEF, SPD, EXP, LV, TEMP_HP : int := 0 % Player Stats Initiation
var HP_E, ATK_E, DEF_E, M_DEF_E, SPD_E : int := 0 % Enemy Stats Initiation
var wizard_class, battle_victory : boolean := false %For magic attacks
% var random_enemy :int := Rand.Int(0,9)

%   Call Procedure
procedure player_stats
    HP := Rand.Int (200, 500)
    TEMP_HP := HP
    ATK := Rand.Int (10, 25)
    DEF := Rand.Int (10, 25)
    M_ATK := Rand.Int (10, 25)
    M_DEF := Rand.Int (10, 25)
    SPD := Rand.Int (10, 25)
    LV := 1
end player_stats

procedure enemy_stats
    HP_E := Rand.Int (200, 500)
    ATK_E := Rand.Int (10, 25)
    DEF_E := Rand.Int (10, 25)
    SPD_E := Rand.Int (10, 25)
    M_DEF_E := Rand.Int (10, 25)
end enemy_stats

procedure show_stats
    put "Name: ", name : 7
    put "Class: Lv.", LV, " ", p_class : 7
    put "HP: ", HP
    put "ATK: ", ATK, "  ", "M.ATK: ", M_ATK, "  ", "SPD: ", SPD
    put "DEF: ", DEF, "  ", "M.DEF: ", M_DEF
    put "EXP : ", EXP
end show_stats

procedure show_stats_E
    put "Name: ", E_name : 7
    put "HP: ", HP_E
    put "ATK: ", ATK_E, "  ", "SPD: ", SPD_E
    put "DEF: ", DEF_E, "  ", "M.DEF: ", M_DEF_E
end show_stats_E

procedure get_class
    loop
        put "What Class are you? (FIGHTER/WIZARD/DEFENDER) ----> " ..
        get p_class
        if p_class = "FIGHTER" then
            player_stats
            ATK += M_ATK
            DEF += M_DEF
            exit
        elsif p_class = "WIZARD" then
            player_stats
            M_ATK += ATK
            M_DEF += DEF
            wizard_class := true
            exit
        elsif p_class = "DEFENDER" then
            player_stats
            M_DEF += ATK
            DEF += M_ATK
            exit
        else
            put "Please enter the choice EXACTLY like it shows."
        end if
    end loop
end get_class

procedure check_enemy_death
    if HP_E <= 0 then
        cls
        put skip
        put "YOU HAVE WON!"
        delay (3000)
        battle_victory := true
    else
    end if
end check_enemy_death

procedure check_player_death
    if HP <= 0 then
        cls
        put skip
        put "YOU HAVE DIED!"
        break
    else
    end if
end check_player_death

procedure battle
    cls
    var random_enemy : int := Rand.Int (0, 9)
    E_name := enemy_names (random_enemy)
    enemy_stats
    var damage_E : int := 0
    var damage : int := 0
    loop
        cls
        if battle_victory = true then
            exit
        end if
        show_stats
        put skip
        show_stats_E
        put skip
        if wizard_class = true then
            put "What do you do? (ATTACK/MAGIC/RUN) ----> " ..
            get choice
            if choice = "ATTACK" then

                if SPD_E > SPD then
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                    check_player_death

                    damage_E := ATK - DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death

                elsif SPD_E <= SPD then
                    damage_E := ATK - DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if

                end if
            elsif choice = "MAGIC" then

                if SPD_E > SPD then
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                    check_player_death

                    damage_E := M_ATK - M_DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death

                elsif SPD_E <= SPD then
                    damage_E := M_ATK - M_DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death

                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                end if
            elsif choice = "RUN" then
                var chance :int := Rand.Int(1,2)
                if chance = 1 then
                    put ""
                    put "You escape sucessfully!"
                    delay (1000)
                    exit
                else
                    put ""
                    put "You failed to escape!"
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                    check_player_death
                end if
            else
                put "Please enter a valid reply."
            end if
        else
            put "What do you do? (ATTACK/RUN) ----> " ..
            get choice
            if choice = "ATTACK" then
                if SPD_E > SPD then
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                    check_player_death
                    damage_E := ATK - DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death
                elsif SPD_E <= SPD then
                    damage_E := ATK - DEF_E
                    if damage_E <= 0 then
                        damage_E := 0
                        HP_E -= damage_E
                        put ""
                        put "Your enemy easily avoided the attack."
                        delay (1000)
                    else
                        HP_E -= damage_E
                        put "You deal ", damage_E, " Damage!"
                        delay (1000)
                    end if
                    check_enemy_death
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                end if
            elsif choice = "RUN" then
                var chance :int := Rand.Int(1,2)
                if chance = 1 then
                    put ""
                    put "You escape sucessfully!"
                    delay (1000)
                    exit
                else
                    put ""
                    put "You failed to escape!"
                    damage := ATK_E - DEF
                    if damage <= 0 then
                        damage := 0
                        HP -= damage
                        put ""
                        put "You easily avoided the attack."
                        delay (1000)
                    else
                        HP -= damage
                        put "Your enemy deals you ", damage, " Damage!"
                        delay (1000)
                    end if
                    check_player_death
                end if
            else
                put "Please enter a valid reply."
            end if
        end if
    end loop
    battle_victory := false
end battle

% ~Intro : Player Creation~
put "This is P.C.I.M, The Player Creation Intitilization Menu. Here you"
put "make you character."
put skip
put "Please enter your name ----> " ..
get name
get_class
put skip

battle




Please specify what version of Turing you are using
Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sat Dec 28, 2013 11:22 pm   Post subject: RE:Battle Test

If you keep trying to expand on your game this way, you're going to commit suicide. What we should focus on first is organizing your code, and trying to find ways to eliminate as much unnecessary code as possible.

First order of business: Records. http://compsci.ca/v3/viewtopic.php?t=9636
Planet_Fall




PostPosted: Thu Jan 02, 2014 8:01 pm   Post subject: Re: Battle Test

Sadly, I'm aware of this... but I have to work with what I know. BooHoo My teacher only taught me the basics of Turing. So stuff like GUI and records, and up to my last post, even arrays are new to me. Confused Thanks for the link, though. I'll try and work on the record it would be a lot better then programming the way I was.
Raknarg




PostPosted: Thu Jan 02, 2014 8:12 pm   Post subject: RE:Battle Test

Your unfamiliarity shouldn't be discouraging. Everyone here had to start from nothing, and it's better to learn now than later, right?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: