Jul 20, 2008

Php Card Game Engine

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Php Card Game Engine

coolcat50
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.

CODE
<?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 hands
if($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.

 

 

 


Reply

sonesay
Pretty cool idea there. Im looking forward to seeing the final result.

Reply

coolcat50
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
CODE
<?php
//Engine code

//Player Cards
$pcards=array("$deck","$deck");
$dcards=array("$deck","$deck");$ptotal=$pcards['0'] + $pcards['1];
$dtotal=$dcards['0'] + $dcards['1'];

//Start game
if($_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>"
}

 

 

 


Reply

deadlyweapon
looks cool, any preview of what i would look like?



How do u make these kind of scripts?

Reply

OneMinute
You being hosted is well deserved. It had be better if you could share scripts that you make around.

Reply

MotU2510
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 biggrin.gif

Reply

coolcat50
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.

Reply

coolcat50
Here is another card game!

CODE
<?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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics
Looking for php, card, game, engine

Searching Video's for php, card, game, engine
advertisement



Php Card Game Engine



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE