0

I have written a game.

It is an async turn based game where each person logs in at any time in the day, submits their orders, and at some time at the end of the day, the present turn is resolved.

However, the client side needs to know how to resolve previous turns, because it has to display it visually with all its many nuances. I have written this turn resolution in javascript.

Unfortunately, there is a secrecy element to the present turn. So I cannot just send all the data for the present turn to someones machine, get it to use its javascript functions of turn resolution in the code, then send it back to the database for everyone else to gather when they log in. Why not? Because that one person could catch the data, see the secret bits from other players, before allowing it to be sent back.

That means I have to completely rewrite my javascript code in PhP, so the secret turn resolution of the present turn can be done in private on the server.

So here is my question. To help me having to write my turn resolution code twice, once in javascript for the client (who needs the visual interpretation from the turn resolution) and again in php so the secret stuff of the present turn can be done in private, is there any way my php code can call my javascript turn resolution code from the php page?

Ie, I want my php page to be able to call a javascript function in a js file, which is all done on the server.

0

1 Answer 1

1

Do you really need to do it in PHP ?

If your hosting solution support node.js, you can reuse directly your javascript inside your server-side app.

It's called isomorphic javascript. (see : http://isomorphic.net/)

Another way to do it, would be to embed a javascript engine and call it from PHP (e.g : https://github.com/phpv8/v8js)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Damien. Do you know of any home-computer based mockup servers like wamp server, that can mimic isomorphic javascript?
You can look-up the MEAN stack (mean.io) which stands for Mongo / Express / Angular / Node.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.