[gameprogrammer] Re: Mulitplayer/Network support extendability
- From: Alan Wolfe <alan.wolfe@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 14 Oct 2005 15:03:39 -0700
Something you might do is try abstracting the process...
Here's what i mean, normaly when programming you would follow a path
something like this:
let's say you make a chess game, at first it's just you vs the computer so
you make your code have the player make their move and then the AI makes
it's move and you go back and forth until someone wins.
well, let's say now that you want to make it a 2 player chess game, you
would then have to rewrite it so that they could set a special mode where it
let the 1st player make a move, and then it let the second player make a
move and go back and forth until someone wins.
That's 1 re-write already.
Now let's say you wanted to add network support, now you would have to go
through and recode it so the 2nd player could make it's move through their
network, making this the 2nd rewrite.
These re-writes could be avoided with some foresight. Imagine if instead of
the above, you sat down to make your chess game and you had your main chess
game loop which would keep track of if it was player 1 or player 2's turn
and would loop until someone won.
Now, imagine there is a class or struct that held all information about a
player, and that there were 2 of these objects; 1 for player 1 an another
for player 2.
Inside of these objects was stored a player type (0=Player, 1 = CPU, 2 =
Player over network) as well as special information, such as player's
name...or in the case of CPU a difficulty level or in the case of player
over network, the player's IP address.
Now your main game loop would be like...
PlayerObject Player1,Player2;
// initialization code here like choosing if its 2 player, 1 player or 2
player networked
PlayerObject *CurrentPlayer;
CurrentPlayer=&Player1;
while((GameIsGoing())&&(NoOneHasWon()))
{
MovePlayer(CurrentPlayer);
SwitchTurns();
}
and then inside your MovePlayer() function it would just check to see if the
current player was across the network (in which case it would wait for them
to make a move), local on the keyboard (wait for them to input their move),
or if it was AI in which case it would calculate it's move and then move the
peice.
make sense?
In any case you could set it up like the above and just code the single
player function for now, and then later on code in multiplayer and netwowrk
multiplayer without having to change too muchcode.
this might all be stuff you already know but hope it helps
On 10/14/05, Gautam Narain <gautam_n_@xxxxxxxxxxx> wrote:
>
> Hi,
>
> I am writing a board game in which only 4 player will be able to interact
> with the game at a time. I am thinking of writing the game in such a way
> so
> that I can later on add network support into it. What I am wondering is
> should I worry about that part now or leave that for later when the time
> comes. Also in case I am only going to have 4 players interacting with the
> system at any given point of time, what would be the best method to make a
> multiplayer game over the network ? The game is not time critical and nor
> does it require high fps but at the same time I am looking at something
> that
> will not lag on the network. Also I don't think I will be able to
> pre-determine movement or information.
>
> Any suggestions ?
>
> Thanks
> Gautam
>
>
>
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
>
>
- Follow-Ups:
- [gameprogrammer] Re: Mulitplayer/Network support extendability
- From: Charlie Lobo
- References:
- [gameprogrammer] Mulitplayer/Network support extendability
- From: Gautam Narain
Other related posts:
- » [gameprogrammer] Mulitplayer/Network support extendability
- » [gameprogrammer] Re: Mulitplayer/Network support extendability
- » [gameprogrammer] Re: Mulitplayer/Network support extendability
- » [gameprogrammer] Re: Mulitplayer/Network support extendability
- » [gameprogrammer] Re: Mulitplayer/Network support extendability
- [gameprogrammer] Re: Mulitplayer/Network support extendability
- From: Charlie Lobo
- [gameprogrammer] Mulitplayer/Network support extendability
- From: Gautam Narain