-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.worksheet.sc
153 lines (119 loc) · 2.97 KB
/
demo.worksheet.sc
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
import scala.reflect.internal.pickling.PickleFormat
1 + 2
val x = 3
def f(x: Int) = x + 1
f(7)
val l = List(1, 2, 3)
l.length
val romme = """romme"""
val oben = "+---+---+"
val mitte = """
| | |
| | |
| | |
"""
val unten = "+---+---+"
val plus = "+"
val minus = "-"
val zusammen = plus + minus * 3 + plus + minus * 3 + plus
def testfunktion(breite: Int) = minus * breite
val test = testfunktion(4)
print(test)
val stern = "*"
val drei = 3
case class Karten(name: String)
val karte = Karten("Karo-Ass")
karte.name
val KartenListe = List(karte)
enum Zahlen:
case Bube, Dame, König, Ass , Zwei, Drei, Vier, Fünf, Sechs, Sieben, Acht, Neun, Zehn
enum Arten:
case Herz, Karo, Kreuz, Pick
case class testKarten(var a: Arten,var z: Zahlen):
def zeigeKarte() = print(a,z)
def zeigeKarteAlsString() : Unit = {
var s:String = this.a.toString +", " + this.z.toString
}
def neueZahl(nz: Zahlen): testKarten = {
this.z = nz
return this
}
def neueArt(na: Arten): testKarten = {
this.a = na
return this
}
val test3 = new testKarten(Arten.Karo,Zahlen.Acht)
print(test3.zeigeKarteAlsString())
test3.zeigeKarte()
test3.neueArt(Arten.Herz)
test3.neueZahl(Zahlen.Bube)
print(test3.a)
print(test3.z)
/*case class herzkarten(kartenArt: Herz):
def zeigeKarte() = print(this.kartenArt)
val k = herzkarten(Herz.Acht)
k.zeigeKarte()
*/
*/
import scala.collection.mutable.ListBuffer
class Card(suit: Integer, rank: Integer) {
val suitList: List[String] =
List("Heart", "Diamond", "Club", "Spades", "Joker")
val rankList: List[String] = List(
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"jack",
"queen",
"king",
"ace",
""
)
def getCardName(): (String, String) = {
val suitAsString = suitList(suit)
val rankAsString = rankList(rank)
return (suitAsString, rankAsString)
}
}
class Deck() {
var deckList: ListBuffer[Card] = ListBuffer()
def createNewDeck(): Unit = {
var suitCounter = 0
var rankCounter = 0
for (suitCounter <- 0 to 3) {
for (rankCounter <- 0 to 12) {
val c = new Card(suitCounter, rankCounter)
deckList :+ c // add every Card twice
deckList :+ c
}
}
var jokerCounter = 0
for (jokerCounter <- 1 to 6) {
val jokerCard = new Card(4, 13)
deckList :+ jokerCard
}
print(deckList.length)
}
def drawFromDeck(): Card = {
val random = new scala.util.Random // random generator
// safe a random value between 0 and the size of the current deck - 1
val tmp = random.nextInt(deckList.length - 1)
// safe the card which will be drawn from the deck
val tmpsafe = deckList(tmp)
deckList.remove(tmp) // remove the card from the game
return tmpsafe // return the card
}
}
var d = new Deck()
var deckLiest: ListBuffer[Integer] = ListBuffer()
var i = 0
for (i <- 0 to 100)
deckLiest.addOne(i)
print(deckLiest.size)