first commit
This commit is contained in:
@@ -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; }
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;};
|
||||||
|
};
|
||||||
@@ -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
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user