Hot answers tagged

16

PHP has the advantage that it is very widely supported by cheap webhosters. You can rent some shared-hosting LAMP (Linux, Apache, MySQL, PHP) webspace for peanuts. And that webspace can also host your website and the game client. The setup of most PHP applications is equally easy. Just copy the files to the webserver and you are done. This makes it very easy ...


8

One way to do this is not to change the actual values in the database in realtime. When the player logs on, you see how long it's been, and how much stuff he should have if he were earning during the time he was logged off, then update the value accordingly. One benefit of this is that if a player never logs on again, you're not spending server time and ...


6

I know your question is specifically asking about cron jobs, but I think a lot of web-based mmos are written using "completeTime" logic as opposed to lots of crons. When you start a long-running action, like building a granary that takes 5 hours to complete. The server will just mark the granary's completion time as start time + 5 hours and store that in ...


6

Several points: You should definitely enable error reporting and error logging into a file on the PHP side, otherwise you'll have no evidence of problems. AJAX errors usually cause little visible error to the user. You should check for errors on the Javascript side too PHP error handling is famous for being both bad (e.g. the default action for most ...


6

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. So when ShortBow, HuntingBow, CompositeBow, ElvenBow etc. all behave identical except for having different stats, then they would all be instances of the same class. When bows have different ...


5

For peer-to-peer communication between web browsers, WebRTC is likely the best option available. But keep in mind that it is not universally supported yet. Also keep in mind that while you might save traffic on the server this way, the perceived performance for your clients might be far worse, because consumer-grade internet connections will likely have far ...


5

Introduction There are pros and cons to each method of synchronization you gave that depend on a couple of factors. First, is your game singleplayer or multiplayer, second, how real-time is your game? If your game is only single player, you may want to consider having a client side only game which would make things simpler. However, assuming you need a ...


5

Token and App side So to do this you will need to get the the relevant Access Token from facebook: User Access Token if you want to post things on their behalf and access information about them. App Access Token if you want to change app settings You can read about it here but from what you have said you will probably want the User Access token. After ...


5

The other answers are correct, but there's a historical factor that hasn't been mentioned. When I started to search for do and donts and tips I realized that a lot of projects use PHP and I have actually not found any PBBG using C# which I find really strange. Until a couple years ago, there was a PBBG development community that mostly existed on two ...


4

What you will need to do is replay the entire game on your sever. If you use randomness in your game then store for each player the random seed you send them on your server and then have the server play the game to validate that their moves do indeed lead to a victory. This has the advantage that other types of cheating won't work either. If it's multi-...


4

I recently created a test program for an algorithm I found. It works on the premise of: I'm an evil overlord and I want more space. Basically the room is seems to be built out of necessity rather than uniformly with corridors. The stages are as follows. Fill the whole map with solid earth Dig out a single room in the centre of the map Pick a wall of ...


4

There is one thing that bothered me about your question: "..But the only programming language I know is Java." So learn another one! Anyway, Java as a client in the browser fails on many, many fronts. For one, Java 7 (and most likely Java 8) doesn't even work in Chrome on Mac OS X because the Java people decided to stop supporting 32-bit, and Chrome is ...


4

Card and Slot concepts should not be mixed. They're not the same. My behind is not fused with the chair on which I'm sitting. This allows me to play musical chairs. Let's organize your data: // A card; belongs to a player, has abilities (among which we find 'CanJump') Card Owner : Player // Blue or red CanJump : bool // Tells if the card can jump two ...


3

You want your webserver access to go through HTTPS; that will encrypt the traffic so people in the middle can't read it.


3

If you're smart with it, it won't be too resource intensive - but I definitely wouldn't try to run it every second (plus the shortest time interval for a cron is 1 minute). Because you mention actions occurring for a user when offline, a cron is probably your only option for that. For online actions, I recommend not having that in a cron, that way you can ...


3

