-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewController.swift
295 lines (213 loc) · 10.2 KB
/
ViewController.swift
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//
// ViewController.swift
// BlackjackReturns
//
// Created by Aamhish Rao on 5/12/16.
// Copyright © 2016 Aamhish Rao. All rights reserved.
//
import UIKit
import AVFoundation
class ViewController: UIViewController {
var count = 0
var p1score = 0
var p2score = 0
var lolllidklollll = true
var chooser = "p1"
var backgroundMusicPlayer = AVAudioPlayer()
func playBackgroundMusic(filename: String) {
let url = NSBundle.mainBundle().URLForResource(filename, withExtension: nil)
guard let newURL = url else {
print("Could not find file: \(filename)")
return
}
do {
backgroundMusicPlayer = try AVAudioPlayer(contentsOfURL: newURL)
backgroundMusicPlayer.numberOfLoops = -1
backgroundMusicPlayer.prepareToPlay()
backgroundMusicPlayer.play()
} catch let error as NSError {
print(error.description)
}
}
@IBAction func clearbuttonlolidk(sender: AnyObject) {
yourmomsbuttonbro.text=""
if(chooser.containsString("p1")){
lolllidk.text="Player 2 come on up!";
imageloll.image=UIImage(named:"backofcard")
NSLog("Attempting Switch")
chooser = "p2"
}
else{
if(p1score>21&&p2score>21){
lolllidk.text="BUSTED both of you"
bruh.text="Restart?"
}
else if(p1score>21){
lolllidk.text = "P1 busted. P2 won"
}
else if(p2score>21){
lolllidk.text = "P2 busted. P1 won"
}
else if(p1score==21){
lolllidk.text="Player1 WON!!!!!"
bruh.text="Restart?"
}
else if(p2score==21){
lolllidk.text="Player2 WON!!!!!"
bruh.text="Restart?"
}
else if(abs(21-p1score)<abs(21-p2score)){
lolllidk.text="Player1 WON!!!!!"
}
else if(abs(21-p1score)>abs(21-p2score)){
lolllidk.text="Player 2 won"
}
else{
NSLog("lol....")
lolllidk.text="Haha lol"
}
}
}
@IBOutlet weak var yourmomsbuttonbro: UILabel!
@IBAction func lolidklol11(sender: AnyObject) {
if(chooser.containsString("p1")){
p1score-=11
p1score+=11
lolllidk.text=" Total score right now \(p1score)"
}
else{
p2score-=11
p2score+=11
lolllidk.text=" Total score right now \(p2score)"
}
yourmom11.text=""
yourdad1.text=""
}
@IBOutlet weak var yourdad1: UILabel!
@IBOutlet weak var yourmom11: UILabel!
@IBAction func lolidklo1(sender: AnyObject) {
if(chooser.containsString("p1")){
p1score-=11
p1score+=1
lolllidk.text=" Total score right now \(p1score)"
yourmom11.text=""
yourdad1.text=""
}
else{
p2score-=11
p2score+=1
lolllidk.text=" Total score right now \(p2score)"
yourmom11.text=""
yourdad1.text=""
}
}
func lolidktheoriginal(){
yourmom11.text="11"
yourdad1.text="1"
}
@IBOutlet weak var bruh: UILabel!
@IBOutlet weak var imageloll: UIImageView!
//@IBOutlet weak var label: UILabel!
@IBAction func lollmanloll(sender: AnyObject) {
p1score=0
p2score=0
chooser = "p1"
yourmomsbuttonbro.text=""
imageloll.image=UIImage(named:"backofcard")
lolllidk.text="Welcome to BasicBlackjack. Lets start with Player 1! Stand or hit?"
}
//@IBOutlet weak var lolllidk: UITextView!
@IBOutlet weak var lolllidk: UITextView!
@IBOutlet weak var testbutton: UIButton!
override func viewDidLoad() {
NSLog("hmm...")
super.viewDidLoad()
playBackgroundMusic("/Users/aamhishrao/Downloads/bgoundmusic.mp3")
}
@IBAction func lolzpass(sender: AnyObject) {
lolidklolidkmanpass()
}
func lolidklolidkmanpass(){
yourmomsbuttonbro.text="Switch?"
}
@IBAction func clickButton(sender: AnyObject) {
var drawloll = Int(arc4random_uniform(10) + 2)
if(chooser.containsString("p1")){
p1score+=drawloll
lolllidk.text="You drew a \(drawloll) Total score right now \(p1score)"
switch(drawloll){
case 11:imageloll.image=UIImage(named:"ace");lolidktheoriginal();if(p1score>21){lolidklolidkmanpass()};
case 2:imageloll.image=UIImage(named:"2");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn";}
case 3:imageloll.image=UIImage(named:"card3");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 4:imageloll.image=UIImage(named:"card4");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 5:imageloll.image=UIImage(named:"card5");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 6:imageloll.image=UIImage(named:"card6");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 7:imageloll.image=UIImage(named:"card7");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 8:imageloll.image=UIImage(named:"card8");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"}
case 9:imageloll.image=UIImage(named:"card9");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score)P2Turn"}
case 10:imageloll.image=UIImage(named:"card10");if(p1score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score) P2Turn"};
default:imageloll.image=UIImage(named:"backofcard")
if(p1score==21){
lolllidk.text="Player 2 come on up!";
imageloll.image=UIImage(named:"backofcard")
NSLog("Attempting Switch")
chooser = "p2"
if(p1score>21&&p2score>21){
lolllidk.text="BUSTED both of you"
bruh.text="Restart?"
}
else if(p1score>21){
lolllidk.text = "P1 busted. P2 won"
}
else if(p2score>21){
lolllidk.text = "P2 busted. P1 won"
}
else if(p1score==21){
lolllidk.text="Player1 WON!!!!!"
bruh.text="Restart?"
}
else if(p2score==21){
lolllidk.text="Player2 WON!!!!!"
bruh.text="Restart?"
}
else if(abs(21-p1score)<abs(21-p2score)){
lolllidk.text="Player1 WON!!!!!"
}
else if(abs(21-p1score)>abs(21-p2score)){
lolllidk.text="Player 2 won"
}
else{
NSLog("lol....")
lolllidk.text="tie"
}
}
//if(drawloll==1){
// NSLog("lollll1")
//}
}
}
else
{
NSLog("Successful Switch")
p2score+=drawloll
lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"
lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"
switch(drawloll){
case 11:imageloll.image=UIImage(named:"ace");lolidktheoriginal()
case 2:imageloll.image=UIImage(named:"2");if(p2score>=21){lolidklolidkmanpass()};lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"
case 3:imageloll.image=UIImage(named:"card3");if(p2score>=21){lolidklolidkmanpass()};lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"
case 4:imageloll.image=UIImage(named:"card4");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 5:imageloll.image=UIImage(named:"card5");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 6:imageloll.image=UIImage(named:"card6");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 7:imageloll.image=UIImage(named:"card7");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 8:imageloll.image=UIImage(named:"card8");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 9:imageloll.image=UIImage(named:"card9");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p2score)"}
case 10:imageloll.image=UIImage(named:"card10");if(p2score>=21){lolidklolidkmanpass();lolllidk.text="You drew a \(drawloll) Total score right now \(p1score)"};
default:imageloll.image=UIImage(named:"backofcard")
}
}
}
// count+=1
// NSLog(String(count))
// label.text=String(count)
}