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
|
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <windows.h>
#include <fstream>
#include "sha256.h"
using namespace std;
void MaximizeWindow()
{
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
SMALL_RECT rc;
rc.Left = rc.Top = 0;
rc.Right = (short)(min(info.dwMaximumWindowSize.X, info.dwSize.X) - 1);
rc.Bottom = (short) (min(info.dwMaximumWindowSize.Y, info.dwSize.Y) - 1);
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, &rc);
}
string userinput = "nul";
string name = "nul";
string currentenchant = "nul";
string checksum1 = "nul";
string checksum2 = "nul";
string checksum3 = "nul";
int namelength=0;
int magnumb=0;
int stonenumb=5;
int glowingstone=0;
int redgem=0;
int raind=0;
int trainswordatk=10;
int trainswordspd=10;
int trainswordlevel=0;
int swordmagicdmg=15;
int equippedmagic=0;
int equippedmagicmax=1;
int savelength=0;
bool trainsword=false;
bool firetrainsword=false;
bool icetrainsword=false;
bool poisontrainsword=false;
bool beginchest=false;
bool swordmagic=false;
bool swordmagicequip=false;
void SaveGame()
{
ofstream data("data.dat");
data << "\n";
data <<name;
data << "\n";
data <<userinput;
data << "\n";
data <<currentenchant;
data << "\n";
data <<magnumb;
data << "\n";
data <<stonenumb;
data << "\n";
data <<glowingstone;
data << "\n";
data <<redgem;
data << "\n";
data <<raind;
data << "\n";
data <<trainswordatk;
data << "\n";
data <<trainswordspd;
data << "\n";
data <<trainswordlevel;
data << "\n";
data <<trainsword;
data << "\n";
data <<firetrainsword;
data << "\n";
data <<icetrainsword;
data << "\n";
data <<poisontrainsword;
data << "\n";
data <<beginchest;
data << "\n";
data <<swordmagic;
data << "\n";
data <<swordmagicdmg;
data << "\n";
data <<swordmagicequip;
data << "\n";
data <<equippedmagicmax;
data << "\n";
data <<equippedmagic;
data << "\n";
data <<namelength;
data << "\n";
ofstream data1("data.dat");
ofstream chksum("chksum.dat");
checksum1 = sha256("data.dat");
chksum << checksum1;
}
void LoadGame()
{
int add = 0;
string line;
ifstream chksum("chksum.dat");
getline(chksum, line) >> checksum2;
ifstream chcsum("data.dat");
checksum3 = sha256("data.dat");
if (checksum3==checksum2)
{
goto goodcheck;
} else if (checksum3!=checksum2) {
cout << "Your current save has been modified from your previous one.\n\n";
cout << "Current: " << checksum3 << "\nPrevious: " << checksum2 << "\n\n";
getch();
exit(0);
} else {
cout << "There has been an error loading your game, please try again.\n\n";
getch();
return;
}
goodcheck:
ifstream data("data.dat");
while(data.is_open()){
if (add==0) getline(data, line) >> name;
if (add==1) getline(data, line) >> userinput;
if (add==2) getline(data, line) >> currentenchant;
if (add==3) getline(data, line) >> magnumb;
if (add==4) getline(data, line) >> stonenumb;
if (add==5) getline(data, line) >> glowingstone;
if (add==6) getline(data, line) >> redgem;
if (add==7) getline(data, line) >> raind;
if (add==8) getline(data, line) >> trainswordatk;
if (add==9) getline(data, line) >> trainswordspd;
if (add==10) getline(data, line) >> trainswordlevel;
if (add==11) getline(data, line) >> trainsword;
if (add==12) getline(data, line) >> firetrainsword;
if (add==13) getline(data, line) >> icetrainsword;
if (add==14) getline(data, line) >> poisontrainsword;
if (add==15) getline(data, line) >> beginchest;
if (add==16) getline(data, line) >> swordmagic;
if (add==17) getline(data, line) >> swordmagicdmg;
if (add==18) getline(data, line) >> swordmagicequip;
if (add==19) getline(data, line) >> equippedmagicmax;
if (add==20) getline(data, line) >> equippedmagic;
if (add==21) getline(data, line) >> namelength;
if (add==22) getline(data, line) >> savelength;
//if (add==23) getline(data, line) >> ; (These are for future use convenience)
//if (add==24) getline(data, line) >> ;
//if (add==25) getline(data, line) >> ;
//if (add==26) getline(data, line) >> ;
//if (add==27) getline(data, line) >> ;
//if (add==28) getline(data, line) >> ;
//if (add==29) getline(data, line) >> ;
//if (add==30) getline(data, line) >> ;
//if (add==31) getline(data, line) >> ;
//if (add==32) getline(data, line) >> ;
if (add==22) data.close();
add++;
}
cout << "Game loaded.\n";
getch();
}
|