Gerben Veenhof

RuneScape Adventure

<<

>>

Fight
Forest
Stats

Voor het eerst gingen wij werken met PHP en MySQL om een text adventure te maken. Elke pagina heeft opties waaruit je kunt kiezen, uit de gekozen optie word de volgende pagina geladen. Hieronder een paar features:

  • Spendeer punten met upgrades die meeschalen met de speler.
  • Kopen en dynamische aanvallen van tegenstanders.
  • Art van RuneScape ®

De speler heeft levens, level etc. te zien in de sidebar van het spel. Beweeg door het spel door onderin de pagina een keuze te maken wat je gaat doen.

Met de onderstaande knop kan je een zip downloaden met alle .php files en een setup voor de database die nodig is.

Download

Hier onder kan je code vinden van het project van een gevecht cyclus, waarbij de plek het bos is (forest).

Expand Code:
<?php
//Gets the main variabled from the database.
$EnemyDataBase = "Select * FROM monsters WHERE monsterid=$TempEnemy";
$EnemyData = $Connection->query($EnemyDataBase);
$GetEnemy = $EnemyData->fetch_assoc();
$TempEnemyName = $GetEnemy['name'];
$TempEnemyHealth = $GetEnemy['stamina'];
$TempEnemyStrength = $GetEnemy['strenght'];
$TempEnemyLoot = $GetEnemy['goldloot'];
$TempEnemyDexterity = $GetEnemy['dexterity'];		
echo("<p class='Orange'>" . $TempEnemyName.  "</p>");
//Selects the right image to display when fighting.
if($TempEnemy == 1)
{
$ImageSource = "Images/Bunny.png";
}
else if($TempEnemy == 2)
{
$ImageSource = "Images/Bear.png";
}
else if($TempEnemy == 3)
{
$ImageSource = "Images/Squirl.png";
}
else if($TempEnemy == 4)
{
$ImageSource = "Images/FlamingDragon.png";
}
else if($TempEnemy == 5)
{
$ImageSource = "Images/DarkDruids.png";
}
else if($TempEnemy == 6)
{
$ImageSource = "Images/ChaosBeast.png";
}
else
{
$ImageSource = "Images/Bunny.png";
}
echo("</br><img class='Image' src='".$ImageSource."'></img></br>");

//If the player has more Dexterity then he can attack first. 
if($TempDexterity > $TempEnemyDexterity)
{
$WhoHasTurn = 0;
}
else
{
$WhoHasTurn = 1;
}
//Simulates the fight till death.
while($TempEnemyHealth > 0 && $TempHitPoints > 0)
{
if($WhoHasTurn == 1)
{
	//Player who is doing damage.
	$WhoHasTurn = 0;
	//Blocking damage calculation.
	if(rand(0,$TempDexterity) > $TempDexterity / 8)
	{
		//Attack damage calculation.
		$TempEnemyHealth = $TempEnemyHealth - rand(1,10) * ($TempStrenght / 10) ;
		if($TempEnemyHealth < 0)
		{
			$TempEnemyHealth = 0; //No negative value.
		}
		echo("<p>You hit the ".$TempEnemyName." For ".$TempStrenght." Damage, Enemy health left: ".round($TempEnemyHealth)."</p>");
	}
	else
	{
		echo("<p class='Red'>Block Damage<p>");	
	}
}
else			
{
	//Enemy doing damage.
	$WhoHasTurn = 1;
	//Blocking damage calculation.
	if(rand(0,$TempEnemyDexterity) > $TempEnemyDexterity / 8)
	{
		//Attack damage calculation.
		$TempHitPoints = $TempHitPoints - rand(1,10) * ($TempEnemyStrength / 10);
		if($TempHitPoints < 0)
		{
			$TempHitPoints = 0; //No negative value.
		}
		echo("<p>The ".$TempEnemyName." did ".$TempEnemyStrength." Damage, Health left: ".round($TempHitPoints)."</p>");
	}
	else
	{
		echo("<p class='Green'>Block Damage<p>");	
	}
}
}

echo("<div class='Text'>");
//Text if you died.
if($TempHitPoints == 0)
{
echo("<p class='Red'>You lost and Died from the: ".$TempEnemyName.".</p>");
$MoneyLost = $TempGold / 4;
$TempGold = $TempGold - $MoneyLost;
echo("<p class='Red'>You Lost 25% of your gold</p>");
$TempHitPoints = $TempStamina * 10;
echo("<center><a href='index.php?Action=1'>To Town.</a></center>");
}
else
{
//Text if you won from the enemy.
$TempGold = $TempGold + $TempEnemyLoot;
$TempExperience = $TempExperience + $TempEnemyStrength;
echo("<p class='Green'>You won from the: ".$TempEnemyName.".</p>");
echo("<p class='Green'>You found: ".$TempEnemyLoot." gold from the carcas.</p>");
echo("<p class='Green'>You got: ".$TempEnemyStrength." Experience, Total: ".$TempExperience." Experience.</p>");

//Amount calculation.
if($TempExperience > 500 + ($TempLevel * 100))
{
	$TempLevel = $TempLevel + 1;
	$TempExperience = 0;
	$TempPoints = $TempPoints + 3;
	$TempHitPoints = $TempStamina;
	echo("<p class='Orange'>You got 3 Stat Points!</p>");
}
//Go back buttons.
if($Action == 6)
{
	echo("<center><a href='index.php?Action=5'>Go back To the ".$ActionName.".</a></center>");
}
if($Action == 4)
{
	echo("<center><a href='index.php?Action=3'>Go back To the ".$ActionName.".</a></center>");
}
}
?>