I am new to C ++ and I am creating a game. I have a class main in which I declare
Game * game; //globally int main() { game = new Game(); game->show(); }
My class game initiates my game, etc. Now in other classes (player, enemy, etc.) I get variables from the game, such as player health, using
#include<game.h> extern Game * game; func::func() { game->health->resetHealth(); }
Is this encapsulation / ood paradigm a violation? Is this a bad practice? I see another way to do this for the game.
extern . - . extern .OOP, java, extern. Java / , .
extern
OOP
java
, , . game - , . - , game . - . OOD , " " Game * game. , GameController, Game *. Game * GameController, GameController -, , , . , . , , wrapping (, , ). , - , . . , , Game *, , . - .
game
Game * game
GameController
Game *
, . , , , , . extern , , .
- , , . , , : . , , ( , ).
, - , , :
, ; , , . A game .
, , . , , , .
, , ( - ), , , , , , .
, . , .