The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 24, 2013, 06:41:41 AM

Login with username, password and session length


Pages: 1 [2]
  Print  
Author Topic: PHP classes, little help please :)  (Read 1856 times)
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #15 on: October 01, 2009, 03:07:40 PM »

Quote
Hope this spawned some thoughts...
It sure did. I still have something nagging in the back of my brain so I'll read missile game example again and it will probably sort itself out.

I'm finally starting to actually understand how this all comes together and it sure is a different way of thinking than your traditional way of coding. God I want so badly to code some sort of Life game, you know those games that have little creatures that interact with each other randomly and stuff happens. Seems like perfect way to understand the logic because each creature would be an object with classes like kick the living shit out of other creature which would call fight class and so on.
Logged

I met god and he had nothing to say to me.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10009



View Profile
« Reply #16 on: October 01, 2009, 03:30:07 PM »

EXACTLY. You're on the perfect mental path here.

It's a great ride man, when you first start to grok OO.
Enjoy the moment. I am enjoying it for you as well 



Just realized, looking back that some pseudocode would be strong to show what all this actually looked like. Note that this is somewhat PHP like but has nothing to do with PHP ... this is just for illustration.

First, I'll respond to an event of a button push. It looked something like this:
function onButton(sender)
{
   // the constructor for gpDefender accepts the start XY and the destination XY as parameters...
   gameQueue.add(new gpDefender(sender.x, sender.y, crossHair->x, crossHair->y));
}

Here's what it might have looked like for a jet to see if it should explode...

...
explosions = gameQueue->getAll(gpExplosions);
foreach(explosions as explosion)
{
   if (this->insideOf(explosion->boundingRect()))
   {
      gameQueue->kill(this);
      gameQueue->add(new gpExplosion(this->x, this->y));
      break;
   }
}

You can really make OO code read like a book, if you name things right - much more so than structured programming I find.
« Last Edit: October 01, 2009, 03:32:35 PM by perkiset » Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
kurdt
Lifer
*****
Offline Offline

Posts: 1153


paha arkkitehti


View Profile
« Reply #17 on: October 02, 2009, 06:19:36 AM »

I have been playing with OOP code all day and I'm starting to get hang of it. It's still A LOT slower than writing with my old ways but I'm getting better.

One WOAAAAHHH (keanu sound) moment was when I had to do multiple different functions for multicurl. I did like addProxy and other CURLOPT thingies. I first was pulling my hair out because array_push($this->curlOpts[CURLOPT_USERAGENT], "Mozilla"); just didn't work. Then I realized that I don't need to play with arrays anymore. I can just do $this->curlOpts[CURLOPT_USERAGENT] = "Mozilla" and don't worry about overwriting other items in the array. I'm not sure if I'm dumber than average but I'm starting to realize how this makes everything so much easier in the long run Smiley
Logged

I met god and he had nothing to say to me.
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #18 on: October 02, 2009, 08:39:47 AM »

not at all kurdt.

OO is a really really hard one to shift your brain to if you have been a procedural programmer for a long time.

I had been procedural for soooooo long, that it is still really hard for me to recognize when something should be an object.
Thats part of the reason for my adventure into CI. I want a base framework, to help me force the object mindset. Since at least if I see a lot more classes, and have to call a lot more classes, I might actually think more about making something a class/object. Its just so freakin easy to make 1-big-ass-function-file and stuff every procedure under the sun in there...
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: 1 [2]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!