Last active
September 15, 2015 02:28
-
-
Save romainmenke/7c9a28d377bdcb639c93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TicketMan { | |
private var ticketStack : Int = 0 | |
private var ticketCounter : Int = 0 | |
var ticket : Int { | |
get { | |
ticketStack += 1 | |
ticketCounter += 1 | |
return ticketCounter | |
} | |
} | |
//you set this as private and call it inside validateTicket() | |
func ripTicket(ticket : Int) { | |
ticketStack -= 1 | |
if ticketStack == 0 { | |
ticketCounter = 0 //because overflows are a real thing ;) | |
} | |
} | |
func validateTicket(ticket: Int) -> Bool { | |
if ticket == ticketCounter { | |
return true | |
} else { | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment