1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
#define NOMINMAX // Must define NOMINMAX before including windows.h if you want to use the min() and max() macros.
#include <iostream>
#include <limits> // This header used for the cin.ignore(numeric_limits<streamsize>max(), '\n');
#include <cstdlib>
#include <stdlib.h>
#include <vector>
#include <fstream>
#include <string>
#include <time.h>
#include <Windows.h>
#include <iomanip>
using namespace std;
void battlefieldMenu(string, string, int, int, int, int, int, int);
double cAttack(int, int, int, int);
double mAttack(int, int, int, int);
void clearScreen();
void main ()
{
string charName, mobName;
int charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic,
battlefieldSelection, charStr, charDef, charDex, charIntel,
mobStr, mobDef, mobDex, mobIntel, cAttackCalc, mAttackCalc, selection, youWin = 1,
skillCount = 1, skillSelection;
string skillsArr [5] = {"fire", "water", "earth", "whatever", "hello"};
int inventory [25];
charName = "James";
mobName = "Mob";
charLevel = 1;
mobLevel = 1;
charHealth = 100;
mobHealth = 100;
charMagic = 100;
mobMagic = 100;
mobDef = 30;
mobStr = 35;
charDef = 20;
charStr = 55;
cout << fixed << showpoint << setprecision(2);
battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);
cin >> selection;
// input validation
while (selection < 1 || selection > 3){
if (cin.fail()){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Please enter a correct choice ";
cin >> selection;
}
while (charHealth > 0 && mobHealth > 0){
switch(selection){
case 1:
{
cAttackCalc = cAttack(charLevel, mobLevel, charStr, mobDef);
clearScreen();
mobHealth -= cAttackCalc;
if (mobHealth <= 0){
cout << "You win!\n\n";
system ("pause");
youWin = 0;
break;
}
battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);
cout << "You did " << cAttackCalc << " damage\n\n";
system("pause");
mAttackCalc = mAttack (charLevel, mobLevel, charDef, mobStr);
clearScreen();
charHealth -= mAttackCalc;
if (charHealth <= 0){
cout << "You lose...\n\n";
system ("pause");
youWin = 0;
break;
}
battlefieldMenu(charName, mobName, charLevel, mobLevel, charHealth, mobHealth, charMagic, mobMagic);
cout << "The enemy did " << mAttackCalc << " damage\n\n";
system("pause");
break;
}
case 2:
{
clearScreen();
for (int i = 0; i < 5; i++){
cout << "(" << skillCount << ") ";
cout << skillsArr[i] << " ";
skillCount++;
}
cout << endl << endl;
cout << "Choose a skill...";
cin >> skillSelection;
//input validation
while (selection < 1 || selection > 3){
if (cin.fail()){
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Please enter a correct choice ";
cin >> selection;
}
switch (skillSelection){
case 1:
{
}
}
cout << endl << endl;
system("pause");
break;
}
case 3:
{
break;
}
}
if(youWin == 0){
break;
}
cin >> selection;
}
}
void clearScreen()
{
DWORD n; /* Number of characters written */
DWORD size; /* number of visible characters */
COORD coord = {0}; /* Top left screen position */
CONSOLE_SCREEN_BUFFER_INFO csbi;
/* Get a handle to the console */
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo ( h, &csbi );
/* Find the number of characters to overwrite */
size = csbi.dwSize.X * csbi.dwSize.Y;
/* Overwrite the screen buffer with whitespace */
FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
GetConsoleScreenBufferInfo ( h, &csbi );
FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
/* Reset the cursor to the top left position */
SetConsoleCursorPosition ( h, coord );
}
double mAttack(int cLevel, int mLevel, int cDef, int mStr)
{
double health = 100.00;
double deductCharHealth = (mStr / 2) - (cDef / 2);
double deduct = (rand()%(int)deductCharHealth) + (deductCharHealth - (deductCharHealth * 0.75));
return deduct;
}
double cAttack(int cLevel, int mLevel, int cStrength, int mDefense)
{
double health = 100.00;
double deductMobHealth = (cStrength / 2) - (mDefense / 2);
double deduct = (rand() % (int)deductMobHealth) + ((int)deductMobHealth - (deductMobHealth * 0.75));
return deduct;
}
void battlefieldMenu(string cName, string mName, int cLevel, int mLevel, int cHealth, int mHealth, int cMagic, int mMagic)
{
// choose your selection.
int selection;
// displays both character's information.
cout << "Level - " << cLevel << setw(21) << "Level - " << mLevel << endl
<< cName << setw(20)
<< mName << endl
<< "Health -" << setw(5) << cHealth << setw(17) << " Health -" << setw(5) << mHealth << endl
<< "Magic -" << setw(5) << cMagic << setw(17) << "Magic -" << setw(5) << mMagic << endl;
cout << endl;
cout << "Choose an option\n"
<< "(1) Attack\n"
<< "(2) Skills\n"
<< "(3) Open Inventory\n\n";
}
|