bhonda

msg:4511575 | 8:04 am on Oct 24, 2012 (gmt 0) |
I'm no PHP expert, but you could that same Random function that generates a random integer between 0 and 1 (inclusive) - like you're already doing. Then, you could have an IF statement saying IF random result is 0, add to awayTeam, if random result is 1, add to homeTeam.
|
omoutop

msg:4511610 | 9:43 am on Oct 24, 2012 (gmt 0) |
how about this: $var = array("home", "away"); $test = $var[rand(0, count($var)-1)];
|
bhonda

msg:4511659 | 11:40 am on Oct 24, 2012 (gmt 0) |
| $test = $var[rand(0, count($var)-1)]; |
| Yup, much nicer.
|
Dinkar

msg:4511700 | 2:03 pm on Oct 24, 2012 (gmt 0) |
What exactly you are willing to use ... OOP or classes? FYI, currently you are using classes and NOT OOP. Just creating classes and (programming) object is not REAL OOP. Concept of Object-oriented programming is to emulate a real object. Here TEAM is your main object. So you should try to emulate it with it's characteristics and functionalities (operations). Event should be part of the TEAM object. So it should be something like:-
object_TEAM: characteristic_1 characteristic_2 characteristic_3 characteristic_4
Object_Event: characteristic_1 characteristic_2 characteristic_3 characteristic_4
functionality_1 functionality_2 functionality_3 functionality_4
/Object_Event
functionality_1 functionality_2 functionality_3 functionality_4
/object_TEAM
Now this TEAM object can be a home team, away team, or city/country wise (US, UK etc) team, or sports wise team (football, cricket etc). Team event should be a part of that TEAM. HTH. PS: If you are writing a public function to access a variable (in your case: $idTeam), you should declare that variable as private. If it's public then why do you need any function to access it?
|
skoff

msg:4511879 | 6:57 pm on Oct 24, 2012 (gmt 0) |
well what im trying to do exactly is to create event during a hockey game. So there will be shot, penalty, faceoff events etc. And i want to associate these to home or away team to create a simulated hockey game. So there will be multiple "events" class that i want to create, like shot, penalty, injury etc. Everything that could happen during a game. Im having problem figuring out how to handle and seperate all of this. Do i create a team class and create an array for penalty and create a class for penalty and add each penalty event inside my array of my team class.
|
Dinkar

msg:4512011 | 11:39 pm on Oct 24, 2012 (gmt 0) |
I guess, you may write simple code like this: //CHOOSING RANDOMLY BETWEEN AWAY OR HOME if (rand(1, 2) == 1) { // Home team } else { // Away team } Is there anything I am missing?
|
Dinkar

msg:4512012 | 11:41 pm on Oct 24, 2012 (gmt 0) |
>> Do i create a team class and create an array for penalty and create a class for penalty and add each penalty event inside my array of my team class. I think you need Game class also. That game class will generate event and assign that event to a random team. No game no penalty, right?
|
skoff

msg:4512031 | 12:50 am on Oct 25, 2012 (gmt 0) |
when assigning that event to a random team should i pass by reference my team object to my method of my penalty event so i would be able to know who's in the penalty box for that team?
|
|