A set of classes for parsing, evaluating, and formatting die roll strings.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SA_DiceBag.m 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // SA_DiceBag.m
  3. //
  4. // Copyright (c) 2016 Said Achmiz.
  5. //
  6. // This software is licensed under the MIT license.
  7. // See the file "LICENSE" for more information.
  8. #import "SA_DiceBag.h"
  9. /*******************************************/
  10. #pragma mark SA_DiceBag class implementation
  11. /*******************************************/
  12. @implementation SA_DiceBag
  13. /****************************/
  14. #pragma mark - Public methods
  15. /****************************/
  16. - (unsigned long long)biggestPossibleDieSize
  17. {
  18. return UINT32_MAX;
  19. }
  20. - (unsigned long long)rollDie:(unsigned long long)dieSize
  21. {
  22. if(dieSize > UINT32_MAX)
  23. {
  24. return -1;
  25. }
  26. return (unsigned long long) arc4random_uniform((u_int32_t) dieSize) + 1;
  27. }
  28. - (NSArray *)rollNumber:(NSNumber *)number ofDice:(unsigned long long)dieSize
  29. {
  30. if(dieSize > UINT32_MAX)
  31. {
  32. return nil;
  33. }
  34. unsigned long long numRolls = number.unsignedLongLongValue;
  35. NSMutableArray *rollsArray = [NSMutableArray arrayWithCapacity:numRolls];
  36. for(unsigned long long i = 0; i < numRolls; i++)
  37. {
  38. [rollsArray addObject:@((unsigned long long) arc4random_uniform((u_int32_t) dieSize) + 1)];
  39. }
  40. return rollsArray;
  41. }
  42. @end