Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created August 28, 2015 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/35ad4af1dec38b3ee7b4 to your computer and use it in GitHub Desktop.
Save phpfiddle/35ad4af1dec38b3ee7b4 to your computer and use it in GitHub Desktop.
[ Posted by LiviuS ] functions + if/elseif + random
<?php
function getClass(){
$class = "Level 1";
$random = rand(0,3);
if($random==0)
{
$class = "Level 2";
}
elseif($random==1)
{
$class = "Level 3";
}
elseif($random==2)
{
$class = "Level 4";
}
return($class);
}
function getName(){
$name = "Apprentice";
$random = rand(0,3);
if($random==0)
{
$name = "Intermediate Apprentice";
}
elseif($random==1)
{
$name = "Advanced Apprentice";
}
elseif($random==2)
{
$name = "Higher Apprentice";
}
elseif($random==3)
{
$name = "Proffesional";
}
return($name);
}
function getAction(){
$action = "FIGHT!";
$random = rand(0,3);
if($random==0){
$action = ("FIGHT!");
}
elseif($random==1){
$action = ("RUN!");
}
elseif($random==2){
$action = ("SCREAM!");
}
elseif($random==3){
$action = ("DANCE!");
}
return($action);
}
$class1 = getCLass();
$name1 = getName();
$class2 = getCLass();
$name2= getName();
$class3 = getCLass();
$name3 = getName();
$action = getAction();
echo ("You are a " .$name1. " " .$class1. ".<br/>");
echo ("In your left there is a $name2 $class2 <br/>");
echo ("In your right there is a " .$name3. " " .$class3. ".<br/>");
echo (getAction());
echo ($action);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment