Informatika2-2014/FeladatPlayers

A MathWikiből
A lap korábbi változatát látod, amilyen Rpalovics (vitalap | szerkesztései) 2014. április 4., 08:42-kor történt szerkesztése után volt.
(eltér) ←Régebbi változat | Aktuális változat (eltér) | Újabb változat→ (eltér)
class Player:
  def __init__(self,name,height,power,speed,acceleration):
    self.name = name
    self.height = height
    self.power = power
    self.speed = speed
    self.acceleration = acceleration
  def display(self):
    print self.name, self.height, self.power, self.speed, self.acceleration
 
 
player1 = Player("AB", 10, 14, 100, 10)
print "Player1:"
player1.display()
 
class Team:
  def __init__(self,listOfPlayers):
    self.listOfPlayers = listOfPlayers
  def addPlayer(self,player):
    self.listOfPlayers.append(player)
  def displayPlayers(self):
    for player in self.listOfPlayers:
      player.display()
 
player2 = Player("BC", 10, 15, 10, 3)
player3 = Player("CD", 9, 14, 100, 2)
player4 = Player("EF", 8, 20, 800, 1)
team1 = Team([player1,player2,player3,player4])
print "Team1:"
team1.displayPlayers()
 
class PlayerRank:
  def __init__(self,team):
    self.setTeam(team)
  def setTeam(self,team):
    self.team = team
  def getBestPlayer(self):
    bestPlayer = self.team.listOfPlayers[0]
    for player in self.team.listOfPlayers:
      betterPlayer = self.getBetterPlayer(player,bestPlayer)
      if(betterPlayer!=bestPlayer):
        bestPlayer = betterPlayer
    return bestPlayer
  def getBetterPlayer(self,player1,player2):
    pass
 
class PlayerRankSpeed(PlayerRank):
  def getBetterPlayer(self,player1,player2):
    if player1.speed > player2.speed:
      return player1
    else:
      return player2
 
class PlayerRankAcceleration(PlayerRank):
  def getBetterPlayer(self,player1,player2):
    if player1.acceleration > player2.acceleration:
      return player1
    else:
      return player2
 
playerRank = PlayerRankSpeed(team1)
player = playerRank.getBestPlayer()
player.display()
 
player5 = Player("GH", 10, 15, 10, 3)
player6 = Player("IJ", 9, 14, 100, 2)
player7 = Player("KL", 8, 20, 700, 1)
team2 = Team([player5,player6,player7])
Személyes eszközök