I have a Player class that stores a rating property of type Int:
class Player {
typealias Rating: Int
var rating: Rating = 0
}
I then have various Range instances that specify the level that a given player is at:
private let level1Range = 0 ..< 100
private let level2Range = 100 ..< 500
I can then switch on the player rating property to obtain the level that the player is at:
switch rating {
case level1Range:
print("On Level 1")
case level2Range:
print("On Level 2")
default:
break
}
I want to be able to say what the next level is and how far away the player is from that next level.
I'm not sure of the best way to go out this problem. I started by making an array:
private var ratingRanges: [Range] {
return [level1Range, level2Range]
}
But I get the error:
Reference to generic type 'Range' requires arguments in <...> Insert '<<#Bound: Comparable#>>'
If this worked, I guess I could then find the first non-zero value:
ratingRanges.first(where: { $0.min() - self.rating > 0 })
in order to locate the next range.
Or is there a more efficient method to achieve this?
Thanks for any help