/*
* This program source code and all associated executables and files that
* may or may not be packaged and distributed are registered under the
* general public licence(GPL) and are free to be copied, re-compiled, edited,
* or just about anything else that you want to do with it. It is not
* required, but the authors(Nik 'xISOx' Daniel and David 'brfngmnky' Brees)
* would like to be credited for their work on this project. Thank You.
*
* As this is intended to be a learning project, we will be trying to document
* and explain what we do, but if you have no idea what any of the code is,
* the explanations may not make much sense. Go buy yourself a programming
* book if you want to learn how to program.
*
* The website for this project has yet to be determined, as it has no name.
*/
/* These things are the things that should appear at the beginning of any
* source code files, they basicly hold the data for the functions that we
* use regularly. (cout, cin, int, char) They are used by the pre-processor
* of the compiler, meaning that they are only used by the compiler, not the
* actual program. The '<>' denote universal files, and a '""' would denote
* a local file, but I'm not sure we'll be using those for this project.
*/
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
/*
* This next little line means that we will be using standard functions and
* calls in the code. This prevents us from having to type std:: in front of
* alot of the code.
*/
using namespace std;
//Defining the strings to be used for logon and saving purposes...
char playername[20];
char playerpass[20];
// Prototyping the functions...
void login (char playername[20], char playerpass[20]);
// The main function, what starts the actual program.
int main()
{
login(playername, playerpass);
cout << "DEBUG: This is where the game would be, if we had one..." << endl;
cin.get();
return 0;
}
void login(char playername[20], char playerpass[20])
{
int playerexists(0);
char newpass[20];
char verifypass[20];
cout << "Welcome to <Game Name>, please enter your username:" << endl;
cin.getline (playername,20);
ifstream in(playername);
in >> playerexists;
if (playerexists == 1) {
existinguser:
cout << "DEBUG: Preloading data for existing user " << playername
<< "...";
ifstream in(playername);
in >> playerexists >> playername >> playerpass;
cout << "Success." << endl;
cout << "Welcome back, " << playername << ". Please enter your "
<< "password:" << endl;
cin.getline (verifypass,20);
if (strcmp (verifypass,playerpass) == 0) { }
else {
cout << "Incorrect login, please try again...\nUsername:" << endl;
cin.getline (playername,20);
ifstream in(playername);
in >> playerexists;
if (playerexists == 1) { goto existinguser; }
else { goto newuser; }
}
}
else {
newuser:
cout << "A new player! " << endl;
do {
cout << "Please pick a nice password for " << playername << ":"
<< endl;
cin.getline (newpass,20);
cout << "Please re-enter your password for verification:" << endl;
cin.getline (verifypass,20);
} while (strcmp (newpass,verifypass) != 0);
cout << "DEBUG: Creating new PlayerFile..." << endl;
playerexists = 1;
playerpass = verifypass;
ofstream out(playername);
out << playerexists << " " << playername << " " << playerpass;
cout << "DEBUG: Done." << endl;
}
cout << "DEBUG: End of login function." << endl;
}
I am wondering if there is a way for the program to prompt the player for a command without making something like:
char arg[20];
cin.getline(arg,20);
switch (arg) {
case save:
save function call
case north:
north movement call
case quit:
save and then exit call
default:
cout << "What?\n" << endl;
}
Does this make any sense at all? Is this the way I will have to do it, it just seems ugly to me.
Also, how can you check to make sure a string has no spaces in it?












