die.cxx 778 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // die.cxx
  3. // dice-roll
  4. //
  5. // Created by Sam Jaffe on 12/1/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #include "dice-roll/die.h"
  9. #include "dice-roll/exception.h"
  10. namespace dice {
  11. int sgn(sign s) { return s == sign::MINUS ? -1 : 1; }
  12. std::string str(sign s) {
  13. switch (s) {
  14. case sign::PLUS:
  15. return "+";
  16. case sign::MINUS:
  17. return "-";
  18. default:
  19. return "";
  20. }
  21. }
  22. mod::operator int() const { return sgn(sign) * value; }
  23. bool difficulty_class::operator()(int value) const {
  24. switch (comp) {
  25. case test::None: return true;
  26. case test::Less: return value < against;
  27. case test::LessOrEqual: return value <= against;
  28. case test::Greater: return value > against;
  29. case test::GreaterOrEqual: return value >= against;
  30. }
  31. }
  32. }