-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimalTypeClass.php
55 lines (55 loc) · 1.55 KB
/
AnimalTypeClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
class AnimalTypeClass
{
private $id;
function __construct($id)
{
$this->id = $id;
}
function createNewAnimal()
{
$db = new DatabaseClass();
$newAnimalRarity = $this->getRarity();
$newAnimalRarity += MathClass::getNormallyDistributedRand() / 4;
if($newAnimalRarity <= 0)
{
$newAnimalRarity = 0;
}
mysql_query("INSERT INTO animals (name, type, rarity) VALUES ('Unnamed', $this->id, $newAnimalRarity)");
$newAnimal = new AnimalClass(mysql_insert_id());
return $newAnimal;
}
function getID()
{
return $this->id;
}
function getName()
{
$db = new DatabaseClass();
$result = mysql_query("SELECT name FROM animalTypes WHERE id = $this->id");
$row = mysql_fetch_assoc($result);
return $row['name'];
}
function getRarity()
{
$db = new DatabaseClass();
$result = mysql_query("SELECT rarity FROM animalTypes WHERE id = $this->id");
$row = mysql_fetch_assoc($result);
return $row['rarity'];
}
function getTempLow()
{
$db = new DatabaseClass();
$result = mysql_query("SELECT tempLow FROM animalTypes WHERE id = $this->id");
$row = mysql_fetch_assoc($result);
return $row['tempLow'];
}
function getTempHigh()
{
$db = new DatabaseClass();
$result = mysql_query("SELECT tempHigh FROM animalTypes WHERE id = $this->id");
$row = mysql_fetch_assoc($result);
return $row['tempHigh'];
}
}
?>