Foreword: I'n not an expert about MMOanything or games in general, but I have a decent grasp on security and I wrote more than a single client/server app. Also being an avid gamer kind of helps. Your conclusion about the inability to protect your game is essentially correct, at least if you expect it to be 100% cheat free: whatever logic you delegate to the ...


3

It depends on your skill at programming, but it should be feasible. Remember, Facebook was built in PHP and it serves a pretty big crowd. A better question might be if PHP is the best choice for what you are trying to do. (And the answer is probably "no", unless it's the only language you know and you're not interested in learning a new one). You will need ...


3

I read somewhere that you shouldn't compare floats Beware programming by hearsay. This is a good way to make mistakes for reasons you don't understand. Instead, ask for clarification. The full advice here is "be careful when comparing floats for exact equality." Code like if (playerCoinBalance == 0) is safe enough with integers, but with floats the player'...


2

This sounds like a pretty simple task. First of all, you need a database to store your messages; presumably you already have one for your user accounts, but if you want recommendations, MySQL, PostgreSQL and SQLite are all common choices and should do fine. Next, you'll need a table to store the messages. A typical message table should probably contain at ...


2

Socket.io/node.js is precisely what you want. If you want to start a tad simpler, you could use ajax and an timeout to poll the server every 30 seconds or whatever time period to get a response concerning other players around. So really either take the active approach with socket "The server has just told me someone joined, someone answered, etc" or the ...


2

You can use websockets to resolve this problem. To be short, a websocket provides a way to exchange messages between several clients and your server. Principles Your websocket application could behave like this : Whenever someone opens your game web page, javascript will open a websocket connection with the server (You don't need any library on the client ...


2

tl;dr The resources should only be controlled by the Server (securely) as a decision making entity; The actual work could be offloaded to Clients and later verified lazily by the Server. Long story: How often you update the resources is up to you, your hardware and desired gameplay experience. I don't see why it requires you to update every second? What ...


2

I would suggest Perlin Noise to do this. Basically, generate N perlin noise values for each different factor, or, if you prefer 1 perlin noise value that gets hashed to a class (like planet, or emptiness): int x, y; // coordinates float scale; // The scale of the universe. Adjust this number to affect smoothness. float value = Perlin(x * scale, y * scale);...


2

Actually using the overloaded construct that take a WWWForm as second parameter, WWW class is automatically considered as an http post request. Your code can be something like: WWWForm form = new WWWForm(); form.AddField( "NUMBER", aNumber ); WWW postRequest = new WWW( server_url, form );


2

Handling negative values There are ways to handle negative values aside from healing the high-defense enemy with your sword strike (which is weird). You could introduce a block mechanic, where if target defense > attack power, the damage is nullified. But this is imbalanced. This might mean you might encounter an opponent who you will never hit. Of course ...


2

While I don't have much experience creating games with php/js I'd say that there are a few things you should consider. First thing that popped out to me is that you wanted to save positions in an SQL database - this seems like a terrible idea. It would be incredibly slow, consider how many times a second a game loop would run, times the number of entities ...


2

Solution A: Don't store the level or the experience points from the last levelup. Only store the total number of experience points the player collected from the start of the game. When you want to know the character's level, calculate it from the experience. Solution B: Replace exp= 0 with exp = exp - max_exp. That way excess experience will be carried over ...


2

Just fixed by doing the X coordinate with $x = $hexagon->ver + $i * $hexagon->size * 1.5; Looks beautiful now.


2

Found a better way to do by moving a cursor N times. public function getRadius($x, $y, $range) { $points = array(array($x,$y)); for($i=1;$i<=$range;$i++) { $curp = array($x,$y); for($j=1;$j<=$i;$j++) { $p = $this->hexagon->moveTo("N",$curp[0],$curp[1]); $points[] = $p; ...


2

Having a class for items is a good idea, but it is rarely useful to have a class for each item. When entities in a game differ by their values and not their behavior, then it is usually better to implement them as instances of the same class which differ by their data. The only case where you need to create new classes inheriting from Item is when you have ...


Only top voted, non community-wiki answers of a minimum length are eligible