-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hand.kt
47 lines (37 loc) · 1.02 KB
/
Hand.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.avalonomnimedia.playingcardsengine
/**
* [Hand] base class. All hands must inherit from this.
*/
abstract class Hand(initialCards: List<Card> = listOf()) {
@Suppress("PropertyName", "This is an internal property.")
protected val _cards = mutableListOf<Card>()
init {
_cards.addAll(initialCards)
}
fun count(): Int {
return _cards.count()
}
override fun toString(): String {
return _cards.joinToString(separator = ", ")
}
}
class FaceUpHand(initialCards: List<Card> = listOf()) : Hand(initialCards) {
val cards: List<Card> = _cards
fun add(card: Card) {
_cards.add(card)
}
override fun toString(): String {
return _cards.toString()
}
}
class FaceDownStack(initialCards: List<Card> = listOf()) : Hand(initialCards) {
fun addToBottom(card: Card) {
_cards.add(card)
}
fun takeTop(): Card {
return _cards.removeAt(0)
}
override fun toString(): String {
return _cards.toString()
}
}