public function getPowerLevelClass(Programmer $programmer)
 {
     $powerLevel = $programmer->getPowerLevel();
     switch (true) {
         case $powerLevel <= 3:
             return 'danger';
             break;
         case $powerLevel <= 7:
             return 'warning';
             break;
         default:
             return 'success';
     }
 }
 /**
  * Powers up this programmer
  *
  * @param Programmer $programmer
  * @return string A description of what happened
  */
 public function powerUp(Programmer $programmer)
 {
     // vary the power change between 3 and 7
     $powerChange = rand(3, 7);
     // have a 1/4 chance that the change will be negative (and then make the negatives smaller)
     $powerChange = rand(0, 3) == 3 ? floor($powerChange / 2) * -1 : $powerChange;
     $programmer->setPowerLevel($programmer->getPowerLevel() + $powerChange);
     $this->em->persist($programmer);
     $this->em->flush();
     if ($powerChange > 0) {
         $key = array_rand(self::$positiveMessages);
         $message = sprintf(self::$positiveMessages[$key], $powerChange);
     } else {
         $key = array_rand(self::$negativeMessages);
         $message = sprintf(self::$negativeMessages[$key], $powerChange);
     }
     return array('message' => $message, 'powerChange' => $powerChange);
 }
 /**
  * Creates and wages an epic battle
  *
  * @param Programmer $programmer
  * @param Project $project
  * @return Battle
  */
 public function battle(Programmer $programmer, Project $project)
 {
     $battle = new Battle($programmer, $project);
     if ($programmer->getPowerLevel() < $project->getDifficultyLevel()) {
         // not enough energy
         $battle->setBattleLostByProgrammer('You don\'t have the skills to even start this project. Read the documentation (i.e. power up) and try again!');
     } else {
         if (rand(0, 2) != 2) {
             $battle->setBattleWonByProgrammer('You battled heroically, asked great questions, worked pragmatically and finished on time. You\'re a hero!');
         } else {
             $battle->setBattleLostByProgrammer('Requirements kept changing, too many meetings, project failed :(');
         }
         $programmer->setPowerLevel($programmer->getPowerLevel() - $project->getDifficultyLevel());
     }
     $this->em->persist($battle);
     $this->em->persist($programmer);
     $this->em->flush();
     return $battle;
 }
 /**
  * @Route("/programmers/new", name="programmer_new_handle")
  * @Method("POST")
  */
 public function handleNewAction(Request $request)
 {
     $programmer = new Programmer();
     $errors = array();
     $data = $this->getAndValidateData($request, $errors);
     $programmer->setNickname($data['nickname']);
     $programmer->setAvatarNumber($data['avatarNumber']);
     $programmer->setTagLine($data['tagLine']);
     $programmer->setUser($this->getUser());
     if ($errors) {
         return $this->render('programmer/new.twig', array('programmer' => $programmer, 'errors' => $errors));
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($programmer);
     $em->flush();
     $this->addFlash(sprintf('%s has been compiled and is ready for battle!', $programmer->getNickname()));
     return $this->redirect($this->generateUrl('programmer_show', array('nickname' => $programmer->getNickname())));
 }
 private function serializeProgrammer(Programmer $programmer)
 {
     return array('nickname' => $programmer->getNickname(), 'avatarNumber' => $programmer->getAvatarNumber(), 'powerLevel' => $programmer->getPowerLevel(), 'tagLine' => $programmer->getTagLine());
 }