Git Product home page Git Product logo

random_cards's Introduction

Random Cards

Random Selection Cards

Copy and run in local - PHP language

<!DOCTYPE html>
<html>
	<body>
		<head>
			<title> Random Card </title>
			<style type="text/css">
				 div{margin: 15px 0;}
				 /*font{border: 1px solid #ccc;padding: 6px 3px; margin-right: 10px;}*/
			</style>
			
			<script>
				function clicked(){
					var num = document.getElementById('number');
					
					if(num.value == ''){
						alert('Please insert any number..');
						return false;
					}
					
					if(num.value == 0 || num.value > 4){
						alert('Please insert a valid number (1-4)');
						return false;
					}
				}
			</script>
		</head>

		<h2>Random Card</h2>
		
		<?php 
			if (isset($_POST['number'])){
			//include 'card.php';	
			
			$num = $_POST['number'];
			$sp = poker();
			$sp2 = poker2();
			for($a=1; $a <= $num; $a++){
		?>
		
			<div> Player <?php echo $a;?> card -> 
				<?php
					 
					/* for ($i=1; $i <=13 ; $i++) { 
						 echo current($sp);
						 next($sp);
					} */
					
					for ($i=1; $i <=13 ; $i++) { 
						 echo current($sp2);
						 $i < 13 ? print(','):print('');
						 next($sp2);
					}
				?>
			</div>
			<?php 
				}
			}
			?>
		<font style='border: 1px solid #ccc;padding: 6px 3px; margin-right: 10px;'>
			S = ♠, <span style='color:red;'>H = ♥</span>, C - ♣, <span style='color:red;'>D = ♦️</span>
		</font>
		<form action="<?php echo $_SERVER['PHP_SELF'];?>" method='post' onsubmit='return clicked();'>
			<div>
				<input type='number' placeholder='insert number' name='number' style='text-align:center;width:130px; height:85px;' id='number' value='<?php if (isset($_POST['number'])){ echo $_POST['number'];}?>'>
			</div>
			<font color='red'><small>#Invalid No = 0, 5 and above</small></font>
		<br/>
		<br/>
		<input type='submit' value='Submit'>
		</form>
	</body>
</html>

<?php 
	function poker(){
		 //Set up an array to save the deck
		 $num = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
		 $icon = ['♥'=>'red','♦️'=>'red','♠'=>'black','♣'=>'black'];
		 //Generate deck
		 foreach ($icon as $key => $vi) {
			 foreach ($num as $vn) {
			  $poker[] = "<font style ='color:$vi;'> $vn $key </font>";
			 }
		 }

		 Shuffle ($poker); // shuffle
		 return $poker;
	}
	
	function poker2(){
		 //Set up an array to save the deck
		 $num = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
		 $icon = ['H'=>'red','D'=>'red','S'=>'black','C'=>'black'];
		 //Generate deck
		 foreach ($icon as $key => $vi) {
			 foreach ($num as $vn) {
			  $poker[] = "<font style ='color:$vi;'> $vn-$key </font>";
			 }
		 }

		 Shuffle ($poker); // shuffle
		 return $poker;
	}

?>

#Expectation Display

alt text

random_cards's People

Contributors

guasyed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.