Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. "so let me get this straight son....you pushed the boundaries of science, turning the laws of physics upside, reached beyond the grave and contacted me...to ask for $20 and the car keys???"
  2. OP asked why there was no response in thread, and I made an observation based on contents of this thread. "If your lack of effort here is any indication of what's in your other thread, I can see why it wasn't answered." After going to the thread in question, IMO I was right in that deduction. She dumped a couple of files on people and asked how to add a new feature. Didn't post relevant code (dumping all your files on us is not posting relevant code), nor did she make any mention of her own efforts to do what she wants done, or where she got stuck (we are here to help you past stumbling blocks of your own efforts, not do your work for you). I don't get paid to sugar coat things or tip-toe on glass or make with the warm and fuzzies or otherwise jerk people off. Oh, right...I don't get paid at all to do stuff around here. So I will apologize for my failure to solve a problem, but not for my lack of tact. Especially when someone is clearly dumping stuff on us instead of asking for help. And IMO I was not even being "brash" about it...if this is considered brash.. one wonders what many of my other responses would be considered as...
  3. You made this thread asking why nobody would respond to your question thread. You didn't post a link to your question thread. So in order to know what thread you are talking about, instead of clicking on a link to it, I now have to go search for it (which I'm not going to do). My observation was that you aren't making it very easy to respond to this thread, so chances are, you probably didn't make it very easy to respond to your question thread, either.
  4. IMO, if it were me doing the interview, it would have earned the OP brownie points (and more time) if he had gone back with a list of questions to clarify details (and perhaps also point out flaws in the "game mechanics" itself, depending on the employer...the warriors are pretty unbalanced...).
  5. This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://www.phpfreaks.com/forums/index.php?topic=336853.0
  6. If this thread is any indication of how you posted your question...I can easily see why nobody responded. For one thing, you didn't even bother to post a link to your question in this thread. But anyways...did you *bump* your thread? You are allowed to do that (but not too much, maybe once a day or so). But more importantly, lack of response usually means you didn't explain your question clear enough or provide enough details or relevant code. Perhaps you should go back and look at your post and pretend you are the one reading and trying to answer it and ask yourself if you've provided enough info, etc... Also, this site is a free resource, and nobody is obligated to help you, even if you asked the question in a most excellent manner. If you expect an answer, I suggest hiring someone to help you.
  7. I interpreted that as: every time a ninja attacks there's a 5% chance that it does twice as much damage as it would normally do, not that the attack stat of the ninja doubles permanently. edit: Looking over the code it seems that Daniel and ignace interpreted it that way (the way I did) as well. I interpret that as for each round, 5% chance that the $attack stat doubles. This doesn't necessarily double the actual damage done, because damage done is $attack - $defense. So IOW I interpret it as ($attack * 2) - $defense not ($attack - $defense) * 2 I guess that interpretation is a matter of opinion though... but I too interpret that it is something to do each round, and shouldn't be a permanent stat increase. So my code in principle basically goes like this:
  8. Yes, you're supposed to let whoever has more speed (failing that, less defense...failing that...unspecified (I just flip a coin at that point)) attack first. And technically it doesn't say "check speed before every round," and technically there are no speed-altering abilities in the spec. So it's within one's rights to write it exactly like that: check stats initially, do all 30 rounds based on initial stat check (..except for defense...see Dan's point, which does apply) HOWEVER... there are specs for abilities that cause stats to change, which does affect each round of the battle. Ninja: "With each attack there is a 5% chance of doubling the attack strength." This very explicitly states that an altered stat should affect each fighting round. Samurai: "When a samurai evades an attack there is a 10% chance of regaining 10 health" What would be the point in increasing health if it's not supposed to be applied to subsequent rounds of the fight? Brawler: "When a brawler’s health falls to less than 20% their defence increases by 10" What would be the point in increasing defense if that increased defense is not going to be used in subsequent rounds? The specs state to alter specific stats for specific warriors, to be applied to each (subsequent) round of a fight. If you stuck to the exact current specs, it does not say to do anything with speed, so it is "safe" to check speed before the rounds begin, and then never check it again. But if you look at the specs in a broader term of "script should be able to alter stats for warriors and be applied to subsequent rounds," then you are fucking yourself on the speed stat. If tomorrow you are tasked with the following: Ninja: "Each attack there is a 10% chance of increasing speed by 20%." Since the current spec is check speed to determine who hits first, this new ability would give ninjas an increased chance to hit first on each round. But since you don't do a speed check every round, you're going to have to recode what you did, to accommodate this new ability. Isn't that the whole point of Object Oriented Programming? To write code in more abstract terms so that there is less work involved in adding new stuff later on? The brawler gets a defence boost when on low health. Defence was the secondary stat to check when determining who goes first. Yeah you're right...forgot about that (I did it in my code..just forgot about it when posting that... but that just further proves my point in this post.
  9. The spec defines how to determine who goes first initially. The way it is worded...yes, technically doing it before the battle loops will work, and be within spec. But then each warrior has a stat-changing ability that is triggered based on the battle. Technically there are currently no speed-changing abilities defined in this spec, so technically you are within spec. But the point of OOP is to be able to think ahead and expand. It makes more sense to code the abilities in a way that any stat can be changed for whatever reason. For instance, say I want to give ninjas a 10% chance of a speed boost, that would affect whether or not they go first. But that stat change won't work if you are determining who will go first only once, before the first battle. So I don't think it was "misinterpreted" per se..just that IMO it is better to code with the mentality of "xyz is in the spec...I could technically do it one way, but if I do it this other way, it will make it easier for me to add more things later". I've never really sat down and formerly learned OOP but I think that's what's called keeping your coupling loose or something.
  10. yay, one year closer to death. Not much longer now!
  11. aaah you're right...forgot to assign it.
  12. Ah okay you're right, deadline has past...okay, here is my take, how far I got. <?php $num_warriors = 2; $types = array('ninja','samurai','brawler'); if (!$_POST) { echo "<p>Choose your Warriors</p>\n"; echo "<form action='' method='post'>\n"; for ($f = 1; $f <= $num_warriors; $f++) { echo "Name <input type='text' name='warriors[{$f}][name]' value='Warrior {$f}'>\n"; echo "Type \n"; echo "<select name='warriors[{$f}][type]'>\n"; foreach ($types as $k => $type) { $selected = ($k>0) ? "" : "selected='selected'"; echo "<option value='{$type}' {$selected}/>{$type}</option>\n"; } echo "</select>\n"; echo "<br/>\n"; } echo "<input type='submit' value='fight!' name='submit' />\n"; echo "</form>\n"; // posted info, lets fight! } else { foreach($_POST['warriors'] as $k => $warrior) { if (in_array($warrior['type'],$types)) { $name = preg_replace('~[^-_0-9a-z ]~i','',$warrior['name']); $warriors[] = new $warrior['type']($name); } } // end for each warrior $rounds = 30; $winner = false; // display initial stats display_stats($warriors); // fight to the death! for ($f = 0; $f < $rounds; $f++) { engage_fight_process($warriors); foreach ($warriors as $warrior) { if ($warrior->get_stat('health','current') <= 0) { echo "<br/>\n" . $warrior->name . " lost the fight!<br>\n"; $winner = true; break(2); } } } // end for each round if (!$winner) echo "The fight was a draw :/<br>\n"; echo "<br>\n"; echo "<a href=''>Fight Again!</a>\n"; } // end if posted stuff function display_stats(&$warriors) { // display current stats of warriors echo "<table border='1'>\n"; echo "<tr>\n"; echo "<th>Type</th>\n"; echo "<th>Name</th>\n"; echo "<th>Health</th>\n"; echo "<th>Attack</th>\n"; echo "<th>Defence</th>\n"; echo "<th>Speed</th>\n"; echo "<th>Evade</th>\n"; echo "</tr>\n"; foreach ($warriors as $warrior) { echo "<tr>\n"; echo "<td>".$warrior->type."</td>\n"; echo "<td>".$warrior->name."</td>\n"; echo "<td>".$warrior->get_stat('health','current')."</td>\n"; echo "<td>".$warrior->get_stat('attack','current')."</td>\n"; echo "<td>".$warrior->get_stat('defence','current')."</td>\n"; echo "<td>".$warrior->get_stat('speed','current')."</td>\n"; echo "<td>".$warrior->get_stat('evade','current')."</td>\n"; echo "</tr>\n"; } echo "</table>\n"; } // end display_stats function display_results($results) { // display fight results foreach($results as $result) { if ($result['evaded']) { echo $result['target'] . " evaded " . $result['attacker'] . "'s attack!<br>\n"; } else { echo $result['attacker'] . " hit " . $result['target'] . " for " . $result['damage'] . " damage (+".$result['attack_bonus']." bonus)!<br>\n"; } } // end display fight results } // end display_results function engage_fight_process(&$warriors) { // fight! $fight_results = fight($warriors); // display results display_results($fight_results); // display current stats display_stats($warriors); } // end fight_to_death function fight (&$warriors) { // figure out who goes first $w1s = $warriors[0]->get_stat('speed','current'); $w2s = $warriors[1]->get_stat('speed','current'); // check speed switch (true) { case ($w1s>$w2s) : break; case ($w1s<$w2s) : $warriors = array_reverse($warriors); break; // check defence default: $w1d = $warriors[0]->get_stat('defence','current'); $w2d = $warriors[1]->get_stat('defence','current'); switch(true) { case ($w1d<$w2d) : break; case ($w1d>$w2d) : $warriors = array_reverse($warriors); break; default : shuffle($warriors); } // end check defence } // end check speed $details[] = $warriors[0]->attack($warriors[1]); if ($warriors[1]->get_stat('health','current')>0) $details[] = $warriors[1]->attack($warriors[0]); return $details; } // end fight abstract class warrior { var $name = ''; var $type = ''; var $stats = array( 'health' => array('min'=>0,'max'=>0,'initial'=>0,'current'=>0,'ability'=>0), 'attack' => array('min'=>0,'max'=>0,'initial'=>0,'current'=>0,'ability'=>0), 'defence' => array('min'=>0,'max'=>0,'initial'=>0,'current'=>0,'ability'=>0), 'speed' => array('min'=>0,'max'=>0,'initial'=>0,'current'=>0,'ability'=>0), 'evade' => array('min'=>0,'max'=>0,'initial'=>0,'current'=>0,'ability'=>0), ); var $statuses = array( 'attacker' => true, 'evade' => false, ); abstract function pre_set_stats(); abstract function post_set_stats(); function __construct($config) { $this->init_stats($config['stats']); } // end construct function init_stats($stats) { foreach ($stats as $k => $v) { if (isset($this->stats[$k])) { $this->stats[$k]['min'] = $v['min']; $this->stats[$k]['max'] = $v['max']; $this->stats[$k]['initial'] = $this->stats[$k]['current'] = rand((int)$v['min'],(int)$v['max']); } // end if stats item } // end foreach stats item } // end init_stats function set_stat ($stat, $state, $value) { $value = ($value < 0) ? 0 : $value; $this->stats[$stat][$state] = $value; } // end set_stats function get_stat ($stat,$state) { return $this->stats[$stat][$state]; } // end get_stats function set_status ($status, $value) { $this->statuses[$status] = $value; } // end set_status function get_status ($status) { return $this->statuses[$status]; } // end set_status function reset_statuses() { foreach ($this->statuses as $status => $value) { $this->set_status($status,false); } } // end reset_statuses function reset_abilities() { foreach ($this->stats as $stat => $value) { $this->set_stat($stat, 'ability', 0); } } // end reset_statuses function is_attack_evaded() { $d = rand(1,100); $pEvade = $this->get_stat('evade','current'); if ($pEvade >= $d) $this->set_status('evade',true); return $this->get_status('evade'); } // end is_attack_evaded function attack(&$target) { $this->set_status('attacker',true); $this->pre_set_stats(); $target->pre_set_stats(); $details = array( 'attacker' => $this->name, 'target' => $target->name, 'evaded' => true, 'attack' => 0, 'attack_bonus' => 0, 'attack_total' => 0, 'defence' => 0, 'damage' => 0, 'health' => 0, 'new_health' => $target->get_stat('health','current'), ); if ( !$target->is_attack_evaded() ) { $details['evaded'] = false; $details['attack'] = $this->get_stat('attack','current'); $details['attack_bonus'] = $this->get_stat('attack','ability'); $details['attack_total'] = $details['attack'] + $details['attack_bonus']; $details['defence'] = $target->get_stat('defence','current') + $target->get_stat('defence','ability'); $details['damage'] = $details['attack_total'] - $details['defence']; if ($details['damage']<0) $details['damage'] = 0; $details['health'] = $target->get_stat('health','current'); $details['new_health'] = $details['health'] - $details['damage']; $target->set_stat('health','current',$details['new_health']); } $this->post_set_stats(); $target->post_set_stats(); $this->reset_statuses(); $target->reset_statuses(); $this->reset_abilities(); $target->reset_abilities(); return $details; } // end attack } // end warrior class class ninja extends warrior { function __construct($name) { $this->name = $name; $this->type = 'ninja'; $config['stats'] = array( 'health' => array('min'=>40,'max'=>60), 'attack' => array('min'=>60,'max'=>70), 'defence' => array('min'=>20,'max'=>30), 'speed' => array('min'=>90,'max'=>100), 'evade' => array('min'=>30,'max'=>50), ); parent::__construct($config); } // end __construct function pre_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // With each attack there is a 5% chance of doubling the attack strength. if(rand(1,100)>95) { $attack = $this->get_stat('attack','current'); $this->set_stat('attack','ability', $attack); } break; // if warrior is defender case false : // no abilities break; } // end if attacker } // end pre_set_stats function post_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // no abilities break; // if warrior is defender case false : // no abilities break; } // end if attacker // no global abilities } // end post_set_stats } // end class ninja class samurai extends warrior { function __construct($name) { $this->name = $name; $this->type = 'samurai'; $config['stats'] = array( 'health' => array('min'=>60,'max'=>100), 'attack' => array('min'=>75,'max'=>80), 'defence' => array('min'=>35,'max'=>40), 'speed' => array('min'=>60,'max'=>80), 'evade' => array('min'=>30,'max'=>40), ); parent::__construct($config); } // end __construct function pre_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // no abilities break; // if warrior is defender case false : // no abilities break; } // end if attacker // no global abilities } // end pre_set_stats function post_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // no abilities break; // if warrior is defender case false : // When a samurai evades an attack there is a 10% chance of regaining 10 health. if ($this->get_status('evade')&&(rand(1,100)>90)) { $health = $this->get_stat('health','current')+10; $this->set_stat('health','current',$health); } break; } // end if attacker // no global abilities } // end post_set_stats } // end class samurai class brawler extends warrior { function __construct($name) { $this->name = $name; $this->type = 'brawler'; $config['stats'] = array( 'health' => array('min'=>90,'max'=>100), 'attack' => array('min'=>65,'max'=>75), 'defence' => array('min'=>40,'max'=>50), 'speed' => array('min'=>40,'max'=>65), 'evade' => array('min'=>30,'max'=>35), ); parent::__construct($config); } // end __construct function pre_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // no abilities break; // if warrior is defender case false : // no abilities break; } // end if attacker // no global abilities } // end pre_set_stats function post_set_stats() { switch ($this->get_status('attacker')) { // if warrior is attacker case true : // no abilities break; // if warrior is defender case false : // When a brawler’s health falls to less than 20% their defence increases by 10. $percent_health_left = round(($this->get_stat('health','current') / $this->get_stat('health','initial')) * 100); if ($percent_health_left < 20) { $new_defence = $this->get_stat('defence','current')+10; $this->set_stat('defence','current',$new_defence); } break; } // end if attacker // no global abilities } // end post_set_stats } // end class brawler ?>
  13. my avatar is supposed to be randomly generated. It used to randomly generate but at some point in time one of the forum upgrades cached the avatar image so it's basically stuck on the last one before the cache :/ You can go here and refresh to see it. Also here is a much bigger version that I based my random avatar off of
  14. There is a "Profile" link at the top in the menu links that gives you a dropdown. Click on Profile > Forum Profile The top section of that page is "Personalized Picture" where you can change your avatar.
  15. Basically, yes. It is a blueprint to ensure that classes that extend other classes will contain necessary stuff. Another way to put it is if you have a method1 in a class that depends on another method2 in a class, but method2 is defined by the child class, it is to make the child class implement method2, so that method1 will not break. In other OOP languages, you are expected to do extra things like declare a return type, etc... to further make sure that methods like method2 will not be broken. Building off of thorpe's example: <?php abstract class Animal { public abstract function makeNoise($noise); public function goToSleep() { $this->makeNoise("zzz"); // will fail for object of Cat! } } class Cat extends Animal { /* public function makeNoise($noise) { echo $noise; } */ } class Dog extends Animal { public function makeNoise($noise) { echo $noise; } } $dog = new Dog; $cat = new Cat; echo " A dog makes noise "; $dog->makeNoise('woof!'); echo " and now sleeps "; $dog->goToSleep() . " <br/>"; echo "<br>"; echo " A cat makes noise "; $cat->makeNoise('meow!'); // doesn't exist! echo " and now sleeps "; $cat->goToSleep() . " <br/>"; ?> The $cat stuff will not work. The goToSleep() method expects makeNoise() to exist (and Ideally have certain arguments and return a certain type). You expect it because you expect a $cat to be able to make a noise, because it is an Animal. So by making makeNoise an abstract method in the Animal class, you are forcing the child object to implement that method. If you don't, it throws an error.
  16. So I got off work and was bored so I decided to make this game. I gave myself a 2 hour limit and here is the result: struggling graduate test game I estimate that it took about an hour and a half or so to throw it together in the worst manner possible (what I like to call the "just make it work" method), and then QA for soundness, near as I can tell, it does what it's supposed to, though to be fair, I took a few liberties as far as filling in some blanks and also whoever designed this test sucks ass at game mechanics/design, but I guess that's probably not the point of this exercise. I spent the last 30m trying to make it OOP style but didn't get very far (I did it procedural style first, just throwing shit together to complete it in time. OOP style is a more significant initial time investment, because it requires more forethought for the future and expandability). So the code itself isn't all that great, but the point is that it can be done fairly quickly, even if he gave you much less time to do it than he apparently gave you. Also note, that my intentions are not to rub this in your face or nothin'...I was mostly just bored and it seemed like a fun thing to do and maybe if you see it in action it will help you understand. No I won't show you the code, that would be cheating
  17. Daniel I don't disagree with you but I got the impression he took vocational type classes. Thing is, pretty much any "web development" classes out there today are not really about teaching programming theory. I certainly agree that taking classes that teach you the theories and principles in a more general sense will help and is useful.
  18. Code and standards evolve so rapidly that it's practically useless and pointless to try and find a school that offers you a relevant, up-to-date, thorough curriculum. Most places don't even bother to make the effort because by the time they get the material and curriculum ready and passed through hoops to be approved for teaching etc.. it's already outdated. But they will continue to happily offer classes about it knowing full well it's not going to be a damn bit helpful in the real world because at the end of the day, they are there to make money, and they know people will throw money at it. I'm not by any means calling you stupid...but if you spent 4 years at college and can't do something like that...then yes, you have for the most part wasted your time and money. The good news is that like the schools, a lot of companies also still try to treat the web dev industry like a traditional job, and do like seeing a piece of paper from some college attached to resumes, so it will certainly help you in getting your foot in the door. But that's about it. That test is kinda easy, with or without OOP (though I do agree, OOP would be the better approach, to make it easier to expand the game...). Even a Jr. Developer should be able to whip something like that up in an hour or two..and most of that time would probably be spent on making it cooler. Hell, that's the sort of thing most 13 year old script kiddies start on when learning web development. I have seen countless posts around here that basically say "So I've been playing KoC or DT or <insert some online text game here> for some time now and I think I can do better..." There is nothing in that test that you shouldn't have been able to pick up from a couple of newbie tuts floating around on the web. Until the schools and other institutions realize that their traditional "teaching" formulas and approaches will not work for something like web development - until they realize they need to treat the classroom more like a business, taking on real world clients and projects - you are far better off learning by experience with your own projects and picking up small freelance jobs and building up a portfolio and going from there.
  19. But... You just did that even right now, with this: Yeah. No need to repeat something that's already been said. OP, if you need further assistance with this let us know and we will be glad to help You just repeated someone else alluding to not repeating things...
  20. Well there's a good chance I woulda ended up on phpfreaks regardless.... I've been pretending to program since i was about 5. That is my only tattoo. I've done a couple designs over the years but I don't really go out of my way to do it or anything. Though I still fairly regularly keep in touch with my artistic side; mostly random sketches or painting once a month or so.
  21. .josh

    Fathers day

    it's the one day I can tell the wife to make me a sammich and she actually will!
  22. Oh as far as info... I got it about 16 years ago (outer, lower right leg). I was sober (I think...I'm about 95% sure...) I guess it did kinda hurt but in a good way...I was kinda into the pain thing back then; if I remember correctly, it felt somewhat euphoric. I hear that's actually not all that uncommon. It was at a local shop in San Antonio. I designed it (was supposed to be my inner child but...meh, I was young ) and paid the guy $50 and promised him hookups on pizza (was the manager of a domino's pizza down the street). IDK if he was famous or anything but I thought he did a decent job. He actually liked my design and some other designs I did (I did a couple other tattoo designs for a few friends) enough that he offered me an apprenticeship. I kinda wanted to, but he was fixin' to move his shop to Philly so I had to kinda go with him. For a while I kinda regretted not taking him up on his offer because it turned out I ended up randomly hopping around the country with random friends anyways, not too long after. Who knows where CV's life would be if he had taken that fork in the road
  23. error is pretty straight forward... you have your registrationKey column set to only allow unique values (no two rows can have the same value). And there is another row with '' as the value
  24. And altering a hidden input field is even easier to spoof than HTTP_REFERER. And also, if you go the hidden field route, you wouldn't be popping it with HTTP_REFERER, but of the current page url. But anyways, we're talking about redirecting user to the page they were trying to get to when logging in, low probability someone would actually try to spoof something like that.
×
×
  • 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.