Skip to content

Instantly share code, notes, and snippets.

@MadaraUchiha
Created May 11, 2012 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadaraUchiha/2662357 to your computer and use it in GitHub Desktop.
Save MadaraUchiha/2662357 to your computer and use it in GitHub Desktop.
Soccer match simulation
<?
/**
* Player class, to describe a single player.
*/
class Player {
protected $name;
/**
* @param string $name
*/
public function __construct($name) {
$this->name = $name;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
}
/**
* Team class, to describe a single team, full of players.
*/
class Team {
protected $name;
protected $players;
/**
* @param string $name
* @param array $players
*/
public function __construct($name, array $players = array()) {
$this->name = $name;
$this->players = $players;
}
/**
* @return string
*/
public function getName() {
return $this->name;
}
/**
* @param string $name
*/
public function setName($name) {
$this->name = $name;
}
/**
* @param Player $player
*/
public function addPlayer(Player $player) {
$this->players[] = $player;
}
/**
* @return Player[]
*/
public function getPlayers() {
return $this->players;
}
}
/**
* Game class, to describe a single game. Will have 2 teams.
*/
class Game {
protected $team1;
protected $team2;
/**
* @param Team $team1
* @param Team $team2
*/
public function __construct(Team $team1, Team $team2) {
$this->team1 = $team1;
$this->team2 = $team2;
}
/**
* @param Team $team1
*/
public function setTeam1(Team $team1) {
$this->team1 = $team1;
}
/**
* @param Team $team2
*/
public function setTeam2(Team $team2) {
$this->team2 = $team2;
}
/**
* @return Team
*/
public function getTeam1() {
return $this->team1;
}
/**
* @return Team
*/
public function getTeam2() {
return $this->team2;
}
}
$p1 = new Player("Lionel Messi");
$p2 = new Player("Christiano Ronaldo");
$t1 = new Team("Barcelona", array($p1));
$t2 = new Team("Real Madrid", array($p2));
$game = new Game($t1, $t2);
print_r($game->getTeam1()->getPlayers());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment