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
|
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
#include<windows.h>
#include<bits/stdc++.h>
using namespace std;
string line;
// Field information //
struct field_information
{
char mode;
int fieldsize, cellblock, cellreturn, maxran, minran;
int cellblocklocate[10];
int cellreturnlocate[10];
};
// Player information //
struct player_information
{
char playername;
int horsenum;
int pos[4];
int victorytime;
};
field_information field;
player_information player[4];
int col, row;
int lastcol[4][4];
int lastrow[4][4];
// savegame //
void savegame(field_information &field, player_information,int numberofmatches,int num,int playertogo)
{
ofstream loaddata;
loaddata.open("C:\\Users\\Public\\Documents\\loaddata.txt");
loaddata << field.fieldsize << endl;
loaddata << field.mode << endl;
loaddata << field.cellblock << endl;
for (int i = 1; i <= field.cellblock; i++)
loaddata << field.cellblocklocate[i] << endl;
loaddata << field.cellreturn << endl;
for (int i = 1; i <= field.cellreturn; i++)
loaddata << field.cellreturnlocate[i] << endl;
loaddata << numberofmatches << endl;
loaddata << field.maxran << endl;
loaddata << field.minran << endl;
loaddata << num << endl;
loaddata << playertogo << endl;
for (int i = 1; i <= num; i++)
loaddata << player[i].playername << endl;
for (int i = 1; i <= num; i++)
loaddata << player[i].horsenum << endl;
for (int i = 1; i <= num; i++)
for (int j = 1; i <= player[i].horsenum; j++)
loaddata << player[i].pos[j] << endl;
for (int i = 1; i <= num; i++)
loaddata << player[i].victorytime;
loaddata.close();
exit();
}
int loadgame(field_information &field, player_information (&player)[4], int &numberofmatches,int &playernum,int &playertogo)
{
ifstream file("C:\\Users\\Public\\Documents\\loaddata.txt");
if (file.is_open())
{
getline(file, line);
if (atoi(line.c_str()) != 0)
{
cout << "You have a save file, do you want to load it?\n";
cout << "1. Yes \n2. No\n";
cin >> choice;
}
else return 0;
}
if (choice == 1)
{
field.fieldsize = atoi(line.c_str());
file >> field.mode;
file >> field.cellblock;
for (int i = 1; i <= field.cellblock; i++)
{
file >> field.cellblocklocate[i];
}
file >> field.cellreturn;
for (int i = 1; i <= field.cellreturn; i++)
{
file >> field.cellreturnlocate[i];
}
file >> numberofmatches;
file >> field.maxran;
file >> field.minran;
file >> playernum;
for (int i = 1; i <= playernum; i++)
{
file >> player[i].playername;
}
for (int i = 1; i <= playernum; i++)
{
getline(file, line);
cout << line;
player[i].horsenum = atoi(line.c_str());
}
for (int i = 1; i <= playernum; i++)
for (int j = 1; i <= player[i].horsenum; j++)
{
file >> player[i].pos[j];
}
file >> playertogo;
for (int i = 1; i <= playernum; i++)
{
file >> player[i].victorytime;
}
file.close();
return 1;
}
else
{
file.close();
return 0;
}
}
int main ()
{
// Ready for statictical outcome //
int numberofmatches;
numberofmatches = 1;
// Start the game //
int situation;
srand (time(NULL));
// Welcome message //
cout << "Welcome to Horse Boardgame" << endl;
// Menu //
int gameload = loadgame(field, player, numberofmatches, playernum, playertogo);
}
|