Jump to content

Want To Make My University Drinking Games More Fun


mike12255

Recommended Posts

Every now and then my roommate find ourselves short of supplies for a drinking game eg. cards. So I wip up a quick program to play it but its not very interactive. For example the game im showing today is a very simple one called horserace. (if you dont know how to play it youtube horserace drinking game, its fun) Anyway what I want to do to this game is add a button so that it draws one card at a time instead of drawing all the cards until the game is finished. I have not really used Ajax/javascript much before so Im looking for what frameworks you think would be best for this and even specific functions or any advice you have. In case anyone wanted to see what I have so far it can be seen here: http://5.9.44.54/~unigames/ (its a slow free webhost) and if for whatever reason you would like to see my code it is here:

 

 

<?php
//define the suits
$suits = array (
"Spades", "Hearts", "Clubs", "Dimonds"
);
//define ALL of the faces for a full deck
$fullFaces = array (
"Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King", "Ace"
);


//create the full deck array
$fullDeck = array();
//full the full deck with every card
foreach ($suits as $suit) {
foreach ($fullFaces as $face) {
$fullDeck[] = array ("face"=>$face, "suit"=>$suit);
}
}
//take out the aces for the game
$gameFaces = array (
"Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King"
);


//create a gamedeck array
$gameDeck = array();


//put all the cards except aces into the game deck
foreach ($suits as $suit) {
foreach ($gameFaces as $face) {
$gameDeck[] = array ("face"=>$face, "suit"=>$suit);
}
}


//shuffle the gamedeck
shuffle($gameDeck);
//create the image paths for the aces and back of cards
$aceSpades = "images/".$fullDeck['12']['face']."_".$fullDeck['12']['suit'].".png";
$aceHearts = "images/".$fullDeck['25']['face']."_".$fullDeck['25']['suit'].".png";
$aceClubs = "images/".$fullDeck['38']['face']."_".$fullDeck['38']['suit'].".png";
$aceDimonds = "images/".$fullDeck['51']['face']."_".$fullDeck['51']['suit'].".png";
$cardBack = "images/b2fv.png";


?>


<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title></title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen, projection" />
<!--[if lte IE 6]><link rel="stylesheet" href="style_ie.css" type="text/css" media="screen, projection" /><![endif]-->
</head>



<body>


<div id="parent">


<?php

//create an array to put each of the card images into
$heart = array();
$club = array();
$spade = array();
$dimond = array();


//setup counters to keep place in the array and make sure no more then 4 of one suite are drawen
$spadeCount = 0;
$heartCount = 0;
$dimondCount = 0;
$clubCount = 0;
//loop untill one suit has four cards
while ($spadeCount !=4 && $heartCount != 4 && $dimondCount != 4 && $clubCount != 4 ){
//draw another card from the game deck
$nextCard = array_shift($gameDeck);
//if card is hearts assign that to the next open hearts spot
if ($nextCard['suit'] == "Hearts"){

$heart[$heartCount] = "images/".$nextCard['face']."_".$nextCard['suit'].".png";

$heartCount++;

//if card is clubs assign that to the next open clubs spot
}else if ($nextCard['suit'] == "Clubs"){

$club[$clubCount] = "images/". $nextCard['face']."_".$nextCard['suit'].".png";
$clubCount++;
//if card is spades assign that to the next open spades spot
}else if ($nextCard['suit'] == "Spades"){

$spade[$spadeCount] ="images/". $nextCard['face']."_".$nextCard['suit'].".png";
$spadeCount++;

}else{
//card is dimonds assign it to the next dimonds spot

$dimond[$dimondCount] = "images/". $nextCard['face']."_".$nextCard['suit'].".png";
$dimondCount++;

}

}




//Fourth line
echo "<br/><div class=\"child\"> <img src=\"".$cardBack."\" /></div>"; //blank card
echo "<div class=\"child\"><img src= \"".$spade[3]."\"/></div>"; //spades
echo "<div class=\"child\"><img src= \"".$heart[3]."\"/></div>";//hearts
echo "<div class=\"child\"><img src= \"".$club[3]."\"/></div>";//clubs
echo "<div class=\"child\"><img src= \"".$dimond[3]."\"/></div><br/>";//dimonds

//Third line
echo "<div class=\"child\"> <img src=\"".$cardBack."\" /></div>"; // balnk card
echo "<div class=\"child\"><img src= \"".$spade[2]."\"/></div>"; //spades
echo "<div class=\"child\"><img src= \"".$heart[2]."\"/></div>";//hearts
echo "<div class=\"child\"><img src= \"".$club[2]."\"/></div>";//clubs
echo "<div class=\"child\"><img src= \"".$dimond[2]."\"/></div><br/>";//dimonds

//Second line
echo "<div class=\"child\"> <img src=\"".$cardBack."\" /></div>"; // balnk card
echo "<div class=\"child\"><img src= \"".$spade[1]."\"/></div>"; //spades
echo "<div class=\"child\"><img src= \"".$heart[1]."\"/></div>";//hearts
echo "<div class=\"child\"><img src= \"".$club[1]."\"/></div>";//clubs
echo "<div class=\"child\"><img src= \"".$dimond[1]."\"/></div><br/>";//dimonds

//First line
echo "<div class=\"child\"> <img src=\"".$cardBack."\" /></div>"; // balnk card
echo "<div class=\"child\"><img src= \"".$spade[0]."\"/></div>"; //spades
echo "<div class=\"child\"><img src= \"".$heart[0]."\"/></div>";//hearts
echo "<div class=\"child\"><img src= \"".$club[0]."\"/></div>";//clubs
echo "<div class=\"child\"><img src= \"".$dimond[0]."\"/></div><br/>";//dimonds


//draw the aces at the bottem
echo "<div class=\"child\"></div>";
echo "<div class=\"child\">";
echo "<img src=\"".$aceSpades. " \" alt= \"Card\">";
echo "</div>";
echo "<div class=\"child\">";
echo "<img src=\"".$aceHearts. " \" alt= \"Card\">";
echo "</div>";
echo "<div class=\"child\">";
echo "<img src=\"".$aceClubs. " \" alt= \"Card\">";
echo "</div>";
echo "<div class=\"child\">";
echo "<img src=\"".$aceDimonds. " \" alt= \"Card\">";
echo "</div>";


?>

</div>




</body>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.