Hey! I just startet fildeling around with c++ a week or so ago. I have some experience in Java and python. Anyways, i wanted to make this simple hangman game;
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void exit(int exitcode);
char hus[] = {'h', 'u', 's'};
char kage[] = {'k', 'a', 'g', 'e'};
void test1(char Input, int done) //function to test answer
{
r=0;
if (Input==kage[0]) {
if (Input==prog[0]) {
jump=1;
goto kage0;
}
prog[0] = 'k';
r=1;
point = point+1;
kage0:;
if (jump==1) {
r=2;
cout<<"Uups, tried that one already did we?..\n \n";
}
}
else if (Input==kage[1]) {
if (Input==prog[1]) {
jump=1;
goto kage0;
}
prog[1] = 'a';
r=1;
point = point+1;
}
else if (Input==kage[2]) {
if (Input==prog[2]) {
jump=1;
goto kage0;
}
prog[2] = 'g';
r=1;
point = point+1;
}
else if (Input==kage[3]) {
if (Input==prog[3]) {
jump=1;
goto kage0;
}
prog[3]= 'e';
r=1;
point = point+1;
}
else {
cout<<" Wrong one, try another.\n";
r=0;
point = point-1;
}
}
void game1()
{
int done; //variable to test progression
string previous; //holds previous tried letters
previous =" ";
done=0;
liv=10;
char Input;
while (done!=4) {
cout<<prog[0]<<" "<<prog[1]<<" "<<prog[2]<<" "<<prog[3]<<"\n";
if (liv==0) { //tests if the player is dead
cout<<"You are dead (try again)"<<"\n";
point=point/increase;
goto game1;
}
cout<<"guess the word: \n";
cin>>Input;
previous= previous+Input;
cout<<"\n";
test1(Input, done); //calls 'test' function
if (r==1) { //structure to count progression, saves in done
done = done+1;
}
else if (r==0) {
liv=liv-1;
}
if (done==4) { //tests if player has finished succesfully
cout<<"You made it :)\n";
point=point*increase;
cout<<prog[0]<<" "<<prog[1]<<" "<<prog[2]<<" "<<prog[3]<<"\n";
goto game1;
}
cout<<"Your changes left (0 means your dead): "<<liv<<"\n\n";
if (liv==5) {
cout<<"The guesses you have made so far: "<<previous;
cout<<"\n";
system("pause");
}
}
game1:;
}
int main()
{
int quit;
int n;
n=1;
quit=0;
srand(time(NULL));
rand();
do {
for(int q=0; q!=50; q++) {
prog[q] = '_'; //resets _ _ _
}
choose=rand()%3+0;
if (choose==0){
game1();
n++;
}
else if (choose==1) {
game2();
n++;
}
else if (choose==2) {
game3();
n++;
}
Right now i need to add the two functions shown (void test, void game)along with each new word i wish to add to the game. What i need help with is i would like to save the words the user guesses in a file and let the program load it on every run. That would give me the option of making void test() more general, thus the code shorter and i wouldnt need to make two new functions per word i add to the game.
Thanks in advance!
/Krokcy EDIT: removed some of the code