first commit

This commit is contained in:
YANNIS
2025-05-29 16:06:07 +02:00
commit 33c6f3ccff
6 changed files with 102 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
//Bomb.hpp
#pragma once
#include "Position.hpp"
#include <iostream>
class Bomb {
private:
Position _position;
unsigned short _timer;
bool _active;
public:
Bomb(): _position({0, 0}), _timer(3), _active(false) {
std::cout << "Bomb created at default position " << std::endl;
};
Bomb(Position position) : _position(position), _timer(3), _active(false) {
std::cout << "Bomb created at " << position << std::endl;
}
void activate() { _active = true; }
void deactivate() { _active = false; }
bool isActive() const { return _active; }
void setPosition(Position position) { _position = position; }
Position getPosition() const { return _position; }
unsigned short getTimer() const { return _timer; }
};
+10
View File
@@ -0,0 +1,10 @@
//Bomberman.cpp
#include "Bomberman.hpp"
Bomberman::Bomberman(const Position &position, unsigned short numberOfBombs)
: _position(position), _numberOfBombs(numberOfBombs) {
std::cout << "Bomberman created at position ("
<< _position.getX() << ", " << _position.getY()
<< ") with " << _numberOfBombs
<< " bombs!" << std::endl;
}
+16
View File
@@ -0,0 +1,16 @@
// Bomberman.hpp
#pragma once
#include <iostream>
#include "Position.hpp"
#include "Bomb.hpp"
class Bomberman {
private:
Position _position;
unsigned short _numberOfBombs;
Bomb _bomb;
public:
Bomberman(){std::cout << "Bomberman created!" << std::endl;}
Bomberman(const Position &position, unsigned short numberOfBombs);
~Bomberman(){std::cout << "Bomberman destroyed!" << std::endl;};
};
+23
View File
@@ -0,0 +1,23 @@
NAME = Bomberman
CC = g++
CFLAGS = -Wall -Wextra -Werror -g3
SRC = main.cpp \
Bomberman.cpp \
OBJ = $(SRC:.cpp=.o)
all: $(NAME)
$(NAME): $(OBJ)
$(CC) $(CFLAGS) -o $@ $^
$(OBJ): $(SRC)
$(CC) $(CFLAGS) -c $(SRC) -o $@
clean:
rm -f $(OBJ)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: all clean fclean re
+19
View File
@@ -0,0 +1,19 @@
//Position.hpp
#pragma once
#include <iostream>
class Position {
private:
int _x;
int _y;
public:
Position() : _x(0), _y(0) {}
~Position() {}
Position(int x, int y) : _x(x), _y(y) {}
int getX() const { return _x; }
int getY() const { return _y; }
friend std::ostream& operator<<(std::ostream& os, const Position& pos) {
os << "Position(" << pos._x << ", " << pos._y << ")";
return os;
}
};
+6
View File
@@ -0,0 +1,6 @@
#include "Bomberman.hpp"
int main (void){
Bomberman bomberman;
return 0;
}