tp1 partie 1 et partie 2.1/2.2
This commit is contained in:
18
pendu/.vscode/c_cpp_properties.json
vendored
Normal file
18
pendu/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "windows-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "windows-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
pendu/.vscode/launch.json
vendored
Normal file
24
pendu/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/Users/kennr/Downloads/pendu",
|
||||
"program": "c:/Users/kennr/Downloads/pendu/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
59
pendu/.vscode/settings.json
vendored
Normal file
59
pendu/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
84
pendu/pendu_pbs.cpp
Normal file
84
pendu/pendu_pbs.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
// Code original généré par ChatGPT - nov 2024
|
||||
// Prompt : "Ecris moi un programme en C++ pour un jeu de pendu."
|
||||
// Modifications apportées : ajouts de bugs et d'erreurs de styles...
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Fonction pour afficher l'état actuel du mot deviné
|
||||
void afficherMot(const string& mot, const vector<bool>& lettresDevinees) {
|
||||
for (size_t i = 0; i <= mot.size(); i++) { // !!! Ne pas inclure "<=" mot size dans la taille de la boucle, crash lors de l'affichage du mot
|
||||
if (lettresDevinees[i]) {
|
||||
cout << mot[i] << " ";
|
||||
}
|
||||
else {
|
||||
cout << "_ ";
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
// Fonction pour vérifier si le joueur a deviné tout le mot
|
||||
bool motDevine(const vector<bool>& lettresDevinees) {
|
||||
for (bool devinee : lettresDevinees) {
|
||||
if (!devinee) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Liste de mots pour le jeu
|
||||
vector<string> words = { "ordinateur", "programmation", "developpeur", "algorithme", "variable" };
|
||||
|
||||
// Initialiser le générateur de nombres aléatoires
|
||||
srand(static_cast<unsigned int>(((time(0))))); // !!! Manque de deux parenthèses, échec lors de l'éxecution
|
||||
|
||||
// Choisir un mot aléatoire dans la liste
|
||||
string Mot = words[rand() % words.size()];
|
||||
|
||||
vector<bool> lettresDevinees(Mot.size(), false);
|
||||
int essaisRestants = 6; // Nombre maximum de tentatives
|
||||
|
||||
cout << "Bienvenue au jeu du pendu !" << endl;
|
||||
|
||||
while (essaisRestants > 0 && !motDevine(lettresDevinees)) {
|
||||
cout << "\nEssais restants: " << essaisRestants << endl;
|
||||
afficherMot(Mot, lettresDevinees);
|
||||
|
||||
cout << "Entrez une lettre : ";
|
||||
char lettre;
|
||||
cin >> lettre;
|
||||
|
||||
bool lettreTrouvee = false;
|
||||
for (int i = 0; i < Mot.size(); ++i){
|
||||
if (Mot[i] == lettre) // !!! deux = pour comparer et pas instancier, crash lors de comparaison
|
||||
{
|
||||
lettresDevinees[i] = true;
|
||||
lettreTrouvee = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lettreTrouvee) {
|
||||
cout << "Lettre incorrecte !" << endl;
|
||||
--essaisRestants;
|
||||
}
|
||||
|
||||
if (motDevine(lettresDevinees));
|
||||
{
|
||||
cout << "\nFélicitations ! Vous avez deviné le mot : " << Mot << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (essaisRestants == 0) {
|
||||
cout << "\nDommage ! Vous avez perdu. Le mot était : " << Mot << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user