Files
Taxon/mesFonctions.cpp

152 lines
3.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*====================================
AUTEUR : Jérémy Hébert & William Godin
PROJET : Taxon
NOM DU FICHIER : mesFonctions.cpp
DATE : 17 novembre 2025
BUT : Contient la définition des fonctions déclarées dans le fichier den-tête
====================================*/
//Librairies
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <Windows.h>
#include <iomanip>
#include "mesFonctions.h"
using namespace std;
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
#include <limits> //Sources : https://www.tutorialspoint.com/cpp_standard_library/limits.htm et https://stackoverflow.com/questions/2158943/split-string-into-array-of-chars
/*====================================
MENU
====================================*/
void afficherMenu(string nomFichier) {
fstream monFlux;
system("cls");
ouvrirFichier(monFlux, nomFichier);
afficherImage(monFlux);
fermerFichier(monFlux);
}
void ouvrirFichier(fstream& monFlux, string nomFichier) {
monFlux.open(nomFichier, ios::in);
if (!monFlux) {
cout << "Une erreur est survenue ! Veuillez relancer le programme.";
exit(1);
}
}
void afficherImage(fstream& monFlux) {
const char carre = 219;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); //Déclaration de variable pour les images
while (!monFlux.eof()) {
int val = 0;
monFlux >> val;
if (val == 99) {
cout << endl;
}
else {
SetConsoleTextAttribute(hconsole, val);
cout << carre << carre;
}
}
SetConsoleTextAttribute(hconsole, 15);
}
void fermerFichier(fstream& monFlux) {
monFlux.close();
}
void delai() {
// Source : https://search.brave.com/search?q=comment+ajouter+du+delai+avant+une+instruction+en+cpp&conversation=ee2f26795aae1fe85434f1&summary=1
this_thread::sleep_for(0.3s);
}
void curseur(bool interrupteur) {
// Source : https://search.brave.com/search?q=comment+cacher+notre+curseur+dans+la+console+en+cpp&summary=1&conversation=c93091ff881c9c38dfd1a2
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hConsole, &cci);
cci.bVisible = interrupteur;
SetConsoleCursorInfo(hConsole, &cci);
}
/*====================================
1 - JOUER
====================================*/
//fonction pour choisir le mot de facon random
void choisirMot(string nomFichier, int maximum) {
int numeroLigne = rand() % (maximum)+1;
fstream monFlux;
ouvrirFichier(monFlux, nomFichier);
string mot = goToLine(monFlux, numeroLigne);
fermerFichier(monFlux);
cout << numeroLigne << " " << mot;
}
string goToLine(fstream& monFlux, int numeroLigne) {
string mot;
for (int i = 0; i < numeroLigne; i++) {
getline(monFlux, mot);
}
return mot;
}
/*====================================
2 - OPTIONS
====================================*/
void background(int couleur) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
switch (couleur) {
case '1':
SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_INTENSITY);
break;
case '2':
SetConsoleTextAttribute(hConsole, BACKGROUND_RED);
break;
case '3':
SetConsoleTextAttribute(hConsole, BACKGROUND_BLUE);
break;
case '4':
SetConsoleTextAttribute(hConsole, BACKGROUND_GREEN);
break;
case '5':
//SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_INTENSITY);
break;
case '6':
//SetConsoleTextAttribute(hConsole, BACKGROUND_RED | BACKGROUND_INTENSITY);
break;
default:
SetConsoleTextAttribute(hConsole, BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
}
}
int demanderBackground() {
cout << "Choix";
int choix = _getche();
return choix;
}
void backgroundDefault() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, 0x0F);
}