Jump to content
  • Advertisement

breakspirit

Member
  • Content Count

    28
  • Joined

  • Last visited

Community Reputation

100 Neutral

About breakspirit

  • Rank
    Member
  1. I'm currently designing a simple ascii-based game using c++ just to get a handle on basic game programming and I've got a few questions. If anyone knows of any guides on these topics, I'd love to read them. 1. What is the standard way to save game-save information in a single-player game? Things like exp or lives or whatever. I assume this would be saved in some sort of binary file? It seems like you'd want something that the user could not freely edit. I'm currently using .txt files and that is clearly not the way to go. 2. In a multiplayer client/server model, how would the server save and retrieve the game state/save information? In a database file full of players and stats perhaps? 3. How is level data stored typically? Again, it seems like this would be stored in such a way that users could not edit it. Like I said, I'm just doing a basic ascii game for now, so the levels would be very simple arrangements of characters on the screen. How should I store and retrieve this information? Like I said, if anyone knows of any guides on these topics, I'd be interested. Thank you for any assistance.
  2. I did that and added extern NetCode netConnection; to Game.h and that let me do netConnection.packetLoop(); in Game.cpp, so it appears to have worked. It mysteriously crashes when a client connects to the server, but that may not have anything to do with this. Thanks a lot for the help! Edit: the crash was completely unrelated. Whew. Thanks again.
  3. Hey guys, I've got two classes, Game and NetCode and I'm trying to get them able to communicate. Here's some relevant code: [heading]Main.cpp[/heading] #include "Game.h" #include "NetCode.h" NetCode netConnection; Game game; main() { game.gameloop(); } etc... [heading]Game.h[/heading] class Game{ //DECLARATION OF NETCODE OBJECT? //more stuff } [heading]Game.cpp[/heading] #include "Game.h" Game::gameloop() { here's the main game loop{ //need to be able to call NetCode methods here } } [heading]NetCode.h[/heading] extern Game game; class NetCode { //stuff } [heading]NetCode.cpp[/heading] #include "Game.h" #include "NetCode.h" //the rest of the NetCode methods. //these need to be able to call Game methods, as shown NetCode::examplefunc() { game.outputText("hey here's some output to parse"); } The code I've got compiles, but I now need a way for Game methods to be able to call NetCode methods and vice versa. I tried having a NetCode object as one of Game's member variables, but I couldn't see a way to get NetCode to then call Game's methods. I also have tried giving Game a pointer to a NetCode object as a member variable but have been unable to make that work. Can anyone enlighten me as to the correct way to accomplish this that is in line with OOP principles?
  4. breakspirit

    C++ << operator use within class

    Gotcha, thanks for the help. I'll avoid creating a new thread and just ask a followup question here: Suppose I want the << operator to work with multiple data types and not just strings. Would I have to overload the function repeatedly for every operator I'd want like this; inline GameSimulation& operator << (GameSimulation& lhs, const std::string inputString) { //stuff } inline GameSimulation& operator << (GameSimulation& lhs, const int inputInt) { //stuff } Or is there a way to make the input value something more generic? Thanks.
  5. breakspirit

    C++ << operator use within class

    That has indeed worked, thank you. I've got a couple questions though: Why make the char* a const? Is there any reason I shouldn't do a string instead of a character? Using character, it only outputs the first character. Using string, it outputs the whole string. I just want to make sure there isn't some good reason not to do the following: inline GameSimulation& operator << (GameSimulation& lhs, std::string inputString) { //some stuff here std::cout << inputString; return lhs; }
  6. Hey guys, please help me accomplish the following: I have a class called GameSimulation and I have the << operator set up so i can do GameSimulation gameObject; gameObject << "some text"; and the game will output that text in a specific way. Well, that works fine if i do that in main. However, how do i do the same thing from within the class? For example, here's a function in the class definition: void GameSimulation::setUpNewPlayer(Player *player) { gameWorld[player->location[0]] [player->location[1]] = player->sprite; ???? << "New player has been set up. There are now " << playerList.size() << " players online\n"; } What do I put in place of the question marks to make it use the GameSimulation::operator << (std::string textString) method that's in the same class? Thanks for your help. Edit: I tried 'this' and '*this' and neither worked.
  7. breakspirit

    c++ help me organize my includes correctly

    Thanks again for the help guys. I just want to update this thread for anyone who reads through it. I did resolve all my issues by the suggested methods except my array in gamesimulation still kept whining about the global constants used to size it. I ended up simply using #define GAME_WIDTH 30 instead of using a const and that instantly solved my issues. The global variables and constants I'm still using are correctly working with the extern command. Now to finally proceed with writing the fun stuff. Again, thanks for the help.
  8. breakspirit

    c++ help me organize my includes correctly

    by that, you mean doing the following in gamesimulation.h, right? extern const int GAME_WIDTH; extern const int GAME_HEIGHT; and the like with the rest of the globals? That's what I've been doing and it's not working for me. I did read the article you linked, twice now, and I feel like I'm just overlooking something. edit: It's just not working with the line char gameWorld[GAME_WIDTH][GAME_HEIGHT]; presumably because it needs to know the exact values of these globals. It did correctly get it to shut up about isServer.
  9. breakspirit

    c++ help me organize my includes correctly

    I'm down to just the errors with gamesimulation.h and cpp not being able to see the contents of Variables.h. If I uncomment out #include "Variables.h" I get different errors, as shown below: 1>main.obj : error LNK2005: "bool isServer" (?isServer@@3_NA) already defined in GameSimulation.obj 1>main.obj : error LNK2005: "void * hStdout" (?hStdout@@3PAXA) already defined in GameSimulation.obj 1>main.obj : error LNK2005: "unsigned __int64 startTime" (?startTime@@3_KA) already defined in GameSimulation.obj 1>NetCode.obj : error LNK2005: "bool isServer" (?isServer@@3_NA) already defined in GameSimulation.obj 1>NetCode.obj : error LNK2005: "void * hStdout" (?hStdout@@3PAXA) already defined in GameSimulation.obj 1>NetCode.obj : error LNK2005: "unsigned __int64 startTime" (?startTime@@3_KA) already defined in GameSimulation.obj 1>C:\Users\Kev\Desktop\Game stuff\Raknet stuff\RakNetTest\Debug\RakNetTest.exe : fatal error LNK1169: one or more multiply defined symbols found That makes me think that I'm including Variables.h too many times somewhere. Player.h is not including Variables currently and when it does, I get more errors of the same sort.
  10. breakspirit

    c++ help me organize my includes correctly

    Thanks for the input guys. I created the .cpp files and am still getting the same errors with the addition of the fact that gamesimulation has mysteriously forgotten about Variables.h. When I manually included it in gamesimulation.h, I got different errors. So, I included the current code and here's the errors: 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.cpp(101): error C2027: use of undefined type 'GameSimulation' 1> c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.h(21) : see declaration of 'GameSimulation' 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.cpp(101): error C2228: left of '.addNewPlayer' must have class/struct/union 1> GameSimulation.cpp 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.h(17): error C2065: 'GAME_WIDTH' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.h(17): error C2065: 'GAME_HEIGHT' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.h(19): error C2143: syntax error : missing ';' before '<' 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.h(19): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.h(19): error C2238: unexpected token(s) preceding ';' 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(7): error C2065: 'GAME_WIDTH' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(10): error C2065: 'GAME_HEIGHT' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(12): error C2065: 'GAME_HEIGHT' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(15): error C2065: 'GAME_WIDTH' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(21): error C2065: 'playerList' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(21): error C2228: left of '.push_back' must have class/struct/union 1> type is ''unknown-type'' 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(22): error C2065: 'playerList' : undeclared identifier 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\gamesimulation.cpp(29): error C2065: 'isServer' : undeclared identifier
  11. breakspirit

    c++ help me organize my includes correctly

    Yeah, but I don't think that is associated with this problem. I seldom do that unless the function is highly incomplete, such as with the simulation and player functions.
  12. breakspirit

    c++ help me organize my includes correctly

    Alright, here's all the source. Thanks again for your help.
  13. breakspirit

    c++ help me organize my includes correctly

    Nah it's in there. =/
  14. breakspirit

    c++ help me organize my includes correctly

    Yeah, I've tried including GameSimulation.h in netcode.cpp and I get link errors saying this kinda stuff: 1>NetCode.obj : error LNK2005: "public: __thiscall Player::Player(void)" (??0Player@@QAE@XZ) already defined in main.obj 1>NetCode.obj : error LNK2005: "public: __thiscall GameSimulation::GameSimulation(void)" (??0GameSimulation@@QAE@XZ) already defined in main.obj newPlayer and game get declared in main.cpp like this: #include "Variables.h" #include "GameSimulation.h" Player *newPlayer = new Player; // a pointer to a player object to give to new players. GameSimulation game; #include "NetCode.h" NetCode netConnection; I simply do not understand why netcode.cpp can not see newPlayer and game.
  15. breakspirit

    c++ help me organize my includes correctly

    Haha yeah I saw that and fixed it and smacked myself. Still getting errors though. I'm down to just two. Here they are: 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.cpp(100): error C2027: use of undefined type 'GameSimulation' 1> c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.h(22) : see declaration of 'GameSimulation' 1>c:\users\kev\desktop\game stuff\raknet stuff\raknettest\raknettest\netcode.cpp(100): error C2228: left of '.addNewPlayer' must have class/struct/union I've done a lot of moving things around, but basically I think my problem lies in NetCode.h because netcode.cpp still doesn't know anything about game but mysteriously doesn't have a problem with player. Here's the relevant chunk of code: #include "Variables.h" //#include "Player.h" //#include "GameSimulation.h" class GameSimulation; class Player; extern Player *newPlayer; extern GameSimulation game; class NetCode {} I don't understand why it needs me to include Variables.h again. You'll notice that I tried using extern in there but it has not fixed my issues.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!