• Fichier: Display.cpp
  • Path: /dungeon_ascii/DungeonASCII/Display.cpp
  • File size: 4.84 KB
  • MIME-type: text/x-c
  • Charset: utf-8
 
Retour
#include "Display.h"

void Display::showTextScreen(std::string pString1, std::string pString2, std::string pString3)
{
	std::system("cls");

	std::string screenTextH1 = "";
	std::string screenTextH2 = "";
	std::string screenTextH3 = "";

	int spaceChar = 48 - pString1.size();
	for (int i = 0; i < spaceChar; i++)
	{
		spaceChar--;
		screenTextH1 += ' ';
	}

	screenTextH1 += pString1;

	for (int i = 0; i < spaceChar; i++)
	{
		screenTextH1 += ' ';
	}

	// String 2

	spaceChar = 48 - pString2.size();
	for (int i = 0; i < spaceChar; i++)
	{
		spaceChar--;
		screenTextH2 += ' ';
	}

	screenTextH2 += pString2;

	for (int i = 0; i < spaceChar; i++)
	{
		screenTextH2 += ' ';
	}

	// String 3

	spaceChar = 48 - pString3.size();
	for (int i = 0; i < spaceChar; i++)
	{
		spaceChar--;
		screenTextH3 += ' ';
	}

	screenTextH3 += pString3;

	for (int i = 0; i < spaceChar; i++)
	{
		screenTextH3 += ' ';
	}

	std::cout << "**************************************************" << std::endl;
	std::cout << "*                                                *" << std::endl;
	std::cout << "*" << screenTextH1 << "*" << std::endl;
	std::cout << "*" << screenTextH2 << "*" << std::endl;
	std::cout << "*                                                *" << std::endl;
	std::cout << "*                                                *" << std::endl;
	std::cout << "*                                                *" << std::endl;
	std::cout << "*" << screenTextH3 << "*" << std::endl;
	std::cout << "*                                                *" << std::endl;
	std::cout << "**************************************************\n" << std::endl;
}

int Display::showMenu(std::vector<std::string> pMenuElements)
{
	int option;
	do
	{
		int optionID = 1;
		for (int i = 0; i < pMenuElements.size() - 1; i++)
		{
			std::cout << optionID << " - " << pMenuElements[i] << std::endl;
			optionID++;
		}

		std::cout << "0 - " << pMenuElements[pMenuElements.size() - 1] << std::endl;

		std::cin >> option;
	} while (option > pMenuElements.size() && option < 1);

	return option;
}

std::vector<std::vector<char>>* Display::getBuffer()
{
	return &m_display;
}

void Display::render(Sector *p_sector, Player *p_player)
{
	// Ecraser le buffer par la map vide
	m_display = p_sector->getMap();

	// Mettre le joueur au bonnes coordonn�es dans le buffer
	m_display[p_player->getCoordinates()->y][p_player->getCoordinates()->x] = '@';

	// Effacer l'ecran
	std::system("cls");

	// Afficher le HUD
	std::cout << "Nom: " << p_player->getName() << " | ";

	std::cout << "Secteur: " << p_sector->getSectorName() << " | ";

	std::cout << "Coordonnee: X:" << p_player->getCoordinates()->x << (p_player->getCoordinates()->x < 10 ? "  " : " ");
	std::cout << "Y:" << p_player->getCoordinates()->y << (p_player->getCoordinates()->y < 10 ? "  | " : " | ");

	std::cout << "Vies: " << p_player->getHP() << std::endl;

	// Faire le rendu de la map
	for (int y = 0; y < m_display.size(); y++)
	{
		for (int x = 0; x < m_display[0].size(); x++)
		{
			std::cout << m_display[y][x];
		}

		std::cout << std::endl;
	}
}

int Display::showHomePage(Save *pSave)
{
	showTextScreen("DUNGEON ASCII", "Par Felix Jobin", "Desgraff 2018");

	std::vector<std::string> menuElements;
	menuElements.push_back("Creer une nouvelle partie");

	for (int i = 0; i < pSave->getGameFileCount(); i++)
	{
		menuElements.push_back("Charger une partie (Fichier " + std::to_string(i) + ")");
	}

	menuElements.push_back("Quitter le jeu");

	int menuOption = showMenu(menuElements);

	if (menuOption == 1)
	{
		std::system("cls");

		std::cout << "Entrez un nom a votre personnage: " << std::endl;
	}

	return menuOption;
}

int Display::showSuccessPage(short *gameState)
{
	if (*gameState == 2)
		showTextScreen("VICTOIRE", "Vous avez trouve le coffre!");
	else
		showTextScreen("DEFAITE", "Dommage, vous etes mort!");


	std::vector<std::string> menuElements;
	menuElements.push_back("Recommencer une nouvelle partie");
	menuElements.push_back("Retourner a l'accueil");

	int menuOption = showMenu(menuElements);

	if (menuOption == 1)
	{
		std::system("cls");

		std::string playerName;

		std::cout << "Entrez un nom a votre personnage: " << std::endl;
		
	}

	return menuOption;
}

int Display::showInGameMenu()
{
	std::system("cls");

	std::vector<std::string> menuElements;
	menuElements.push_back("Continuer la partie");
	menuElements.push_back("Recharger la derniere sauvegarde");
	menuElements.push_back("Sauvegarder la partie");
	menuElements.push_back("Quitter la partie");

	int menuOption = showMenu(menuElements);

	if (menuOption == 3)
	{
		std::system("cls");

		std::cout << "La partie a ete sauvegardee\n" << std::endl;
		std::system("pause");
	}

	return menuOption;
}

Display::~Display(){}