Created
November 23, 2017 18:46
-
-
Save jesuscmadrigal/c874c77e01a5e10e33b8f3d1ccc339df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
#include <ctime> | |
#include <stdio.h> | |
#include <cmath> | |
#include <string> | |
using std::cout; | |
using std::endl; | |
using std::cin; | |
using std::string; | |
string palabra_original; | |
string palabra_mostrar; | |
int intentos; | |
void mostrar(); | |
void ingresar (char x); | |
void inicializar(); | |
char a=92; | |
int horca(int intentos){ | |
if (intentos==9) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==8) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==7) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| |" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==6) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==5) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==4) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "| |" << endl; | |
cout << "|" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==3) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "| |" << endl; | |
cout << "| |" << endl; | |
cout << "|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==2) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "| |" << endl; | |
cout << "| |" << endl; | |
cout << "| _|" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==1) | |
{ | |
cout << " __________" << endl; | |
cout << "|" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "| |" << endl; | |
cout << "| |" << endl; | |
cout << "| _|_" << endl; | |
cout << "|___________" << endl; | |
} | |
if (intentos==0) | |
{ | |
cout << " __________" << endl; | |
cout << "| |" << endl; | |
cout << "| 0" << endl; | |
cout << "| _|_" << endl; | |
cout << "| |" << endl; | |
cout << "| |" << endl; | |
cout << "| _|_" << endl; | |
cout << "|___________" << endl; | |
} | |
} | |
int main(){ | |
cout << "Welcome to the best hangedman of the history" << endl; | |
cout << "Here you can learn some german, because that the purpose of this game" << endl; | |
cout << "that´s why all the words here are in german composed by an article and a noun" << endl; | |
cout << "Only one letter is accepted per attempt" << endl; | |
inicializar(); | |
mostrar(); | |
while (intentos>0 && palabra_mostrar!=palabra_original) | |
{ | |
char x=0; | |
cout<< "Please enter one the letter" << endl; | |
cin>> x; | |
ingresar(x); | |
mostrar(); | |
if (intentos>=0 && palabra_mostrar==palabra_original) | |
{ | |
cout << "Congrats!! you win" << endl; | |
} | |
if (intentos==0) cout << "Sorry you have lost, the word was: " << palabra_original << endl; | |
} | |
} | |
void mostrar() | |
{ | |
cout << "Attempts: " << intentos << endl; | |
cout << palabra_mostrar << endl; | |
} | |
void inicializar() | |
{ | |
const char* listadepalabras[6] = {"das ei","der stuhl", "der tisch","das kinder","die frau",'\0'}; | |
char numero; | |
srand(time(NULL)); | |
numero=rand()%6; | |
intentos=9; | |
palabra_original = listadepalabras[numero]; | |
palabra_mostrar = palabra_original; | |
for (int i=0 ; i<palabra_original.length(); i++){ | |
if (palabra_original[i]>= 'A' && palabra_original[i]<= 'Z'){ | |
palabra_original[i]+=32; | |
} | |
} | |
for (int i=0 ; i<palabra_original.length(); i++){ | |
if (palabra_original[i]>= 'a' && palabra_original[i]<= 'z'){ | |
palabra_mostrar[i]= '_'; | |
} | |
} | |
} | |
void ingresar(char x) | |
{ | |
bool perdividas=true; | |
for (int i=0; i<palabra_original.length(); i++) | |
{ | |
if (x==palabra_original[i]) | |
{ | |
perdividas=false; | |
palabra_mostrar[i]=x; | |
} | |
} | |
if (perdividas==true) | |
{ | |
intentos--; | |
horca(intentos); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment