Thread: Turning a single player game into multiplayer

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    42

    Turning a single player game into multiplayer

    Hello All,

    I'm in the middle of programming a text based adventure game and was thinking how nice it would be to make it multiplayer. Unfortunately, I have no idea how to go about this? So, I have a few questions:

    1. Is there any sample code I can use as an example?
    2. Are there any good books to read to accomplish this?

    I think I want to start off small by creating the program to initialize the game, accept connections and be able to communicate to each other in a chat-like environment. Then start the game and know what I need to know to ensure the game is synchronized between the two computers (possibly more).

    Edit: I'm also wondering if I'm going to make this a multiplayer game, will I have to start over with my code? Or can I just finish my game as a single player game, then add the required code to make it multiplayer later?
    Last edited by edomingox; 11-09-2017 at 10:50 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,994
    As an exercise, I would suggest you implement a simple Tic-tac-toe - Wikipedia, then add the feature where a remote player can connect.

    You then have to consider what sort of architecture to go with
    - client-server - a central server maintains the game state for everyone, and every player is a remote client.
    - peer-to-peer - every player controls their own state, and sends updates to everyone else.
    - master-slave - one machine controls everything, and the local player is likely 'god' or 'admin'.

    If you go client-server, are your clients thick or thin?
    Fat client - Wikipedia

    Design is important, if you want to avoid rewriting everything from scratch each time.
    Model–view–controller - Wikipedia

    For example, user input and display should be well isolated from game logic, so it's that much easier to replace a local GUI with a remote network equivalent.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I think for my game, I would want the client-server type. The game would run and everyone connects as a client. I think the main thing I need to do is ensure all the clients get the same data to display everything at the same time. Moving from room to room should be easy to send the same information to everyone. But then it gets confusing when you get into combat because there is more data running around.

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,656
    One advantage of peer to peer is if there are multiple independent groups of players playing that the same time, for example a racing game with many rooms of players in separate lobbies or separate races. The advantage is that you don't end up with all players in all races waiting for server response to update progress. The peer to peer data is usually minimal, such as position, velocity, control input position (use for prediction and also sound), ... . EA made a online racing game called Need For Speed World, based on prior peer to peer based games (including combining the maps from those older games). One issue is that they added powerups to the game which used a server handshake, and this created a delay in response to the powerups, and also caused EA to increase the size of their server farm to deal with all the player activity.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    so would it be difficult adding multiplayer into a text based game after it's already created? or would it be easier to start over?

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,994
    Well that depends entirely on the game, and what multi-player architecture model you're going with.

    If input and display are reasonably compartmentalised in the program (or can be refactored to be so), then adding some kind of remote connection shouldn't be too difficult.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Posts
    42
    I don't think i have it compartmentalized as much as it should be. As I have been programming it and testing it, I have been finding things I wished I should of done differently but settled with it thinking it's not that bad.

    I'm thinking I would like to have a multiplayer that is peer to peer, and you can use your single player character to join up in another single player's world. You can just tell a friend, "Hey, come to my world, I need help beating this guy." Or, "Hey, come to my world, I found a hidden area you need to check out." But that brings in factor's like cheating that I'd like to prevent. Like have a player drop a unique weapon for another player, disconnect, then start up their game with their last saved character. I'm sure I can eventually find a way around that.

    I think I will need to find some code that has a good example of input and display being compartmentalized properly. I'm thinking that my code is not.

  8. #8
    Registered User
    Join Date
    Apr 2013
    Posts
    1,656
    Even if the actual game play is peer to peer, you will need some way for players to communicate in order to join games, and this is where the client / server interface comes in. Again using past racing games as a model, some of them had a lobby for chat and invites, although if there's a huge number of players this can get hectic. For other racing games, a player indicated he wanted to join a race, and the server would match players together.

    While tutoring at a local junior college, where the main computer was an IBM 370, running batch jobs and an interactive programming language called APL. When the APL got upgraded to APL SV (shared variables) which allowed terminal to terminal communication, they had battleship board type game up and running within a week. There were some graphic terminals, and they later got a space wars type game up and running on those.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiplayer game development question
    By nbedoc in forum Game Programming
    Replies: 3
    Last Post: 04-18-2014, 10:22 PM
  2. How to setup a multiplayer game
    By suryak in forum Game Programming
    Replies: 2
    Last Post: 12-16-2011, 10:28 AM
  3. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  4. idea for multiplayer game
    By h_howee in forum Networking/Device Communication
    Replies: 10
    Last Post: 08-29-2007, 08:17 PM
  5. Far Cry Single Player Demo Available
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-21-2004, 03:37 PM

Tags for this Thread