busby Posted June 20, 2011 Share Posted June 20, 2011 hey i finished university about 2 months ago after studying web development. im just waiting for graduation now and looking for full time work in web development. during the last 2 months ive had 2 jobs...one as an ASP.net developer and the other as a PHP developer...i lost both jobs within a matter of weeks because both said they needed someone more advanced as i was struggling to get work done quickly enough. ive continued to apply but more specifically for junior and graduate roles...this morning someone i sent my CV to got back to me and said they would like to send me a small test before they decide on an interview or not...this is for a junior web developer role...i recieved the test and have been trying to do it all day i just cant do it....its far too complicated for me and i dont even know where to begin...i only have untill tomorrow morning. this has got me thinking my time at uni has been a complete waste...perhaps i didnt learn as much as i needed to even though i managed to pass all my modules and create what i think is quite a good final project (using PHP) i cant seem to hold a job down...and am struggling with a junior roles test and its getting me down...can someone give me any advice? Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/ Share on other sites More sharing options...
KevinM1 Posted June 20, 2011 Share Posted June 20, 2011 What areas are you struggling with? What did your courses at school cover? Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232512 Share on other sites More sharing options...
busby Posted June 20, 2011 Author Share Posted June 20, 2011 What areas are you struggling with? What did your courses at school cover? you mean at university? they covered web database programming, PHP programming, asp programming, Flash and action script, javascript, XML SQL CSS HTML, graphics, few other things i appear to be struggling with everything given to me outside of university...if i get a job..the work is too hard and i get fired...ive just been given a test for a junior job role...but the test is too hard....its just so difficult but it wasnt this hard at university its startin to really bug me Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232514 Share on other sites More sharing options...
KevinM1 Posted June 20, 2011 Share Posted June 20, 2011 Sounds like your university took a "Survey of Web Development" approach to things, which is really pretty limiting. Professionals tend to start with one core non-HTML language, then branch out to others as their skills improve and they become better programmers in general. Look no further than the "How long have you been writing code for?" thread for proof of that. Did you go to school for four years, or two? Generally speaking, 'university' means four year bachelor's program, while 'college' means two year associate's program, although there are exceptions (Boston College, for one). In any event, there's no real way to get better than to roll up your sleeves and work on your deficiencies. I'm sure that's not the answer you want to hear, but that's the reality of the situation. To help you identify your weak areas, here's a general checklist I'd look for if I was hiring an intern/entry level coder (no particular order): 1. Form handling, including sticky forms, and input validation/escaping/general security 2. Array creation and manipulation 3. Basic database manipulation/CRUD 4. Comfort with logical structures - conditionals and loops 5. Decently written code (good variable names, good script structure, DRY, Separation of Concerns) 6. Comfort with creating custom functions. *Basic OOP skills (not mandatory, but a bonus) **You'd get fired immediately for using 'global' So, look at that basic list, see where you're weakest, and work to make it a strength. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232521 Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 Let's see the test questions, so we can evaluate its difficulty. Web development is difficult, and like any other type of programming, it takes time to become good at it. Junior people should be mentored by a sr. person. Often what companies mean when they hire a "jr person" is really: we don't want to pay for a sr. developer, so we'll call it a jr. position, but we'll expect the same results we would expect from a sr. person." If you didn't have a senior person working with you, reviewing your code, and providing answers to your questions, then those weren't entry level positions. Try not to become discouraged. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232523 Share on other sites More sharing options...
busby Posted June 20, 2011 Author Share Posted June 20, 2011 Sounds like your university took a "Survey of Web Development" approach to things, which is really pretty limiting. Professionals tend to start with one core non-HTML language, then branch out to others as their skills improve and they become better programmers in general. Look no further than the "How long have you been writing code for?" thread for proof of that. Did you go to school for four years, or two? Generally speaking, 'university' means four year bachelor's program, while 'college' means two year associate's program, although there are exceptions (Boston College, for one). In any event, there's no real way to get better than to roll up your sleeves and work on your deficiencies. I'm sure that's not the answer you want to hear, but that's the reality of the situation. To help you identify your weak areas, here's a general checklist I'd look for if I was hiring an intern/entry level coder (no particular order): 1. Form handling, including sticky forms, and input validation/escaping/general security 2. Array creation and manipulation 3. Basic database manipulation/CRUD 4. Comfort with logical structures - conditionals and loops 5. Decently written code (good variable names, good script structure, DRY, Separation of Concerns) 6. Comfort with creating custom functions. *Basic OOP skills (not mandatory, but a bonus) **You'd get fired immediately for using 'global' So, look at that basic list, see where you're weakest, and work to make it a strength. i went to university for 4 years bachelors degree i dont even know half the terminology that is thrown at me from employers or even some of the stuff in that list. Let's see the test questions, so we can evaluate its difficulty. Web development is difficult, and like any other type of programming, it takes time to become good at it. Junior people should be mentored by a sr. person. Often what companies mean when they hire a "jr person" is really: we don't want to pay for a sr. developer, so we'll call it a jr. position, but we'll expect the same results we would expect from a sr. person." If you didn't have a senior person working with you, reviewing your code, and providing answers to your questions, then those weren't entry level positions. Try not to become discouraged. thanks...a little uplifting but discouraged is pretty much how i feel...and a little like the university ripped me off...a problem im worried about is not being able to keep a job in development...losing grip on the industry as it advances and changes without me because the technologies change. and that without being able to keep a job ill never be good enough. edited to include the test ( imo its slightly vague...but i think they want it writen in PHP...not sure if it requires login scripts...i look at it and might as well be looking at a space shuttle engine Create the following game: You set of warriors, each warrior has the following data: ● Name ● Health ● Attack ● Defence ● Speed ● Evade Health, Attack, Defence and Speed are integer values between 0 and 100. Evade is a number between 0 and 1. There are currently 3 types of warrior: ● Ninja ○ Health (40-60) ○ Attack (60-70) ○ Defence (20-30) ○ Speed (90-100) ○ Evade (0.3-0.5) ● Samurai ○ Health (60-100) ○ Attack (75-80) ○ Defence (35-40) ○ Speed (60-80) ○ Evade (0.3-0.4) ● Brawler ○ Health (90-100) ○ Attack (65-75) ○ Defence (40-50) ○ Speed (40-65) ○ Evade (0.3-0.35) The values for each attribute are specified as a range, on creation each warrior will be assigned a random value within this range for the given attribute. Warriors can take part in a battle, a battle has only 2 combatants. Warriors take it in turn to attack each other. The warrior with the greatest speed takes the first attack (in the event of two with the same speed, player with the lower defence goes first). The damage dealt is (attack - oppositions defence) and is taken from the health. Damage may be avoided, the chance of avoiding an attack is specified by the evade attribute. The max amount of turns is 30 per player, if no player is defeated then the battle is a draw. As the battle progresses a text output should be shown. When a warrior gets to zero health the warrior is defeated. Special attributes of warriors: ● Ninja With each attack there is a 5% chance of doubling the attack strength. ● Samurai When a samurai evades an attack there is a 10% chance of regaining 10 health. ● +Brawler ○ When a brawler’s health falls to less than 20% their defence increases by 10. Allow a form to select player 1 and 2, and when submitted create a battle with the 2 players and output the result of the battle!! Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232524 Share on other sites More sharing options...
gizmola Posted June 20, 2011 Share Posted June 20, 2011 Yeah, I think you're letting this overwhelm you. What they probably are looking for is can you develop a few reasonable classes. The actual web aspect of this is really only one form.. no logins or anything like that. Do you have a good understanding of php5 oop, and oop concepts in general? That is what I'd be expecting from a task like this. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232533 Share on other sites More sharing options...
KevinM1 Posted June 20, 2011 Share Posted June 20, 2011 Do you know any OOP? This project is perfect for some basic OOP. It can still be done without it by using associative arrays. Here's how I'd approach the problem: 1. Your first page would be a simple form with two <select> elements and a submit button. The <select> options would be the kinds of warriors the player could pick - Ninja, Samurai, or Beserker. So, just to be absolutely clear, two drop down elements, each having the names of the kinds of warriors a player can choose. 2. That data would then be submitted to another page. This page would take the values of the drop downs and either create the appropriate objects (which is really the way to go) or associative arrays based on those values. 3. Once it's determined what kind of warriors to create, you need to go about filling their properties. For the random numbers in a range, you can use mt_rand like so: $ninja = array(); $ninja['health'] = mt_rand(40, 60); $ninja['attack'] = mt_rand(60, 70); // etc. For the evade property, you can fudge a decimal by dividing the result of the random number generator by 100: $ninja['evade'] = mt_rand(30, 50)/100; 4. From there, it's a matter of figuring out the game engine. a. Figure out which warrior goes first (you can get a 50/50 chance by using mt_rand and basic math). b. Have them attack each other for 30 turns (sounds like a loop...) c. Check if they meet the criteria for one of the special abilities/functions (if statements in the loop...) d. Echo the result of each turn to the screen You should be able to figure it out from here. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232534 Share on other sites More sharing options...
spiderwell Posted June 21, 2011 Share Posted June 21, 2011 maybe its me but that seems quite a test for a junior position. I was expecting something more like a form with validation or paging through a dataset. making a simple game I would say is more moderate level than junior. good luck though. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232773 Share on other sites More sharing options...
KevinM1 Posted June 21, 2011 Share Posted June 21, 2011 maybe its me but that seems quite a test for a junior position. I was expecting something more like a form with validation or paging through a dataset. making a simple game I would say is more moderate level than junior. good luck though. The test isn't difficult if you have a solid grasp of OOP fundamentals. Not syntax, but the real fundamentals. The test is asking a few things: 1. Does the person know how to use abstract classes? 2. Does the person know the Factory Method, perhaps the most common creational pattern in use? 3. Can the person use objects in a loop while testing for certain edge cases (the special abilities of each warrior)? OOP is the dominant programming paradigm. That's not a value statement, merely an observation. It's something new developers need to learn if they want to work for someone else. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232785 Share on other sites More sharing options...
xylex Posted June 21, 2011 Share Posted June 21, 2011 Busby- Looking at your post history, you haven't answered a single php question on the forum. Most of the questions people ask on here are ones that you commonly run into in the real world, and many companies expect you to be able to answer many of those off the top of your head, and for ones that you can't, to quickly find the answers to those problems. Hit the help forum, and learn to master figuring out the answer to those types of questions. This will give you the the basic skills of what employers expect at an entry level. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232809 Share on other sites More sharing options...
.josh Posted June 21, 2011 Share Posted June 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232827 Share on other sites More sharing options...
spiderwell Posted June 21, 2011 Share Posted June 21, 2011 maybe its me but that seems quite a test for a junior position. I was expecting something more like a form with validation or paging through a dataset. making a simple game I would say is more moderate level than junior. good luck though. The test isn't difficult if you have a solid grasp of OOP fundamentals. Not syntax, but the real fundamentals. The test is asking a few things: 1. Does the person know how to use abstract classes? 2. Does the person know the Factory Method, perhaps the most common creational pattern in use? 3. Can the person use objects in a loop while testing for certain edge cases (the special abilities of each warrior)? OOP is the dominant programming paradigm. That's not a value statement, merely an observation. It's something new developers need to learn if they want to work for someone else. Well I con't have OOP sussed yet, but I have held positions in companies which were definately above junior or entry level and they didn't require any OOP, mind you that said my new role does and i'm learning fast!!! Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232832 Share on other sites More sharing options...
Daniel0 Posted June 21, 2011 Share Posted June 21, 2011 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. Of course you can learn to program in a school. Imperative programming and functional programming is based on models of computations known as the Turing machine and the λ-calculus respectively, both "invented" in the 1930s. Object-oriented programming became more widespread with the emergence of Smalltalk in the 1970s, but the concept of objects started in academia over a decade earlier. Imperative programming works by manipulating the state of the computer until a particular set of variables/registers have the desired value. This hasn't changed at all. There hasn't really been much development from the von Neumann architecture, which is really the practical "implementation" of a Turing machine. If a school doesn't teach its students how to manipulate computers (not necessarily by introducing them to the aforementioned theory) by breaking problems down to things that can be handled by those models of computations, then it simply has a shitty curriculum. Sure, if a school only teaches trivia about a particular programming language's API then there is a problem, but the fundamental problem in this thread isn't that he is having trouble because of API changes during the course of his education, but that he hasn't learned to program, something which transcends the choice of programming language. If you've learned to program object-orientedly in Java, then you shouldn't have much trouble programming in another object-oriented programming language (e.g. C#). Sure, the syntax might be a bit different and you'll have to get used to the different API, but thsoe are things are encyclopeadic knowledge, things that can be looked up. You cannot look up "how to program". The only time you'll have real trouble is if you switch to a programming language in an unfamiliar paradigm. For programming, I would at any time recommend an theory based education instead of a vocational one, i.e. an education that teaches the "whys" instead of the "hows". If you understand the theory, then it's (fairly) easy applying that in many different scenarios (such as picking up a new object-oriented programming language when you already understand OOP). Note that I'm not advocating a strictly bottom-up approach though. I'm not saying that you should introduce people to things like Turing machines before you start teaching them programming, nor that they necessarily need to know what that is. However, they do need to understand what it essentially means to program. As for keeping up with particular technologies, that's the students own responsibility. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232866 Share on other sites More sharing options...
.josh Posted June 21, 2011 Share Posted June 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232869 Share on other sites More sharing options...
Daniel0 Posted June 21, 2011 Share Posted June 21, 2011 maybe its me but that seems quite a test for a junior position. I was expecting something more like a form with validation or paging through a dataset. making a simple game I would say is more moderate level than junior. I don't mean to sound condescending, but I was a teaching assistant on a first-year university level programming course (Object Oriented Programming and Design). The course load was 7.5 ECTS-credits. I would have expected my students to be able to solve that problem. Indeed the exam was creating a Tron-like game with a GUI and simple AI strategies for computer based players using Java. The only programming course prior to that one was Introduction to Programming, which used functional programming, so the for many students, it was the first time they had to program imperatively. Having these expectations of first-year students, I would certainly expect that anyone who has completed a four year degree that claims to teach programming would be able to solve this problem with no trouble at all. 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. That's the impression I got as well. I suppose this would mean OP's degree has what I called a "shitty curriculum". That's not his fault of course. You cannot really know what is essential to be taught in a particular field if you're not already experienced with that field. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232878 Share on other sites More sharing options...
KevinM1 Posted June 21, 2011 Share Posted June 21, 2011 To be honest, I'm not even sure if the OP has his degree in web development. It sounds like he took a course or two because someone said "Hey, web development is easy $$" and expects to hit the ground running from there. AFAIK, there aren't web development bachelors programs, at least, not in my area of the US. The best are two-year associate degrees from technical colleges. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232885 Share on other sites More sharing options...
Zane Posted June 21, 2011 Share Posted June 21, 2011 What was your major busby? If you majored in Computer Information Systems, then I can understand how you came out not knowing enough to catch a junior level position. From 2005 - 2010, I majored in both Computer Info Systems AND Web Technologies (a double degree). In that time, I learned nothing new that would help me in the long run. Sure, I got to play with ASP.NET, VB.NET, PowerBASIC (for those who have heard of that) and XML/XSLT, but the curricula in those classes never reached passed the beginner level. PowerBASIC was only taught to us by sponsorship from a local tax software business who used that language to write the software. There was only one class offered on this language in this school and I took it, but that wasn't enough for Tax Services place to offer me a job in programming, much less technical support. In 2004, I took a PHP class, while in a Computer Science major at a university, just to see if I would get an A. By the second week of that class, I ended up running around the class helping people fix parse errors and invalid query errors that the professor had not even planned time for. There were times when we spent the entire class trying to make it to the same point. Unfortunately, everyone couldn't help but to forget a semicolon here, or an end parenthesis there. I even had to help the professor set phpmyadmin up. Needless to say, that professor lost his job, for lack of a Master's degree, I made an A and the rest of the class was still dumbfounded on the purpose of PHP at all. We failed to finish any projects, other than connecting to phpmyadmin. The best education I ever received concerning programming, in all of 6 years, was my first year's schedule. CS130 taught me quite a bit of Javascript and CS150 taught me more or less, OOP through Java. Even in CS150, we had questions like the one you posted. My point and question in all this is "What was your major?" and perhaps you chose the wrong one. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232915 Share on other sites More sharing options...
spiderwell Posted June 21, 2011 Share Posted June 21, 2011 maybe its me but that seems quite a test for a junior position. I was expecting something more like a form with validation or paging through a dataset. making a simple game I would say is more moderate level than junior. I don't mean to sound condescending, but I was a teaching assistant on a first-year university level programming course (Object Oriented Programming and Design). The course load was 7.5 ECTS-credits. I would have expected my students to be able to solve that problem. Indeed the exam was creating a Tron-like game with a GUI and simple AI strategies for computer based players using Java. The only programming course prior to that one was Introduction to Programming, which used functional programming, so the for many students, it was the first time they had to program imperatively. I think perhaps I need to have some education, Ive been scripting for a long time, and can deal with most demands that small to medium datadriven websites would have. I only recently started to do OOP but I have only learnt from books and online resources and forums similar to this one. I would be amazed if I could get this test up and running in an hour or two. Maybe I ought to have a go just to see , also I am off to google factory method! lol I think my biggest downfall is I only really know what I have had to learn, so many things have slipped past me, particularily in theory of programming and structure of code etc. I never forget the day i discovered recursion by accident/necessity, and thought I had found something AMAZING, only for my mate to laugh at me, but way I see it, I can't be that dumb if I managed to create it in the first place without knowing it before!! Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1232935 Share on other sites More sharing options...
.josh Posted June 22, 2011 Share Posted June 22, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233107 Share on other sites More sharing options...
ebmigue Posted June 22, 2011 Share Posted June 22, 2011 I understand your predicament. Why not try things that are within your skill set first, then gradually build on that. For instance, find a friend/relative in need of a website. Create their website from scratch, say a database-driven website with an administration panel, login, etc, etc. Don't use pre-madewebsites and frameworks (e..g, joomla, wordpress, zend, etc.). They have the tendency to dull the mind and occupy you with their-software-specific issues, and not software-development-in-general issues. You'll be amazed at what you'll be learning within months. Just be patient, because skills and knowledge don't come overnight. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233113 Share on other sites More sharing options...
Alex Posted June 22, 2011 Share Posted June 22, 2011 Seemed like fun so I decided to give it a shot myself. Attempted an OOP approach. Took me just under an hour and a half. The output from mine could be formatted a lot nicer, I just got lazy on that aspect. There also isn't form validation and stuff like that, I just focused on the OOP design mostly. It was only an hour and a half so of course things could be nicer, but I don't think it's too bad. There could be bugs; I didn't really rigorously test it. Because the deadline for submitting this test to the potential employer has passed I don't see any harm in providing the code. If you want to attempt it on your own still, then just don't look <?php class Battle { private $_warrior1; private $_warrior2; public function __construct(Warrior $warrior1, Warrior $warrior2) { $this->_warrior1 = $warrior1; $this->_warrior2 = $warrior2; } public function start_battle() { $round = 0; /* If either's warrior's health is zero, the product of their healths will be zero. */ while($this->_warrior1->get_health() * $this->_warrior2->get_health() > 0 && $round < 30) { $battling_warriors = array($this->_warrior1, $this->_warrior2); if($this->_warrior1->get_speed() < $this->_warrior2->get_speed()) { $battling_warriors = array_reverse($battling_warriors); } else if(!($this->_warrior1->get_speed() > $this->_warrior2->get_speed())){ /* This is a bit ambiguous, the rules don't specify what happens if they have the same speed and defence, so we're assuming it won't happen */ if($this->_warrior1->get_defence() > $this->_warrior2->get_defence()) { $battling_warriors = array_reverse($battling_warriors); } } for($i = 0;$i < 2;++$i) { $damage = $battling_warriors[$i % 2]->attack() - $battling_warriors[($i + 1) % 2]->get_defence(); if($battling_warriors[($i + 1) % 2]->take_damage($damage)) { echo $battling_warriors[$i % 2]->get_name() . " has done " . $damage . " damage! " . $battling_warriors[($i+ 1) % 2]->get_name() . " has " . $battling_warriors[($i + 1) % 2]->get_health() . " left!<br />";; } else { echo $battling_warriors[($i + 1) % 2]->get_name() . " has evaded the attack!<br />"; } } ++$round; } } } class WarriorFactory { public static $types = array('Ninja', 'Samurai', 'Brawler'); public static function factory($type, $name) { if(in_array($type, self::$types)) { return new $type($name); } else { // error } } } class Warrior { /* Health, Attack, Defence and Speed are integer values between 0 and 100. Evade is a number between 0 and 1. */ protected $_name; protected $_max_health; protected $_health; protected $_attack; protected $_defence; protected $_speed; protected $_evade; public function __construct($name, $health, $attack, $defence, $speed, $evade) { $this->_name = $name; $this->_health = $this->_max_health = $health; $this->_attack = $attack; $this->_defence = $defence; $this->_speed = $speed; $this->_evade = $evade; } public function get_name() { return $this->_name; } public function get_health() { return $this->_health; } public function get_max_health() { return $this->_max_health; } public function get_speed() { return $this->_speed; } public function get_defence() { return $this->_defence; } /* Returns true on success hit, false on evade */ public function take_damage($attack) { if(rand(1, 100) <= $this->_evade * 100) { // attack blocked return false; } else { if($attack >= $this->get_health()) { $this->_health = 0; } else { $this->_health -= $attack; } } return true; } public function attack() { return $this->_attack; } } class Ninja extends Warrior { public function __construct($name) { parent::__construct( $name, rand(40, 60), rand(60, 70), rand(20, 30), rand(90, 100), rand(3, 5) / 10 ); } public function attack() { if(rand(0, 19) == 0) { echo $this->get_name() . " has double damage!<br />"; return $this->_attack * 2; } else { return $this->_attack; } } } class Samurai extends Warrior { public function __construct($name) { parent::__construct( $name, rand(60, 100), rand(75, 80), rand(35, 40), rand(60, 80), rand(3, 4) / 10 ); } public function take_damage($attack) { if(!($result = parent::take_damage($attack))) { if(rand(0, 9) == 0) { $this->_health += 10; echo $this->get_name() . " has gained 10 health!<br />"; } } return $result; } } class Brawler extends Warrior { private $_has_defence_bonus = false; public function __construct($name) { parent::__construct( $name, rand(90, 100), rand(65, 75), rand(40, 50), rand(40, 65), round(rand(30, 35) / 100, 2) ); } public function take_damage($attack) { if($result = parent::take_damage($attack) && $this->get_health() < 0.2 * $this->get_max_health() && !$this->_has_defence_bonus) { $this->_defence += 10; $this->_has_defence_bonus = true; echo $this->get_name() . "'s defence has been increased by 10!<br />"; } return $result; } } if(!isset($_POST['check'])) { ?> <form action="" method="POST"> <input type="hidden" name="check" value="1" /> Name <input type="text" name="warrior1_name" value="Warrior 1" /> Type <select name="warrior1_type"> <option value="Ninja">Ninja</option> <option value="Samurai">Samurai</option> <option value="Brawler">Brawler</option> </select> <br /> Name <input type="text" name="warrior2_name" value="Warrior 2" /> Type <select name="warrior2_type"> <option value="Ninja">Ninja</option> <option value="Samurai">Samurai</option> <option value="Brawler">Brawler</option> </select> <br /> <input type="submit" value="Battle!" name="submit" /> </form> <?php } else { $warrior1 = WarriorFactory::factory($_POST['warrior1_type'], $_POST['warrior1_name']); $warrior2 = WarriorFactory::factory($_POST['warrior2_type'], $_POST['warrior2_name']); $battle = new Battle($warrior1, $warrior2); $battle->start_battle(); } ?> Edit: I wish I had more to contribute to the thread question more directly, but all I can offer is speculation and secondhand anecdotal evidence. In many cases it seems like formal education and experience (learning it on your own, whatever) simply offer different things, but both can be valuable to fill in where the other missed out. I think the best option is to get a lot of experience in the field on your own, but to also get the formal education so that you're exposed to certain things that you might not have otherwise been exposed to. Personally, I've never had a formal education in anything computer related, besides a few high school courses on things unrelated to programming, and nothing was really learned, or taught for that matter, anyway. I've been programming for several years now completely self-taught, and I like to think that I've learned a lot, but I know there's still a ton to learn, and that's why this upcoming academic year I'm off to university to study computer science and mathematics, now that I've graduated high school. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233138 Share on other sites More sharing options...
.josh Posted June 22, 2011 Share Posted June 22, 2011 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233155 Share on other sites More sharing options...
Alex Posted June 22, 2011 Share Posted June 22, 2011 I like your idea to use array_reverse to order who goes first and who goes second. I knew my method for that was clunky and could have been done better, but are you using it correctly? In this code: 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) : array_reverse($warriors); ... Are you sure array_reverse is doing what you intend? I don't think you can do it like that (you would have to do $warriors = array_reverse($warriors);) even though you passed $warriors into that function by reference. Maybe I'm wrong, or I'm just missing what you're doing entirely. But I thought you were doing something like this: function test(&$arr){ array_reverse($arr); print_r($arr); } $var = array('1', '2'); test($var); // Array ( [0] => 1 [1] => 2 ) Which you can see doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233158 Share on other sites More sharing options...
.josh Posted June 22, 2011 Share Posted June 22, 2011 aaah you're right...forgot to assign it. Quote Link to comment https://forums.phpfreaks.com/topic/239936-struggling-graduate/#findComment-1233162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.