Jump to content
  • Advertisement
Sign in to follow this  
Simon Lewis

Checkers Online with delphi

This topic is 515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Am looking for some help or src for a online checkers game I have made a basic single player game, but I really want to add net coding to it but with out any luck any help would be much appreciated,

Thanks.

Share this post


Link to post
Share on other sites
Advertisement

What, exactly, are you having trouble with? What have you tried so far?

It's hard to give any help when we don't know what the problem is.

 

At a very high level:

1) For players to find other players, you need some kind of server attached to the internet. What choices have you looked at, and what budget do you have?

2) For developing software that runs on the server (to connect players to each other,) some choices (cheap web hosts) may limit the languages you can use (like, perhaps only PHP?) whereas other choices let you choose both language and application server environment (virtual private servers, your own linux box, amazon, google, or microsoft clouds, etc.) What language would you use?

3) Once you know your environment, language, and possible toolkits, you need to figure out what kind of protocol you want to use. HTTP is very easy to work with everywhere, but requires each game to constantly "poll" state, and some environments may require you to persist state between web requests. Other approaches include using websockets, or persistent TCP connections, or action-game-like UDP protocols. Various libraries exist for these various options.

4) Once you have your server, hosting, environment, and protocol suite all selected, you end up with game-specific networking questions, like "what's a good way to keep clients in sync" or "how do I make sure players can't cheat."

Share this post


Link to post
Share on other sites

full project is done in delphi am going to be building a TCP client/server structure for the game that will run on any windows based server/computer I have a single player version of the game but I like to learn know how to turn it into a working online game so two players can face each other.

Share this post


Link to post
Share on other sites

So, if all you want is for two collaborating players to play each other, then you use WinSock to do this (or, if Delphi has some object that wraps WinSock.)

 

One player will "host" a game, and let the other player know his IP address. (Likely this needs firewall/router configuration to port forward.)

Serer calls socket() / bind() / listen() to set up the hosting game, and checks for incoming connections by calling select() on the listening socket in the main loop, and when it is readable, call accept() on it.

Client instead has some UI where the player enters the IP address of the server. Then call socket() / getaddrinfo() / connect() to connect to the server.

Once you have sockets (on client or server,) you call select() each time through the main loop, and if the socket is available for reading, call recv() with a sufficiently large buffer to drain whatever is pending in the buffer. Then parse whatever messages may be available in your buffer (note: you may receive partial messages in any particular recv() call, with the rest of the message following in the next recv())

When it's time to tell the other end about something, you can call send() right away, unless your send packet size is larger than the default socket buffer size. Typically, for games, this is not a probem.

 

If you want a "game browser" or other such central service, you need to write some service (using a similar methodology) that runs on a publicly available server. Azure Cloud has good deals on hosting Windows in the cloud.

Edited by hplus0603

Share this post


Link to post
Share on other sites

You can consider incoming network traffic as just another source of input, just like a player clicking somewhere or typing a key. Instead of asking "is there a key entered?", you ask "is there something on the network?". The only thing that is different is the player (network traffic comes from the remote player, key/mouse input from the local player).

 

If the local player makes a move, you not only update the local board, but you also send a message out to the remote player (so eventually, he receives that message as incoming network traffic, and his board gets changed too).

 

 

Before trying to add it to a game, you may first want to experiment with just the connection. Write a "send-move" function to send a move onto the network. Also, write a "is there a message" function along with "get the message". The less code you have that is not involved in the network connection, the simpler and faster you can experiment to get the network working.

Share this post


Link to post
Share on other sites

Ah, not really network related thus :)

 

I assume you have separate images for the board, and each of the stones. Since most of the stones are stationary, it makes sense to have some kind of list with stones and their position on the board, for the stationary stones.

 

The moving stone is an animation. You must draw the stone at a slightly different position each frame. If you draw the next frame often enough (to 10-15 frames each second), you see movement. To make this happen, have an xy position (in pixels) of the moving stone at the board, and a destination xy position (in pixels). If the destination x is bigger than the x of the moving stone, increment the stone x a little (add eg 2 pixels), else decrement it (subtract 2 pixels). For y, do the same thing.

 

Finally, you need a timer, that triggers a next frame 15 times a second, shifts the stone (if it has not arrived at its destination), and draws the board again.

 

 

Experiment with number of frames per second, and amount of shifting, until it looks good.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!