Jump to content

Kryllster

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by Kryllster

  1. I believe it would be the PAGE_DIR which as it is only allows for 1 set directory I Have several of these as controllers in this project but I want to use just 1 controller instead of several. Does that help??
  2. I have this script as my index.php <?php include_once "templates/header.php"; include_once "templates/website/navi1.php"; define("PAGE_DIR", dirname(__FILE__) . "/templates/website"); require_once "templates/FrontController.php"; FrontController::createInstance()->dispatch(); include_once "templates/footer.php"; ?> And I have this as my frontcontroller: <?php class FrontController { public static function createInstance() { if (!defined("PAGE_DIR")) { exit("Critical error: Cannot proceed without PAGE_DIR."); } $instance = new self(); return $instance; } public function dispatch() { $page = !empty($_GET["page"]) ? $_GET["page"] : "main"; $class = ucfirst($page) . "page"; //e.g. pages/home/HomeActions.php $file = PAGE_DIR . "/" . $page . ".php"; if (!is_file($file)) { exit("Page not found"); } require_once $file; } } ?> Both of these I had gotten off the internet and it does work however its pretty limited I need to go into sub folders and such but I'm stuck as how to go about this a link or tutorial would be nice or just some pointers. Thanks,
  3. I am in need of some articles and examples of a FrontController that will handle multiple directories.Coul someone point me in the right direction? Thanks,
  4. Thanks for pointing that out I fixed it and also fixed the problem with phpmyadmin. There was some sort of glitch or something I have it back now I have no idea really what it was. Thanks again.
  5. I just tried to upload this sql file to my phpadmin and now I cant get back in phpmyadmin and it says to check my error logs and there is nothing to do with phpadmin in any of my error logs. I did have a problem where php didnt have an error log and asked me if I wanted to create one so I did or thought I did. and way is there something wrong with my sql that would break it? CREATE TABLE'ferentus_text`( `player_id` INTEGER NOT NULL AUTO_INCREMENT , `username` TEXT NOT NULL , `password` TEXT NOT NULL , `email` TEXT NOT NULL , `sex` TEXT NOT NULL , `race` TEXT NOT NULL , `class` TEXT NOT NULL , `strength` INTEGER NOT NULL , `dexterity` INTEGER NOT NULL, `intelligence` INTEGER NOT NULL , `vitality` INTEGER NOT NULL , `level` INTEGER NOT NULL , `advance` INTEGER NOT NULL , `hitpoints` INTEGER NOT NULL , `mana` INTEGER NOT NULL , `spirit` INTEGER NOT NULL , `copper` INTEGER NOT NULL , `silver` INTEGER NOT NULL , `gold` INTEGER NOT NULL , `platinum` INTEGER NOT NULL , `main_hand` TEXT NOT NULL , `main_power` INTEGER NOT NULL , `off_hand` TEXT NOT NULL , `off_power` TEXT NOT NULL , `off_defence` INTEGER NOT NULL , `twohand` TEXT NOT NULL , `twohand_power` INTEGER NOT NULL , `torso` TEXT NOT NULL , `torso_power` INTEGER NOT NULL , `pants` TEXT NOT NULL, `pants_power` INTEGER NOT NULL , `gloves` TEXT NOT NULL, `glove_power` INTEGER NOT NULL, `boots` TEXT NOT NULL , `boot_power` INTEGER NOT NULL, `necklace` TEXT NOT NULL , `necklace_bonus` INTEGER NOT NULL , `ring1` TEXT NOT NULL , `ring1_bonus` INTEGER NOT NULL , `ring2` TEXT NOT NULL , `ring2_bonus` INTEGER NOT NULL , `skill1` TEXT NOT NULL , `skill1_power` INTEGER NOT NULL , `skill2` TEXT NOT NULL , `skill2_power` INTEGER NOT NULL , `skill3` TEXT NOT NULL , `skill3_power` INTEGER NOT NULL , `skill4` TEXT NOT NULL , `skill4_power` INTEGER NOT NULL , `skill5` TEXT NOT NULL , `skill5_power` INTEGER NOT NULL , `skill6` TEXT NOT NULL , `skill6_power` INTEGER NOT NULL , `skill7` TEXT NOT NULL , `skill7_power` INTEGER NOT NULL , `skill8` TEXT NOT NULL , `skill8_power` INTEGER NOT NULL , `avatar` TEXT NOT NULL , `guild` TEXT NOT NULL , `offence` INTEGER NOT NULL , `defence` INTEGER NOT NULL , `bind_spot` TEXT NOT NULL ) Thanks for any help on this,
  6. To continue on with this I have some code that works to a degree. I can get the right information from a database and display it correctly but the subtraction from the $mob_hp doesnt reflect the damage it just sits there with the correct value. <?php session_start(); // include object code include('objects/mob_lib.php'); // get db info from url $stat = $_GET['p']; // include the database code include('scripts/mobdbconnect.php'); //get the hp, if it exists if (!isset($_SESSION['player_hp'])) { $player_hp = 30; } else { $player_hp = $_SESSION['player_hp']; } // set monster hitpoints if (!isset($_SESSION['mob_hp'])) { $mob_hp = $mob->mob_hp; } else { $mob_hp = $_SESSION['mob_hp']; } // start the fight $first = mt_rand(1,100); //find out who goes first if ($first < 65) { $player_damage = 5; $mob_hp -= $player_damage; } else { $mob_attack = $mob->attack; $player_hp -= $mob_attack; } if ($player_hp <= 0) { header("Location:south.php?p=defeat"); exit(); } if($mob_hp <= 0) { header("Location:south.php?p=victory"); exit(); } //Gotta store them back in sessions $_SESSION['player_hp'] = $player_hp; $_SESSION['mob_hp'] = $mob_hp; include('scripts/interface.php'); ?> If you need more code let me know. I did try the other code but kept getting error about using $this in object form. Thanks,
  7. How are you using that object? Is it in conjunction with a database or an array? I have the code I have but cant seem to get it to work actually all my coding at this point is in a nightmare state lol I guess I need to start all over and do some more planning.
  8. You can print_r objects. I am making a similar game and using a similar method to that which you've demonstrated. You have a lot of unnecessary functions. Have two functions as follows, using parameters: <?php public get_stat($stat) { if(isset($this->$stat) { return $this->$stat; } } public set_stat($stat, $value) { if(isset($this->$stat) { $this->$stat = $value; } } ?> I don't understand what your trying to do with that code. I tried mine with a database but all I got was errors. Just trying to learn and understand. Thanks for all your help guys.
  9. Funny you should mention that because I have some code that I am learning about objects. <?php class mob { // Monstors public $mob_name; public $attack; public $mob_hp; public $mob_level; // construct provided by phpfreaks forum function __construct(array $items) { foreach($items as $k => $v) { $this->{$k} = $v; } } function set_mob_name($mob_name) { $this->mob_name = $mob_name; } function get_mob_name() { return $this->mob_name; } function set_attack($attack) { $this->attack = $attack; } function get_attack() { return $this->attack; } function set_mob_hp($mob_hp) { $this->mob_hp = $mob_hp; } function get_mob_hp() { return $this->mob_hp; } function set_mob_level($mob_level) { $this->mob_level = $mob_level; } function get_mob_level() { return $this->mob_level; } } ?> The problem is I have no Idea how to implement it it works with an array if I print it out but I wanted something for a fighting script for a game I'm making. I wanted to have a 1 fight script fits all type of thing. I have a database but don't know how to use it with the piece of code I posted.
  10. Ok I'll try to explain what I'm trying to do if I can. Say I have a link in a web page: http://index.php?p=skeleton Can I compare the variable of skeleton with the entry in the array and pull all the info from it to use in a page I am creating. I hope that helps I am working on it myself but haven't found the solution yet even if there is one.
  11. Can I compare an item in an array with a $_GET[''] variable and then use that item from the array in my page?
  12. Ok I have a multidimensional array and what I want to know is how to use it. I need to pick the items from the array but only the items specified or individual keys in the array how would I go about doing that. Here is the array: <?php $monstors = array ( "Skeleton"=>array ( "mob_name"=>"Skeleton", "mob_attack"=>"5", "mob_hp"=>"30", "mob_level"=>"1" ), "Skeleton Fighter"=>array ( "mob_name"=>"Skeleton Fighter", "mob_attack"=>"10", "mob_hp"=>"35", "mob_level"=>"2" ), "Skeleton Warrior"=>array ( "mob_name"=>"Skeleton Warrior", "mob_attack"=>"15", "mob_hp"=>"40", "mob_level"=>"3" ) ); ?> How would I like print_r the element in the array called Skeleton Warrior?
  13. The technical answer is I don't know how I can learn what I need to know and I'm not sure if I'm smart enough to understand what I need to know. I know a lot of things today are OOP and I'm having a hard time understanding how to use it I know some basics but that's it and that's from what I learned on this forum. Hope that answers your question. Thanks guys for the reply's.
  14. Well the need comes from all the work Id have to put in the game if I used mysql or the like. I have already created a text based game before and it was a lot of work and the end result wasn't what I expected. I was hoping with this new game to do the things I didn't do in the last one but I have so much to learn and I am already so far behind in what I see other games doing nowadays it makes me want to give up learning php but I want to learn as much as I can to do this in a short time to. I also thought it would be unique.
  15. Before I even try I would like to know if its possible to make a small game based on sessions? The idea is to create a character then put starting data into a session that is maintained till the browser is closed or they log off the game and the session destroyed. It sounds like it would work but I don't want to put in the effort unless its possible to do something like this.
  16. Have you tried header("Location:page_to_goto.php");
  17. Is it possible to set a certain session to time out after say 2 minutes. I want to lock a person from seeing a page for 2 minutes then destroy the session yet keep the primary session and still keep dpoing what they were doing? Just curious. Thanks,
  18. Thanks for the reply! How do I set my session variable before I redirect I think thats the problem I have been running into.
  19. I am having problems with this code sometimes it works other times it doesnt I cant figure out why. <?php session_start(); $xml = simplexml_load_file("xmlmonstor/skeleton.xml"); //get the hp, if it exists if (!isset($_SESSION['player_hp'])) { $player_hp = 30; } else { $player_hp = $_SESSION['player_hp']; } if (!isset($_SESSION['mob_hp'])) { $mob_hp = $xml->mob_hp; } else { $mob_hp = $_SESSION['mob_hp']; } // Set amount of starting turns if (!isset($_SESSION['turns'])) { $turns = 500; } else { $turns = $_SESSION['turns']; } $first = mt_rand(1,100); //find out who goes first if ($first < 60) { $player_damage = 5; $mob_hp -= $player_damage; } else { $mob_attack = $xml->attack; $player_hp -= $mob_attack; } if ($player_hp <= 0) { header("Location:south.php?p=defeat"); $turns = $turns - 1; $_SESSION['turns'] = $turns; exit(); } if($mob_hp <= 0) { header("Location:south.php?p=victory"); $turns = $turns - 1; $_SESSION['turns'] = $turns; exit(); } //Gotta store them back in sessions $_SESSION['player_hp'] = $player_hp; $_SESSION['mob_hp'] = $mob_hp; $_SESSION['turns'] = $turns; ?> Am I setting the sessions right or is there a better way to do it? Thanks
  20. I tried that but I had to make a new script it worked on the first one but the second one didn't work. I am trying to make a dynamic fighting script that will handle all fights in a game I am working on. Any other advice I am also using an oop library I made just to try it out but it looks like im gonna have to do this procedurally some anyway. just some more code to throw in there for any comments. <?php class mob { // Monstors public $mob_name; public $attack; public $mob_hp; public $mob_level; // construct provided by phpfreaks forum function __construct(array $items) { foreach($items as $k => $v) { $this->{$k} = $v; } } function set_mob_name($mob_name) { $this->mob_name = $mob_name; } function get_mob_name() { return $this->mob_name; } function set_attack($attack) { $this->attack = $attack; } function get_attack() { return $this->attack; } function set_mob_hp($mob_hp) { $this->mob_hp = $mob_hp; } function get_mob_hp() { return $this->mob_hp; } function set_mob_level($mob_level) { $this->mob_level = $mob_level; } function get_mob_level() { return $this->mob_level; } } ?> This works when I make an array and put the values in and such. Any ideas? Could an xml form handle this? Im stumped.
  21. Ok I have links from different pictures and I am wanting to retrieve data from a database depending on the link clicked how would I go about doing this here is my database code. <?php // include database connection to mob database $host = "localhost"; // Host name $db_username = ""; // Mysql username $db_password = ""; // Mysql password $db_name = ""; // Database name // Connect to server and select databse. $sql = mysql_connect("$host", "$db_username", "$db_password"); // error message if (!$sql) { die('Could not connect: ' . mysql_error()); exit(); } // failure to select db else{ mysql_select_db("$db_name")or die("cannot select DB"); } // perform sql $sql = "select * from monstors where mob_name = '" . $_GET['name'] . "'"; $result = mysql_query($sql) or trigger_error($sql . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $mob = new mob($row); } ?> Thanks for any advice!
  22. Certainly gives me a lot more to think about thanks I will go ahead and mark this topic solved. I dont understand all you did there but at least I have something to go by. Thanks again.
  23. Here is some code that works but I need to know how I could use a database to get the armor values from it. <?php class armor { // Head public $head; public $torso; public $pants; public $gloves; public $boots; // new stuff here function set_head($head) { $this->head = $head; } function get_head() { return $this->head; } function set_torso($torso) { $this->torso = $torso; } function get_torso() { return $this->torso; } function set_pants($pants) { $this->pants = $pants; } function get_pants() { return $this->pants; } function set_gloves($gloves) { $this->gloves = $gloves; } function get_gloves() { return $this->gloves; } function set_boots($boots) { $this->boots = $boots; } function get_boots() { return $this->boots; } } ?> And this is in armor.php <?php $head = new armor(); $torso = new armor(); $pants = new armor(); $gloves = new armor(); $boots = new armor(); $head->set_head("Leather Helm"); $torso->set_torso("Leather Shirt"); $pants->set_pants("Leather Pants"); $gloves->set_gloves("Chainmail Gloves"); $boots->set_boots("Platemail Boots"); echo "You are wearing: " . $head->get_head(); echo "<br />"; echo "You are wearing: " . $torso->get_torso(); echo "<br />"; echo "You are wearing: " . $pants->get_pants(); echo "<br />"; echo "You are wearing: " . $gloves->get_gloves(); echo "<br />"; echo "You are wearing: " . $boots->get_boots(); ?> Like I said this works but I cant help but think there is a better way to do this with less code. Thanks for any advice.
  24. I am trying to understand PHP OOP and I have some code that is not working. here is the error code. Parse error: parse error, expecting `T_FUNCTION' in C:\wamp\www\testing\armor_lib.php on line 11 And here is the armor_lib.php file: <?php class armor { // Head public $head; public $torso; public $pants; public $gloves; public $boots; // new stuff here class head extends armor { function __construct($head){ $this->set_head($head); } } // Torso class torso extends armor { function __construct($torso){ $this->set_torso($torso); } } // Pants class pants extends armor { function __construct($pants){ $this->set_pants($pants); } } // Gloves class gloves extends armor { function __construct($gloves){ $this->set_gloves($gloves); } } // Boots class boots extends armor { function __construct($boots){ $this->set_boots($boots); } } } ?> And here is the php in the armor.php file I have: <?php $head = new armor("Leather Helm"); $torso = new armor("Leather Shirt"); $pants = new armor("Leather Pants"); $gloves = new armor("Chain Mail Gloves"); $boots = new armor("Leather Boots"); echo "You are wearing: " . $head->get_head() . "on your Head"; echo "<br />"; echo "You are wearing: " . $torso->get_torso() . "on your Torso"; echo "<br />"; echo "You are wearing: " . $pants->get_pants() . "on your Legs"; echo "<br />"; echo "You are wearing: " . $gloves->get_gloves() . "on your Hands"; echo "<br />"; echo "You are wearing: " . $boots->get_boots() . "on your Feet"; ?> Any Help in understanding this will be much appreciated. Thanks.
  25. Sorry posted in the wrong forums!! Please forgive the intrusion!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.