Apr 4, 2013 at 2:06pm UTC
it just wont work and vc++ 2010 wont show if it wont work until I debug so if you can help with that to that would be great.
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;
int main()
{
string command ;
string save;
//menu
menu:
cout << " say newgame to start or, load to load new game " << endl;
cin >> command;
if (command == "newgame" );
if (command == "load" ) goto load;
system("cls");
//end
dstart:
int aipos[100][100][100] ;
//stats
int hp = 100;
int maxhp = 100;
int xp = 0;
//end
//spawn pos.
int x = 10;
int y = 10;
//end
//save
save:
if(save == void)
{
cout << "whats your save name?" << endl;
cin << save;
ofstream a_file(save);
}
close();
f.open( argv[ n ], ios::out | ios::trunc );
a_file << x;
a_file << y;
a_file << hp;
a_file << maxhp;
a_file << xp;
//end
start:
//map
int world [100] [100] = {0};
world [11] [10] = 9;
if (x == 98) x = 3;
if (x == 2) x = 16;
if (y == 98) y = 3;
if (y == 2) y = 16;
//end
//avatar
world[x][y] = 1 ;
//end
//death
if (hp < 1)
{
cout << "you died" << endl << endl;
goto dstart;
}
//end
//graphics script
cout << world[x+2][y+1];
cout << world[x-1][y+1];
cout << world[x][y+1];
cout << world[x-1][y+1];
cout << world[x-2][y+1];
cout << endl;
cout << world[x+2][y];
cout << world[x+1][y];
cout << world[x][y];
cout << world[x-1][y];
cout << world[x-2][y];
cout << endl;
cout << world[x+2][y-1];
cout << world[x+1][y-1];
cout << world[x][y-1];
cout << world[x-1][y-1];
cout << world[x-2][y-1];
cout << endl <<endl;
cout << "Health:" << hp << endl << endl;
//end
//movement script
cin >> command;
cout << endl;
if (command == "w" && world[x][y+1] != 9) y = y + 1;
if (command == "s" && world[x][y-1] != 9) y = y - 1;
if (command == "d" && world[x-1][y] != 9) x = x - 1;
if (command == "a" && world[x+1][y] != 9) x = x + 1;
if (command == "save") goto save;
//end
system("cls");
goto start;
load:
cout << "add .txt to the end of save name" << endl;
cin >> save;
ifstream load(save);
if(!load.is_open())
{
cout << "invalid or missing file" << endl;
goto menu;
}
load >> x;
load >> y;
load >> hp;
load >> maxhp;
load >> xp;
goto start;
return 0;
}
Last edited on Apr 4, 2013 at 2:06pm UTC
Apr 4, 2013 at 3:36pm UTC
Try replacing all of your goto sections with functions. Its the same idea, but its easier to read and doesn't create spaghetti code.
What is it that you hope to do here?
Apr 4, 2013 at 4:25pm UTC
well get it to save a txt file containing the x and y positions and stats
and whats a function???