Skip to content

Commit 93b99fd

Browse files
committed
adding sample
1 parent a94cf0c commit 93b99fd

5 files changed

Lines changed: 130 additions & 3 deletions

File tree

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
Ce projet sert d'exemple pour expliquer le fonctionnement d'un Makefile. Il s'agit d'un petit jeu nommé "monjeu" compilé en C++.
44

55
## Structure du Makefile
6-
<!--
6+
7+
<!--
78
Le Makefile de ce projet est conçu pour compiler un jeu simple en C++ avec les fichiers suivants:
89
- `src/main.cpp`
910
- `src/Character.cpp`
@@ -124,11 +125,13 @@ Les bibliothèques statiques SFML pour Windows sont déjà incluses dans le proj
124125
1. **Télécharger SFML 3.0.2** depuis [https://www.sfml-dev.org/download.php](https://www.sfml-dev.org/download.php)
125126

126127
2. **Installer les dépendances** (dans MSYS2):
128+
127129
```bash
128130
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
129131
```
130132

131133
3. **Compiler SFML en mode statique**:
134+
132135
```bash
133136
cd /chemin/vers/SFML-3.0.2
134137
cmake -S . -B build-static \
@@ -137,11 +140,12 @@ Les bibliothèques statiques SFML pour Windows sont déjà incluses dans le proj
137140
-DBUILD_SHARED_LIBS=OFF \
138141
-DSFML_BUILD_EXAMPLES=OFF \
139142
-DSFML_BUILD_TEST_SUITE=OFF
140-
143+
141144
cmake --build build-static
142145
```
143146

144147
4. **Copier les bibliothèques** dans `lib/Windows/`:
148+
145149
```bash
146150
mkdir -p /chemin/vers/sample-sfml-project/lib/Windows
147151
cp build-static/lib/*.a /chemin/vers/sample-sfml-project/lib/Windows/
@@ -156,6 +160,7 @@ Les bibliothèques statiques SFML pour Windows sont déjà incluses dans le proj
156160
### Obtenir les Bibliothèques SFML pour macOS
157161

158162
Les bibliothèques macOS sont déjà dans `lib/macOS/`. Elles ont été compilées avec:
163+
159164
```bash
160165
cmake -S . -B build-static -G Ninja \
161166
-DCMAKE_BUILD_TYPE=Release \
@@ -174,4 +179,3 @@ Si vous devez les recompiler, suivez les mêmes étapes que pour Windows en adap
174179
3. Pour créer `$(NAME)`, make vérifie si tous les fichiers objets `$(OBJ)` existent
175180
4. Pour chaque fichier `.cpp` qui n'a pas de fichier `.o` correspondant ou qui a été modifié, la règle `%.o: %.cpp` est appliquée
176181
5. Une fois tous les fichiers objets créés, ils sont liés ensemble pour former l'exécutable final
177-
116 KB
Binary file not shown.

src/Character.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/******************************************************************************/
2+
/* */
3+
/* ::: :::::::: */
4+
/* Character.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmoumini <https://moustoifa.moumini.xyz/> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/04/22 19:36:53 by mmoumini #+# #+# */
9+
/* Updated: 2025/04/22 19:42:45 by mmoumini ### ########.fr */
10+
/* */
11+
/******************************************************************************/
12+
13+
#include "Character.hpp"
14+
#include <iostream>
15+
16+
using namespace std;
17+
18+
Character::Character() : _name("Hero") {
19+
cout << "Character created" << endl;
20+
}
21+
22+
Character::Character(const Character& other) : _name(other._name) {
23+
cout << "Character copied" << endl;
24+
}
25+
26+
Character& Character::operator=(const Character& other) {
27+
if (this != &other) {
28+
_name = other._name;
29+
}
30+
cout << "Character assigned" << endl;
31+
return *this;
32+
}
33+
34+
Character::~Character() {
35+
}
36+
37+
void Character::speak() const {
38+
cout << "My name is " << _name << "!" << endl;
39+
}

src/Game.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/******************************************************************************/
2+
/* */
3+
/* ::: :::::::: */
4+
/* game.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmoumini <https://moustoifa.moumini.xyz/> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/04/22 19:37:29 by mmoumini #+# #+# */
9+
/* Updated: 2025/04/22 19:43:25 by mmoumini ### ########.fr */
10+
/* */
11+
/******************************************************************************/
12+
13+
14+
#include "Game.hpp"
15+
#include <iostream>
16+
17+
using namespace std;
18+
19+
Game::Game() {
20+
cout << "Game initialized" << endl;
21+
}
22+
23+
Game::Game(const Game& other) : _mainCharacter(other._mainCharacter) {
24+
cout << "Game copied" << endl;
25+
}
26+
27+
Game& Game::operator=(const Game& other) {
28+
if (this != &other) {
29+
_mainCharacter = other._mainCharacter;
30+
}
31+
std::cout << "Game assigned" << std::endl;
32+
return *this;
33+
}
34+
35+
Game::~Game() {
36+
}
37+
38+
void Game::start() {
39+
cout << "Game starting..." << endl;
40+
_mainCharacter.speak();
41+
}

src/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/******************************************************************************/
2+
/* */
3+
/* ::: :::::::: */
4+
/* main.cpp :+: :+: :+: */
5+
/* +:+ +:+ +:+ */
6+
/* By: mmoumini <https://moustoifa.moumini.xyz/> +#+ +:+ +#+ */
7+
/* +#+#+#+#+#+ +#+ */
8+
/* Created: 2025/04/21 12:15:46 by mmoumini #+# #+# */
9+
/* Updated: 2026/01/26 11:39:28 by mmoumini ### ########.fr */
10+
/* */
11+
/******************************************************************************/
12+
13+
#include <SFML/Graphics.hpp>
14+
#include "Game.hpp"
15+
16+
17+
18+
int main() {
19+
Game game;
20+
game.start();
21+
22+
auto window = sf::RenderWindow(sf::VideoMode({1920u, 1080u}), "SFML Project");
23+
window.setFramerateLimit(144);
24+
25+
26+
while (window.isOpen())
27+
{
28+
29+
while (const std::optional event = window.pollEvent())
30+
{
31+
32+
if (event->is<sf::Event::Closed>())
33+
{
34+
window.close();
35+
}
36+
}
37+
38+
window.clear();
39+
40+
window.display();
41+
}
42+
return 0;
43+
}

0 commit comments

Comments
 (0)