Jump to content
xisto Community
Sign in to follow this  
coolcat50

Php Card Game Engine

Recommended Posts

Ok, I have come up with a code that can be used to make card games. It is a deck script and is fairly complex. Here it is.

<?php//Start deck shuffle$deck=rand("1,52");//Start cards//Spades$s_ace=str_replace("1","A(S)",$deck);$s_2=str_replace("2","2(S)",$deck);$s_3=str_replace("3","3(S)",$deck);$s_4=str_replace("4","4(S)",$deck);$s_5=str_replace("5","5(S)",$deck);$s_6=str_replace("6","6(S)",$deck);$s_7=str_replace("7","7(S)",$deck);$s_8=str_replace("8","8(S)",$deck);$s_9=str_replace("9","9(S)",$deck);$s_10=str_replace("10","10(S)",$deck);$s_jack=str_replace("11","J(S)",$deck);$s_queen=str_replace("12","Q(S)",$deck);$s_king=str_replace("13","K(S)",$deck);//Diamonds$d_ace=str_replace("14","A(D)",$deck);$d_2=str_replace("15","2(D)",$deck);$d_3=str_replace("16","3(D)",$deck);$d_4=str_replace("17","4(D)",$deck);$d_5=str_replace("18","5(D)",$deck);$d_6=str_replace("19","6(D)",$deck);$d_7=str_replace("20","7(D)",$deck);$d_8=str_replace("21","8(D)",$deck);$d_9=str_replace("22","9(D)",$deck);$d_10=str_replace("23","10(D)",$deck);$d_jack=str_replace("24","J(D)",$deck);$d_queen=str_replace("25","Q(D)",$deck);$d_king=str_replace("26","K(D)",$deck);//Clubs$c_ace=str_replace("27","A(C)",$deck);$c_2=str_replace("28","2(C)",$deck);$c_3=str_replace("29","3(C)",$deck);$c_4=str_replace("30","4(C)",$deck);$c_5=str_replace("31","5(C)",$deck);$c_6=str_replace("32","6(C)",$deck);$c_7=str_replace("33","7(C)",$deck);$c_8=str_replace("34","8(C)",$deck);$c_9=str_replace("35","8(C)",$deck);$c_10=str_replace("36","10(C)",$deck);$c_jack=str_replace("37","J(C)",$deck);$c_queen=str_replace("38","Q(C)",$deck);$c_king=str_replace("39","K(C)",$deck);//Hearts$h_ace=str_replace("40","A(H)",$deck);$h_2=str_replace("41","2(H)",$deck);$h_3=str_replace("42","3(H)",$deck);$h_4=str_replace("43","4(H)",$deck);$h_5=str_replace("44","5(H)",$deck);$h_6=str_replace("45","6(H)",$deck);$h_7=str_replace("46","7(H)",$deck);$h_8=str_replace("47","8(H)",$deck);$h_9=str_replace("48","9(H)",$deck);$h_10=str_replace("49","10(H)",$deck);$h_jack=str_replace("50","J(H)",$deck);$h_queen=str_replace("51","Q(H)",$deck);$h_king=str_replace("52","K(H)",$deck);//Optional additions//Dealer system//Shuffle//Deal$pcards=array("$deck","$deck","$deck","$deck","$deck");$dcards=array("$deck","$deck","$deck","$deck","$deck");//Show handsif($deck == 0){die("I am sorry an error has occured with the card engine.")}else{echo "Dealer's cards" . "$dcards" , ".\n";echo "<br />";echo "Your cards" . "$pcards" . ".\n";}//Jokers//Change deck from rand(1,52) to rand(1,54)//Add this to the end$joker1=str_replace("53","Joker(R)",$deck);$joker2=str_replace("54","Joker(B)",$deck);//Indivual Decks//BETA$spades=array('$s_ace','$s_2','$s_3','$s_4','$s_5','$s_6','$s_7','$s_8','$s_9','$s_10','$s_jack','$s_queen','$s_king');//Soon to come

There is my card engine. It is in what I call version ALPHA. Well, enjoy. I will update it soon. Also, tests and modifications are welcome. This is a non-tested script.
Edited by coolcat50 (see edit history)

Share this post


Link to post
Share on other sites

I added a dealer system to it. The system is very basic but can be modified to do more than what it does. Also, i will occasionally post games with it that i come up with.

2 Card Poker

<?php//Engine code//Player Cards$pcards=array("$deck","$deck");$dcards=array("$deck","$deck");$ptotal=$pcards['0'] + $pcards['1];$dtotal=$dcards['0'] + $dcards['1'];//Start gameif($_POST['submit']{if($ptotal < $dtotal){echo "Dealer's cards"."$dcards";echo"Your cards"."$pcards";echo "Sorry you lost.";}else{echo "Dealer's cards"."$dcards";echo "Your cards"."$pcards";echo "You have won!";}}else{echo "<form method=\"post\">\n";echo "<input type=\"submit\" name=\"submit\" value=\"Click to play!\" />\n";echo "</form>"}

Share this post


Link to post
Share on other sites

That's a very clever script. The principles behind it could be applied to a lot of other things as well. I'm looking forward to seeing the finished version of this script. I can't see any errors in it, although I'm not exactly God's gift to PHP :P

Share this post


Link to post
Share on other sites

Hmm, well currently it is just a script that can be used to make others manually. i will set up a preview soon. Currently it is a basis on other PHP games such as Blackjack or poker or even War. Hmm I'll try to get a preview arcade set up. I just need a way to get it on to a site. I'll put it on my RPG site.Preview coming soon.

Share this post


Link to post
Share on other sites

Here is another card game!

<?php//1 Card Poker Version Beta//Engine code here//Shuffle//Deal$pcard=$deck;$dcard=$deck;if($_POST['submit']){if($pcard < $dcard){echo "Sorry, you have lost.\n";echo "You're card" . "$pcard" . "!\n";echo "Dealer's card" . "$dcard" . "!\n";}else{echo "You have won!!!\n";echo "Your card" . "$pcard" . "!\n";echo "Dealer's card" . "$dcard" . "!\n";}}else{echo "<form method=\"post\">";echo "<input type=\"submit\" name=\"submit\" value=\"Click to play!\" />"\n;echo "</form>";}?>

There is a one card poker game. Soon I might add a betting section to the games.
Edited by coolcat50 (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.