. Updated Daily. Editions SDA India   SDA Indonesia
JAX Asia 2008 - Conference for Enterprise Java, SOA, Spring, Web Services, Ajax, Agile and more
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Wednesday, 24 January 2007

How to Transport Blackjack Game from C++ to PHP?

 

 

Jacob Santos in a new post over his blog shows you how to port a Blackjack game from C++ version to PHP. He also says, Blackjack can be a good alternative of ‘Hello World’ for those who want to learn a new language. He reasons out that Blakjack is simple and allows practice for the following:

  • Randomization
  • Handling input and output
  • Looping
  • Conditional Statements
  • Procedural Programming


He says running Blackjack with an OpenGL Toolkit may create some problems.

He provides the guidelines under the following two headings:

Procedural Programming

He comments its generally a bad idea to have everything in the main(), as it gets cluttered. For a project of this size, it is a good idea to break things down into reusable functions to help with debugging and development.

Keeping it Simple

He says that the idea to convert from C++ to PHP is quick and simple. He divides it into three parts giving the converting codes.
  • Introduction: the intro states the games intention and gets the game started. He provides the example code for better understanding. He points out that the interesting part worth noting is getch(), which gets a character for a variable. Since there is no variable, it will pause the console until one is pressed and then continue the execution. He also uses a similar code to explain how it can be converted into PHP.
  • Holding Statistics: he informs the original version held the stats in the main in separate variables and updated the variables by passing reference. But Jason uses a global struct instead. The usage would be similar for both languages. Only for C++, the access would use a period instead of the "->" symbol, in PHP.
  • Randomization: he says randomization is easier with PHP as you don't need to seed the random number using srand(). What Jason did is he worked on main() and left rand() in another function. He shows it with the example codes both in C++ and PHP. He finds out that PHP is much better to work with, as you don’t have to worry about the tricky math related to the modulus symbol.

 

Read the Post

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use