Jump to content


How would you do it


2 replies to this topic

#1 TheSpaniard

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 May 2008 - 06:21 AM

hey guys,
I have officially been programming in C++ for 2 days now, in an attempt to begin the long process of learning. My first program (of my own) was an attempt to create a dynamic endurance/capacity system for spellcasting.

here's the code I used:

// Laws of Magic v1.0
// Tolerance and stat system

#include <iostream>
using namespace std;

int main()
{
    // Variables
    
    // 3rd eye stats and tolerances
    double tEyeEndurance;
    double tEyeEnduranceMax;
    double tEyeEnduranceRegen;
    
    double tEyeEnduranceSlopeA;
    double tEyeEnduranceSlopeB;
    double tEyeEnduranceRangeA;
    double tEyeEnduranceRangeC;
    
    double tEyeEnduranceDrain;
    double tEyeEnduranceDrainX;
    
    double tEyeCapacity;
    double tEyeCapacityMax;

    // Other
    double manaCost;
    
    // Code Begins
            
    tEyeEndurance = 500.0;
    tEyeCapacity = 100.0;
    tEyeEnduranceMax = 500.0;
    tEyeEnduranceRangeC = .90;
    tEyeEnduranceRangeA = .40;
    tEyeCapacityMax = 100.0;
    tEyeEnduranceDrainX = 4.0;
    tEyeEnduranceSlopeA = .3;
    tEyeEnduranceSlopeB = .15;
    
    while (true)
    {   
        cout << "3rd eye stats" << endl;
        cout << "endurance: " << tEyeEndurance << "/" << tEyeEnduranceMax << endl;
        cout << "capacity: " << tEyeCapacity << endl;
        cout << "\nmanacost of spell?  ";
        cin >> manaCost;
        cout << endl <<endl;
        tEyeEnduranceDrain = ((manaCost * tEyeEnduranceDrainX) * (manaCost / tEyeCapacity) * (manaCost / tEyeCapacity));
        
        if (manaCost > tEyeCapacity)
        {
            cout << "You fail noob.\n Try Again.\n";
            continue;
        }
        if (tEyeEnduranceDrain > tEyeEndurance)
        {
            cout << "OMGZ OOM\n";                        
            cout << "Resetting stats.\n\n";
            tEyeEndurance = tEyeEnduranceMax;
            tEyeCapacity = tEyeCapacityMax;
            continue;
        }
        if (manaCost <= tEyeCapacity)
        {    
            cout << "Congratulations, you cast the spell for " << manaCost << " mana.\n";
            cout << "It drained " << tEyeEnduranceDrain << " endurance.\n\n" ;
            tEyeEndurance -= tEyeEnduranceDrain;
            
            if ((tEyeEndurance / tEyeEnduranceMax) >= tEyeEnduranceRangeC)
            {
                cout << "still fresh.\n\n";
                continue;
            }
            if ((tEyeEndurance / tEyeEnduranceMax) >= tEyeEnduranceRangeA)
            {
                cout << "a little tired.\n\n";
                tEyeCapacity = (tEyeCapacityMax - (tEyeEnduranceSlopeB * ((tEyeEnduranceMax * tEyeEnduranceRangeC) - tEyeEndurance)));
                continue;
            }
            if ((tEyeEndurance / tEyeEnduranceMax) < tEyeEnduranceRangeA)
            {
            
                cout << "friggin exhausted.\n\n";
                tEyeCapacity = tEyeCapacityMax - (tEyeEnduranceSlopeB * (tEyeEnduranceMax * (tEyeEnduranceRangeC - tEyeEnduranceRangeA))) - (tEyeEnduranceSlopeA * ((tEyeEnduranceMax * tEyeEnduranceRangeA)- tEyeEndurance));
                if (tEyeCapacity > 15)
                   tEyeCapacity = 15;
                continue;
            }
        
        }
    }
    return 0;
}
How would you have achieved the same effect? Keep in mind endurance and mana will be 2 separate things in the game I intend to make.

#2 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 907 posts

Posted 09 May 2008 - 02:38 PM

It isn't important how you solve the problem, the only thing that matters is that the problem gets solved.

If it works, then your job is done and you can move on to the next task :)

Btw, your code looks well-structured, but I will however comment on your use of 'noob' and 'OMGZ'. Unless it is a part of the game, consider using more friendly terms, instead of insults and IM-speak.
"Stupid bug! You go squish now!!" - Homer Simpson

#3 TheSpaniard

    New Member

  • Members
  • Pip
  • 7 posts

Posted 09 May 2008 - 10:30 PM

yeah this isnt really part of the game, just a test to make sure the if statements are working.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users