Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Project: Videogame Hangman

Introduction

Hangman (also called Hanged Man) is a pencil and paper guessing game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it based on what he suggests with letters or within a certain number of possibilities.

Tech Stack

Programming Language: C++

IDE: DevC++

Introduction

Libraries Used

#include <iostream>
#include <string>
#include <conio.h>
#include <vector>
#include <fstream>
#include <time.h>
#include <stdlib.h>
#include <windows.h>
#include <colorwin.hpp>

Functions

Gotoxy

In charge of positioning the items on the screen.

void gotoxy(int x,int y){  
	 HANDLE hcon;
     COORD dwPos;
     dwPos.X = x;
     dwPos.Y= y;
     hcon = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleCursorPosition(hcon,dwPos);
}

Lifes

Place the hearts of life on the screen.

void Vidas(int corazones){
	//Coordenadas de la palabra Vidas
	gotoxy(2,1);
	cout<<"VIDAS: ";
	//Coordenadas borrar corazones
	for(int j=0;j<corazones;j++){
		gotoxy(9+j,1);
		cout<<" ";
	}
	//Coordenas imprimir corazones
	for(int i=0;i<corazones;i++){
		gotoxy(9+i,1);
		cout<<color(red)<<"\3";
	}
}

Initialize the words

Extract the words from the text file and replace the values of the variables: palabra_original and palabra_mostrar.

//Rellenar variables palabra_original y palabra_mostrar
void Inicializar(){
	palabra_original=Palabras();
	//Convertir la palabra en minusculas
	for(int i=0; i<palabra_original.length(); i++){
		if(palabra_original[i]>='A' && palabra_original[i]<='Z'){
			palabra_original[i]+=32;
		}
	}
	//Sobreescribir palabra_mostrar
	for(int i=0; i<palabra_original.length(); i++){
		if(palabra_original[i]>='a' && palabra_original[i]<='z'){
			//Si es una letra colocara el guion
			palabra_mostrar+='-';
		}else{
			//Si es un caracter especial, permanecera el caracter especial
			palabra_mostrar+=palabra_original[i];
		}
	}
}

Compare the words

If the entered letter is correct, it will replace the letter in the word to guess. Else, it lowers the life counter.

//Comparar letras con la palabra original
void Ingresar(char letra){
	bool LostVidas=true;
	//Comprobar letra con la palabra_original y reemplazar en la palabra_mostrar
	for(int i=0; i<palabra_original.length(); i++){
		if(letra==palabra_original[i]){
			LostVidas=false;
			palabra_mostrar[i]=letra;
		}
	}
	//Perder Vidas
	if(LostVidas==true){
		corazones--;
		//argumento 1: frecuencia o tono del sonido, y el argumento 2: duración.
		Beep(523,500);
	}
}

Open text file

Extract the words from the text file.

//Abrir archivo de texto - contenedor de palabras
vector<string> Coleccion_Palabras(){
	vector<string> palabras;
	string palabra;
	ifstream file_input_stream("Historial_de_Palabras.txt");
	while(file_input_stream>>palabra){
		palabras.push_back(palabra);
	}
	file_input_stream.close();
	return palabras;
}

Random number

Returns the number at random.

//Dar un número Aleatorio
int Numero_Aleatorio(int a){
	srand(time(0));
	int numero_aleatorio=rand();
	return numero_aleatorio%a;
}

Extract random word

Select a word from the text file at random.

//Sacar una palabra aleatoria
string Palabras(){
	vector<string> palabras=Coleccion_Palabras();
	int numero_aleatorio=Numero_Aleatorio(palabras.size());
	return palabras[numero_aleatorio];
}

Win

If you win, the score increases and lives are regenerated.

//Ganar
void Ganar(){
	if(corazones>0){
		system("cls");
		Escenario();
		gotoxy(40,8);
		cout<<"Palabra acertada"<<endl;
		gotoxy(40,9);
		cout<<color(green)<<palabra_mostrar<<endl;
		gotoxy(40,14);
		cout<<"Siguiente Nivel"<<endl;
		score+=10;
		corazones=6;
		palabra_mostrar.clear();
		gotoxy(40,25);
		system("pause");
	}
}

Lose

If he loses, he regenerates lives and returns to level 1.

//Perder
void Perder(){
	system("cls");
	Escenario();
	GameOver_Palabra();
	gotoxy(25,18);
	cout<<color(blue)<<"La palabra era: "<<color(red)<<palabra_original<<endl;
	gotoxy(25,20);
	cout<<"El puntaje obtenido es: "<<color(green)<<score;
	palabra_mostrar.clear();
	corazones=6;
	nivel=1;
	Ahorcado_Dibujo_Grande();
	gotoxy(19,25);
	system("pause");
	system("cls");
}

Example

Pantalla de Inicio

Pantalla de Opciones

Interfaz de Juego - Sección Adivinar

Ganar - Parte 1

Ganar - Parte 2

Perder - Parte 1

Perder - Parte 2

Créditos

Authors

Documentation

Report about Videogame

About

Hangman (also called Hanged Man) is a pencil and paper guessing game for two or more players. One player thinks of a word, phrase or sentence and the other tries to guess it based on what he suggests with letters or within a certain number of possibilities. Also, it is programmed in C ++

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages