Skip to main content
Tweeted twitter.com/StackCodeReview/status/751190558081679360

c++ Singleplayer Class, Is there a good way to do this C++ single-player class?

I am making a little single player-player game and to help with scoring I have created a Player class. Can you review my implementation?

I know that for a multiplayer game this isn't good. ForFor multiplayer I would need to call functions and have all players in one instance.

###File player.h

namespace SDLGamecore { namespace player {   class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName)  { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; };   }} 

###File player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

###File main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Codecode works as expected. ThankThank you for any feedback and assistance in improving my single player class.

c++ Singleplayer Class, good way to do this?

I am making a little single player game and to help with scoring I have created a Player class. Can you review my implementation?

I know that for a multiplayer game this isn't good. For multiplayer I would need to call functions and have all players in one instance.

player.h

namespace SDLGamecore { namespace player {   class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName)  { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; };   }} 

player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Code works as expected. Thank you for any feedback and assistance in improving my single player class.

Is there a good way to do this C++ single-player class?

I am making a little single-player game and to help with scoring I have created a Player class. Can you review my implementation?

I know that for a multiplayer game this isn't good. For multiplayer I would need to call functions and have all players in one instance.

###File player.h

namespace SDLGamecore { namespace player { class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName) { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; }; }} 

###File player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

###File main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The code works as expected. Thank you for any feedback and assistance in improving my single player class.

Removed greetings
Source Link
forsvarir
  • 11.8k
  • 7
  • 39
  • 72

I makeam making a little Singleplayersingle player game and do now my new Playerto help with scoring I have created a Player class. Is this way good for that Singleplayer classCan you review my implementation?

I know for multiplayer that isnt good, for multiplayer need to call functions to have all players in one instance

I know that for a multiplayer game this isn't good. For multiplayer I would need to call functions and have all players in one instance.

player.h

namespace SDLGamecore { namespace player { class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName) { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; }; }} 

player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Code works fineas expected.

Thank Thank you for yourany feedback and assistance to possible a goodin improving my single player class.

Greetings Yannick

I make a little Singleplayer game and do now my new Player class. Is this way good for that Singleplayer class?

I know for multiplayer that isnt good, for multiplayer need to call functions to have all players in one instance

player.h

namespace SDLGamecore { namespace player { class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName) { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; }; }} 

player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Code works fine.

Thank you for your assistance to possible a good single player class.

Greetings Yannick

I am making a little single player game and to help with scoring I have created a Player class. Can you review my implementation?

I know that for a multiplayer game this isn't good. For multiplayer I would need to call functions and have all players in one instance.

player.h

namespace SDLGamecore { namespace player { class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName) { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; }; }} 

player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Code works as expected. Thank you for any feedback and assistance in improving my single player class.

Source Link

c++ Singleplayer Class, good way to do this?

I make a little Singleplayer game and do now my new Player class. Is this way good for that Singleplayer class?

I know for multiplayer that isnt good, for multiplayer need to call functions to have all players in one instance

player.h

namespace SDLGamecore { namespace player { class Player { private: long cash; int workers; std::string name; public: Player(std::string playerName) { name = playerName; cash = 0; workers = 0; } ~Player(){} long getCurrentCash() const; int getWorkers() const; std::string getPlayerName() const; }; }} 

player.cpp

namespace SDLGamecore { namespace player { long Player::getCurrentCash() const { return cash; } int Player::getWorkers() const { return workers; } std::string Player::getPlayerName() const { return name; } }} 

main.cpp

Player player("Test"); std::string pName = player.getPlayerName(); std::cout << pName << std::endl; 

The Code works fine.

Thank you for your assistance to possible a good single player class.

Greetings Yannick