vide
This commit is contained in:
1
TicTacToe/0
Normal file
1
TicTacToe/0
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Appuyez sur une touche pour continuer...
|
||||||
@@ -127,8 +127,12 @@
|
|||||||
<None Include="..\README.md" />
|
<None Include="..\README.md" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="fonctions.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="fonctions.h" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
|||||||
@@ -26,5 +26,13 @@
|
|||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="fonctions.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="fonctions.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
247
TicTacToe/fonctions.cpp
Normal file
247
TicTacToe/fonctions.cpp
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
/*====================================
|
||||||
|
AUTEURS : L<>a Dezothez et Sol<6F>ne Baillargeon
|
||||||
|
PROJET : Final
|
||||||
|
NOM DU FICHIER : fonctions.cpp
|
||||||
|
DATE : 2025-11-14
|
||||||
|
BUT : Fichier de fonctions Tic Tac Toe
|
||||||
|
====================================*/
|
||||||
|
|
||||||
|
#include "fonctions.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <fstream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
extern const int LARGTIC;
|
||||||
|
const string ICONJ1 = { "X" };
|
||||||
|
const string ICONJ2 = { "O" };
|
||||||
|
|
||||||
|
fstream monFlux;
|
||||||
|
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
char carre = 219, choix;
|
||||||
|
|
||||||
|
//Fichiers
|
||||||
|
void ouvrirFichier(std::fstream& monFlux, std::string nomFichier) {
|
||||||
|
monFlux.open(nomFichier, ios::in);
|
||||||
|
if (!monFlux) //On v<>rifie si le flux est "faux"/non fonctionnel.
|
||||||
|
{
|
||||||
|
cout << "ERREUR: Impossible d'ouvrir le fichier!" << endl;
|
||||||
|
system("PAUSE>0");
|
||||||
|
exit(1); //On quitte imm<6D>diatement le programme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fermerFichier(std::fstream& monFlux) {
|
||||||
|
monFlux.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Menu
|
||||||
|
void afficherMenu(char& choix) {
|
||||||
|
system("cls");
|
||||||
|
//T I C T A C T O E
|
||||||
|
ouvrirFichier(monFlux, "menuTitre.txt");
|
||||||
|
afficherImageMenu(monFlux);
|
||||||
|
fermerFichier(monFlux);
|
||||||
|
|
||||||
|
// Menu
|
||||||
|
cout << endl << "MENU" << endl << "----------------------------------" << endl
|
||||||
|
<< "A) 1 joueur" << endl
|
||||||
|
<< "B) 2 joueurs" << endl
|
||||||
|
<< "C) Montrer l'historique des scores" << endl
|
||||||
|
<< "D) Changer le style du jeu" << endl
|
||||||
|
<< "Q) Quitter" << endl << endl
|
||||||
|
<< "Quel est votre choix? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficherImageMenu(std::fstream& monFlux) {
|
||||||
|
int repet = 0;
|
||||||
|
if (monFlux) {
|
||||||
|
while (!monFlux.eof()) {
|
||||||
|
monFlux >> repet;
|
||||||
|
if (repet == 99) {
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
else if (repet == 0) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SetConsoleTextAttribute(hconsole, 15);
|
||||||
|
cout << carre << carre;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monFlux.close();
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "ERREUR : Impossible d<>ouvrir le fichier! " << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//G<>n<EFBFBD>ral (plusieurs options)
|
||||||
|
void afficherImageTableau(std::string grid[][LARGTIC]) {
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
string emoteUp,
|
||||||
|
emoteLine,
|
||||||
|
emoteDown;
|
||||||
|
ouvrirFichier(monFlux, "themes/themeSea.txt");
|
||||||
|
if (monFlux) {
|
||||||
|
while (!monFlux.eof()) {
|
||||||
|
monFlux >> emoteUp >> emoteLine >> emoteDown;
|
||||||
|
}
|
||||||
|
monFlux.close();
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << "ERREUR : Impossible d<>ouvrir le fichier! " << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
fermerFichier(monFlux);
|
||||||
|
|
||||||
|
cout << " ";
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
cout << " " << i + 1 << " ";
|
||||||
|
}
|
||||||
|
cout << " " << endl << " ";
|
||||||
|
for (int k = 0; k < LARGTIC; k++) {
|
||||||
|
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
for (int j = 0; j < 2; j++) {
|
||||||
|
cout << emoteUp << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << endl << " ";
|
||||||
|
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
cout << emoteLine;
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << emoteLine << endl << " " << k + 1 << " ";
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
cout << emoteLine << " " << grid[k][i] << " ";
|
||||||
|
|
||||||
|
}
|
||||||
|
cout << emoteLine << endl << " ";
|
||||||
|
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
cout << emoteLine;
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << emoteLine << endl << " ";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
|
for (int j = 0; j < 2; j++) {
|
||||||
|
cout << emoteDown << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tourJoueur(string grid[][LARGTIC], int joueur) {
|
||||||
|
int verticale,
|
||||||
|
horizontale;
|
||||||
|
|
||||||
|
cout << "\n\nTour du joueur " << joueur << endl;
|
||||||
|
afficherImageTableau(grid);
|
||||||
|
|
||||||
|
cout << "\n\nEntrez une coordonnee verticale : ";
|
||||||
|
cin >> verticale;
|
||||||
|
cout << "\nEntrez une coordonnee horizontale : ";
|
||||||
|
cin >> horizontale;
|
||||||
|
|
||||||
|
if (joueur == 1) {
|
||||||
|
grid[verticale - 1][horizontale - 1] = ICONJ1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
grid[verticale - 1][horizontale - 1] = ICONJ2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool verifFinMatch(std::string grid[][LARGTIC]) {
|
||||||
|
bool fin = true;
|
||||||
|
// Valide horizontales
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
fin = true;
|
||||||
|
for (int j = 0; j < 2; j++) {
|
||||||
|
fin = fin && grid[i][j] == grid[i][j + 1];
|
||||||
|
}
|
||||||
|
if (fin == true) {
|
||||||
|
return fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Valide verticales
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
fin = true;
|
||||||
|
for (int j = 0; j < 2; j++) {
|
||||||
|
fin = fin && grid[i][j] == grid[i + 1][j];
|
||||||
|
}
|
||||||
|
if (fin == true) {
|
||||||
|
return fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Valide diagonale de 00, 11, 22
|
||||||
|
fin = true;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
fin = fin && grid[i][i] == grid[i + 1][i + 1];
|
||||||
|
if (fin == true) {
|
||||||
|
return fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valide diagonale 02, 11, 20
|
||||||
|
for (int i = 2; i > 0; i--) {
|
||||||
|
fin = fin && grid[i][i] == grid[i - 1][i - 1];
|
||||||
|
if (fin == true) {
|
||||||
|
return fin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//1 joueur
|
||||||
|
void jeuUnJoueur(string grid[][LARGTIC]) {
|
||||||
|
bool fin;
|
||||||
|
cout << "\nUn joueur a ete choisi. Le joueur joue en premier.\n\n";
|
||||||
|
|
||||||
|
do {
|
||||||
|
tourJoueur(grid, 1);
|
||||||
|
tourOrdi(grid);
|
||||||
|
system("PAUSE>0");
|
||||||
|
fin = verifFinMatch(grid);
|
||||||
|
} while (fin = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tourOrdi(string grid[][LARGTIC]) {
|
||||||
|
int vertical = rand() % (3);
|
||||||
|
int horizontal = rand() % (3);
|
||||||
|
|
||||||
|
cout << "\n\nTour de l'ordinateur" << endl;
|
||||||
|
afficherImageTableau(grid);
|
||||||
|
|
||||||
|
grid[vertical][horizontal] = ICONJ2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//2 joueurs
|
||||||
|
void jeuDeuxJoueurs(string grid[][LARGTIC]) {
|
||||||
|
bool fin;
|
||||||
|
cout << endl << "Deux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre." << endl << endl;
|
||||||
|
|
||||||
|
do {
|
||||||
|
tourJoueur(grid, 1);
|
||||||
|
tourJoueur(grid, 2);
|
||||||
|
fin = verifFinMatch(grid);
|
||||||
|
// la condition doit <20>tre une s<>rie de 3 chiffres
|
||||||
|
} while (fin = true);
|
||||||
|
}
|
||||||
35
TicTacToe/fonctions.h
Normal file
35
TicTacToe/fonctions.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
/*====================================
|
||||||
|
AUTEURS : L<>a Dezothez et Sol<6F>ne Baillargeon
|
||||||
|
PROJET : Final
|
||||||
|
NOM DU FICHIER : fonctions.h
|
||||||
|
DATE : 2025-11-14
|
||||||
|
BUT : D<>claration fonctions pour le jeu Tic Tac Toe
|
||||||
|
====================================*/
|
||||||
|
|
||||||
|
/*test*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
const int LARGTIC = 3;
|
||||||
|
|
||||||
|
//Fichiers
|
||||||
|
void ouvrirFichier(std::fstream& monFlux, std::string nomFichier);
|
||||||
|
void fermerFichier(std::fstream& monFlux);
|
||||||
|
|
||||||
|
//Menu
|
||||||
|
void afficherMenu(char& choix);
|
||||||
|
void afficherImageMenu(std::fstream& monFlux);
|
||||||
|
|
||||||
|
//G<>n<EFBFBD>ral
|
||||||
|
void afficherImageTableau(std::string grid[][LARGTIC]);
|
||||||
|
void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser
|
||||||
|
bool verifFinMatch(std::string grid[][LARGTIC]);
|
||||||
|
|
||||||
|
//1 joueur
|
||||||
|
void jeuUnJoueur(std::string grid[][LARGTIC]);
|
||||||
|
void tourOrdi(std::string grid[][LARGTIC]);
|
||||||
|
|
||||||
|
//2 joueurs
|
||||||
|
void jeuDeuxJoueurs(std::string grid[][LARGTIC]);
|
||||||
@@ -1 +1,54 @@
|
|||||||
allo
|
/*====================================
|
||||||
|
AUTEURS : L<>a Dezothez et Sol<6F>ne Baillargeon
|
||||||
|
PROJET : Final
|
||||||
|
NOM DU FICHIER : main.cpp
|
||||||
|
DATE : 2025-11-14
|
||||||
|
BUT : Main pour le jeu Tic Tac Toe
|
||||||
|
====================================*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "fonctions.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
const string ICONJ1 = { "X" };
|
||||||
|
const string ICONJ2 = { "O" };
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
char choix;
|
||||||
|
string grid[LARGTIC][LARGTIC] = { " ", " ", " "," ", " ", " ", " ", " ", " "};
|
||||||
|
|
||||||
|
do {
|
||||||
|
afficherMenu(choix);
|
||||||
|
|
||||||
|
switch (choix) {
|
||||||
|
case 'A':
|
||||||
|
system("cls");
|
||||||
|
jeuUnJoueur(grid);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'B':
|
||||||
|
system("cls");
|
||||||
|
jeuDeuxJoueurs(grid);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'D':
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Q':
|
||||||
|
cout << "\nAu revoir!";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
cout << endl << "Saisissez un choix valide." << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
system("PAUSE>0");
|
||||||
|
} while (choix != 'Q');
|
||||||
|
}
|
||||||
8
TicTacToe/menuTitre.txt
Normal file
8
TicTacToe/menuTitre.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
2 2 2 2 2 0 2 2 2 2 2 0 2 2 2 2 0 0 2 2 2 2 2 0 0 2 2 2 0 0 2 2 2 2 0 0 2 2 2 2 2 0 0 2 2 2 0 0 2 2 2 2 99
|
||||||
|
0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99
|
||||||
|
0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99
|
||||||
|
0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 2 2 2 99
|
||||||
|
0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 2 2 2 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99
|
||||||
|
0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99
|
||||||
|
0 0 2 0 0 0 2 2 2 2 2 0 2 2 2 2 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 2 2 2 0 0 0 0 2 0 0 0 0 2 2 2 0 0 2 2 2 2 99
|
||||||
|
|
||||||
3
TicTacToe/themes/themeSea.txt
Normal file
3
TicTacToe/themes/themeSea.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
🌊
|
||||||
|
🔹
|
||||||
|
🪸
|
||||||
Reference in New Issue
Block a user