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.











