Some Game Code ( 5 Views )
-
I am just messing about really. I am going to create a php game. I and I was just writing some code just, to get organized and see how I could put everything togethor in an OO kind of way. Its pretty basic but tell me what you think.
PHP Code:
<?php // Player Class class player{ var $hp; var $name; function player($name,$hp){ $this->name = $name; $this->hp = $hp; } } // Battle Class class battle{ var $player; var $opp; function battle (&$player, &$opp){ $this->player = $player; $this->opp = $opp; } function dead_opp(){ if ($this->opp->hp <= 0){ return TRUE; } else{ return FALSE; } } function dead_player(){ if ($this->player->hp <= 0){ return TRUE; } else{ return FALSE; } } function winner(){ if ($this->dead_player()){ return $this->opp->name; } elseif ($this->dead_opp()){ return $this->player->name; } } } // Attack Class class attack{ var $player; var $message; function attack(&$player){ $this->player = $player; $this->melee(10); } function melee($damage){ $dmg = rand($damage-5,$damage+5); $this->player->hp -= $dmg; $this->message = ''.$this->player->name.'('.$this->player->hp.') was hit for '.$dmg.' points of damage <br />'; } function update_player(){ return $this->player; } function send_message(){ return $this->message; } } function fight(&$player,&$opp){ // New Battle $battle =& new battle($player,$opp); // While the players are still alive while (!$battle->dead_opp() && !$battle->dead_player()){ // OPP GETTING ATTACKED BY PLAYER $attack =& new attack($battle->opp); echo $attack->send_message(); $battle->opp = &$attack->update_player(); // PLAYER GETTING ATTACKED BY OPP $attack =& new attack($battle->player); echo $attack->send_message(); $battle->player = &$attack->update_player(); } return $battle->winner(); } $player = new player('James',100); $opp = new player('John',100); $winner = fight($player,$opp); echo '<br />'.$winner.' is the Winner!'; ?>
(sinan, Mauritius)
Related Topics ... (or search in 1.720.883 topics !)
the simple code game. (4) game code copyright (4) game charictar recognize code (1) whats wrong with code game (7) c++ console game need help wit code (1) some one up for a game of code hockey tennis? (1) video game code database (1) 64bit game code business model (4) your favorite cheat code/mod on any game? (30)
copyright © 2007-2031 Pfodere.COM ( 7 Pfoyihuee Online )
|