ouverture de fenetre possible
faire le Game::run
This commit is contained in:
@@ -1,26 +0,0 @@
|
|||||||
//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) {
|
|
||||||
};
|
|
||||||
|
|
||||||
Bomb(Position position) : _position(position), _timer(3), _active(false) {
|
|
||||||
}
|
|
||||||
|
|
||||||
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
-1
@@ -1,3 +1,12 @@
|
|||||||
//Bomberman.cpp
|
|
||||||
#include "Bomberman.hpp"
|
#include "Bomberman.hpp"
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const Bomberman& b) {
|
||||||
|
os << "Bomberman at (" << b._x << ", " << b._y << ") with "
|
||||||
|
<< b._maxBomb << " max bombs, "
|
||||||
|
<< b._maxRange << " max range, "
|
||||||
|
<< b._bombPlanted << " bombs planted, "
|
||||||
|
<< "speed: " << b._speed
|
||||||
|
<< ", alive: " << (b._isAlive ? "yes" : "no")
|
||||||
|
<< ", invincible: " << (b._isInvincible ? "yes" : "no");
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|||||||
+12
-16
@@ -1,21 +1,17 @@
|
|||||||
// Bomberman.hpp
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include<iostream>
|
||||||
#include "Position.hpp"
|
|
||||||
#include "Bomb.hpp"
|
|
||||||
class Bomberman {
|
|
||||||
|
|
||||||
|
class Bomberman {
|
||||||
private:
|
private:
|
||||||
Position _position;
|
int _x, _y;
|
||||||
unsigned short _maxNumberOfBombs = 1;
|
unsigned short _maxBomb = 1;
|
||||||
unsigned short _numberOfBombsPlanted = 0;
|
unsigned short _maxRange = 1;
|
||||||
Bomb _bomb;
|
unsigned short _bombPlanted = 0;
|
||||||
|
float _speed = 1.0f;
|
||||||
|
bool _isAlive = true;
|
||||||
|
bool _isInvincible = false;
|
||||||
public:
|
public:
|
||||||
Bomberman(){std::cout << "Bomberman created!" << std::endl;}
|
Bomberman() = default;
|
||||||
~Bomberman(){std::cout << "Bomberman destroyed!" << std::endl;};
|
~Bomberman() = default;
|
||||||
int plantBomb();
|
friend std::ostream& operator<<(std::ostream& os, const Bomberman& b);
|
||||||
friend std::ostream& operator<<(std::ostream &os, const Bomberman &bomberman) {
|
|
||||||
os << "Bomberman at " << bomberman._position << ", Number of bombs: " << bomberman._numberOfBombs;
|
|
||||||
return os;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
|||||||
|
#include "Game.hpp"
|
||||||
|
|
||||||
|
Game::Game(){
|
||||||
|
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||||
|
throw std::runtime_error("SDL could not initialize! SDL_Error: " + \
|
||||||
|
std::string(SDL_GetError()));
|
||||||
|
}
|
||||||
|
|
||||||
|
window = SDL_CreateWindow("Bomberman", \
|
||||||
|
SDL_WINDOWPOS_CENTERED, \
|
||||||
|
SDL_WINDOWPOS_CENTERED, \
|
||||||
|
800, 600, \
|
||||||
|
SDL_WINDOW_SHOWN);
|
||||||
|
if (window == nullptr) {
|
||||||
|
throw std::runtime_error("Window could not be created! SDL_Error: " + \
|
||||||
|
std::string(SDL_GetError()));
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||||
|
if (renderer == nullptr) {
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
throw std::runtime_error("Renderer could not be created! SDL_Error: " + \
|
||||||
|
std::string(SDL_GetError()));
|
||||||
|
}
|
||||||
|
|
||||||
|
isRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Game::~Game() {
|
||||||
|
if (renderer) {
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
}
|
||||||
|
if (window) {
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
}
|
||||||
|
SDL_Quit();
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Game {
|
||||||
|
private:
|
||||||
|
SDL_Window* window = nullptr;
|
||||||
|
SDL_Renderer* renderer = nullptr;
|
||||||
|
bool isRunning = false;
|
||||||
|
public:
|
||||||
|
Game();
|
||||||
|
void Run();
|
||||||
|
~Game();
|
||||||
|
|
||||||
|
};
|
||||||
Binary file not shown.
@@ -1,19 +1,24 @@
|
|||||||
NAME = Bomberman
|
NAME = Bomberman
|
||||||
|
|
||||||
CC = g++
|
CC = g++
|
||||||
CFLAGS = -Wall -Wextra -Werror -g3
|
CFLAGS = -Wall -Wextra -Werror -g3 -I/usr/include/SDL2 -D_GNU_SOURCE=1 -D_REENTRANT
|
||||||
|
LDFLAGS = -lSDL2
|
||||||
|
|
||||||
SRC = main.cpp \
|
SRC = main.cpp \
|
||||||
Bomberman.cpp \
|
Bomberman.cpp \
|
||||||
|
Game.cpp \
|
||||||
|
|
||||||
|
DEPS = Bomberman.hpp \
|
||||||
|
Game.hpp \
|
||||||
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
|
|
||||||
$(NAME): $(OBJ)
|
$(NAME): $(OBJ)
|
||||||
$(CC) $(CFLAGS) -o $@ $(OBJ)
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ)
|
||||||
|
|
||||||
$(OBJ): $(SRC)
|
$(OBJ): $(SRC) $(DEPS)
|
||||||
$(CC) $(CFLAGS) -c $(SRC)
|
$(CC) $(CFLAGS) $(LDFLAGS) -c $(SRC) $(DEPS)
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
//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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
#include "Bomberman.hpp"
|
#include "Bomberman.hpp"
|
||||||
|
#include "Game.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
Bomberman bomberman;
|
try{
|
||||||
std::cout << bomberman << std::endl;
|
Game game;
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user