LevelDefinition.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. namespace DevilLink2.Gameplay
  3. {
  4. /// <summary>Immutable single-level configuration, using display columns/rows.</summary>
  5. public sealed class LevelDefinition
  6. {
  7. public GameMode Mode { get; }
  8. public int Level { get; }
  9. public int Columns { get; }
  10. public int Rows { get; }
  11. public bool HasTimer { get; }
  12. public int TimeLimitSeconds { get; }
  13. public int ClearCoinReward { get; }
  14. public int ClearTicketReward { get; }
  15. public LevelDefinition(GameMode mode, int level, int columns, int rows,
  16. int timeLimitSeconds, int clearCoinReward, int clearTicketReward)
  17. {
  18. GameModeGuard.Validate(mode);
  19. if (level < 1 || level > 20) throw new ArgumentOutOfRangeException(nameof(level));
  20. if (columns <= 0) throw new ArgumentOutOfRangeException(nameof(columns));
  21. if (rows <= 0) throw new ArgumentOutOfRangeException(nameof(rows));
  22. long count = (long)columns * rows;
  23. if (count > int.MaxValue || count % 2 != 0) throw new ArgumentException("Board cell count must be even and representable.");
  24. bool hasTimer = mode != GameMode.Zen;
  25. if (hasTimer ? timeLimitSeconds <= 0 : timeLimitSeconds != 0)
  26. throw new ArgumentOutOfRangeException(nameof(timeLimitSeconds), "Zen has no timer; timed modes require positive seconds.");
  27. if (clearCoinReward < 0) throw new ArgumentOutOfRangeException(nameof(clearCoinReward));
  28. if (clearTicketReward < 0) throw new ArgumentOutOfRangeException(nameof(clearTicketReward));
  29. Mode = mode; Level = level; Columns = columns; Rows = rows; HasTimer = hasTimer;
  30. TimeLimitSeconds = timeLimitSeconds; ClearCoinReward = clearCoinReward; ClearTicketReward = clearTicketReward;
  31. }
  32. }
  33. }