Code examples for simple game servers

后端 未结 3 985
眼角桃花
眼角桃花 2021-02-06 09:44

I\'d like to build an iPhone game for the Game Center and am currently researching the server part of it all. I learn best by example and I\'m having a hard time finding any ex

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 10:41

    OK, after reading your edit, Node.js should do the job quite well I think.

    Regarding your points:

    1. I don't know how exactly the pairing works(guess you get a pair of keys or so to validate the requests) but it should be hard to implement, regardless of the programming language.

    2. Easy: Setup a server, handle connections, keep a list of running games, for each game keep track of the state(players, time etc.), that should be at maximum(well depending on the message procotol you use..) 150-200 lines

    3. Just send some kind of ready event to each of the players in a given game when you deem that game to be ready(like everyone touched the 'I'm ready' button or so)

    4. OK, some tips here:

      1. Track the remaining/passed time on the server and send it to the players, timers get off pretty quickly(I had 4-5 secs off in just about 3 minutes)

      2. To prevent cheating, validate the moves on the server, that should be fairly easy in case of a puzzle game. You could also check the times between each move everything below 50ms should be suspicious, but that mainly depends on the difficulty of the puzzles.

    5. By checking the moves on the server this is pretty easy too, you don't have to rely on a client sending you a "Look I'm done" message.

    6. Again easy, just send out the events with the accompanying data and log the points into the db.

    The most important point is obviously the prevention of cheating, in case of a puzzle game where the solution can be easily solved by a computer, it's impossible to prevent it completely. Although, with the tips above you can make it harder.

    But keep in mind, you can't stop people from cheating on the high-scores when the game is simple, building more and more protection into the game just doesn't make sense. Focus on the game-play, make it interesting and simple for humans but complex and unpredictable for computers.

    In case of the DB, uh... I suppose you could go with MongoDB for that, but I haven't played around with that under Node yet.

    Oh, and if you want a impression what you can do with Node.js here's the game that I've built:
    http://github.com/BonsaiDen/NodeGame-Shooter

    All the logic runs on the server, the clients just draw the stuff they know about, I had a playable prototype up and running in two evenings.

提交回复
热议问题