Character.C 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <iostream>
  2. #include <boost/lexical_cast.hpp>
  3. #include "Character.h"
  4. Character::Character(const std::string& name, WContainerWidget *parent)
  5. : WText(parent),
  6. name_(name),
  7. redDrops_(0),
  8. blueDrops_(0)
  9. {
  10. setText(name_ + " got no pills");
  11. setStyleClass("character");
  12. /*
  13. * Accept drops, and indicate this with a change in CSS style class.
  14. */
  15. acceptDrops("red-pill", "red-drop-site");
  16. acceptDrops("blue-pill", "blue-drop-site");
  17. setInline(false);
  18. }
  19. void Character::dropEvent(WDropEvent event)
  20. {
  21. if (event.mimeType() == "red-pill")
  22. ++redDrops_;
  23. if (event.mimeType() == "blue-pill")
  24. ++blueDrops_;
  25. std::string text = name_ + " got ";
  26. if (redDrops_ != 0)
  27. text += boost::lexical_cast<std::string>(redDrops_) + " red pill";
  28. if (redDrops_ > 1)
  29. text += "s";
  30. if (redDrops_ != 0 && blueDrops_ != 0)
  31. text += " and ";
  32. if (blueDrops_ != 0)
  33. text += boost::lexical_cast<std::string>(blueDrops_) + " blue pill";
  34. if (blueDrops_ > 1)
  35. text += "s";
  36. setText(text);
  37. }