1

Background info: I've recently decided to take on a project of making a social browser game. I have nothing large in mind at the moment, but in particular I want to experiment with making a facebook app for fun, that me and my friends can play (perhaps it gets more popular, but let me not get sidetracked).

Firstly, I would like to state that I feel I am above average at programming in general (I have developed a php/mysql website, made a rough 3d game engine in java, some embedded C programming, etc - to give an idea of the level of help I require). As stated, I know php and I can work with sql databases. My javascript is perhaps mediocre as I have not used it extensively, but I am learning and not finding it too difficult. I don't know flash at all, but it seems the trend is towards html5 and canvas.

To-the-point-question: I would like to start with html5+javascript, mySQL database and php. However, I am not too sure how to integrate this into a game. My main concern is what tool to use for communication between client and server. Am I wrong in saying that all relevant calculations (for instance, for resources), are kept server-side as advanced users can possible hack?

Secondly, how would you send data between client and server (obviously posting and reloading the page won't work)? I have used ajax before, but I'm not sure if this is the route to go.

I don't require an intricate answer (although I won't complain if I get one!). I'd be appreciative if someone can simply point me in the right direction. Thank you!

*I guess I should add that the game should be interactive, not text-based (as simply posting would work here)

***Anyone interested in the same problem, check this out: nodejs: Ajax vs Socket.IO, pros and cons (The reason I didn't find this before was that I was not aware of socket connections)

Community
  • 1
  • 1
Denzil
  • 664
  • 1
  • 8
  • 20
  • too broad, too subjective. you might try asking google. once you get something started, ask us for help if you get stuck. – Chris Drappier Mar 23 '12 at 18:11
  • 2
    take this discussion into http://chat.stackoverflow.com/ – code4life Mar 23 '12 at 18:18
  • 1
    It really depends on the game. Ajax or sockets are the most common route. The main thing required to make a game is to make a game. Since this is a pretty broad question, you might be better off asking it in the [Gamedev StackExchange Chat](http://chat.stackexchange.com/rooms/19/game-development) – thedaian Mar 23 '12 at 18:19
  • Perhaps I did not state my question properly. The first main question is simply, should the communication between client and server be implemented with AJAX? Still perhaps subjective, but what is generally done? I googled and got stuck, because most websites talk about flash, and on developers.facebook they talk about moving over to html5. The html5 tutorials I found were all for non-multiplayer/client-only games. – Denzil Mar 23 '12 at 18:23
  • Thank you @thedaian. I will look into using sockets vs Ajax. You should answer it so I can accept your answer as correct – Denzil Mar 23 '12 at 18:25
  • So the conclusion it seems is that I will use ajax for communication with the server (alternatively socket - but I'll have to read up on that some more) and keep the important logic on the server itself (to prevent hacking). – Denzil Mar 23 '12 at 18:41

2 Answers2

1

To expand on my previous comment:

There's two options for communicating between client and server in an html5 game right now. Which one you choose depends on what sort of game you're making. For real time, multiplayer type communication, you should use websockets, for something more turn based, than regular AJAX is fine (insert obligatory "use jQuery" here).

Also, yes, you want to keep your relevant calculations server side. Just use javascript to pass data to the server, and display that data (think MVC framework, where Javascript is the view)

Sidenote: If you do make a multiplayer/realtime focused game, you should avoid storing the current location of players in MySQL, because that will slow you down a lot. At that point, you're better off doing something else.

thedaian
  • 1,313
  • 9
  • 11
  • Thank you! Exactly what I am looking for (Sorry for asking it so vaguely. Guess I wasn't too sure what I was trying to say). Say the game is single player in the sense that you will only every see your own character(s) on the screen, but multiplayer in the sense that scores/resources are saved server side (and calculated there for security), will AJAX be fine? I'm feeling that I should lean towards websockets at the moment? I have no problem learning anything new. Thanks again – Denzil Mar 23 '12 at 19:06
  • In hindsight I could've named my question title a lot better :) – Denzil Mar 23 '12 at 19:08
  • 1
    @Denzil If the scores/resources don't need to be constantly updated in realtime (aka, more than 1 second or so before updating) then AJAX will be fine. Websockets is mostly if you need instant updates from the server about something, usually for something like other player positions or such. – thedaian Mar 23 '12 at 19:20
  • Thanks a lot. Your insights have been really helpful. I'll carry on researching a bit more (and learning), before attempting to implement. – Denzil Mar 23 '12 at 20:01
0

if you want to develop a facebook game, probably the best resource are the facebook developer pages that facebook publishes that describe the facebook API itself.

http://developers.facebook.com/docs/guides/canvas/

Mike Corcoran
  • 14,072
  • 4
  • 37
  • 49
  • Thank you, but I have done this already. I don't need help with canvas or integrating with facebook. My question is about client-server communication. – Denzil Mar 23 '12 at 18:24