-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
114 lines (91 loc) · 2.96 KB
/
ContentView.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
//
// ContentView.swift
// warGame
//
// Created by Zain 👻 on 25/07/2021.
//
import SwiftUI
struct ContentView: View
{
@State var CpuScore = 0
@State var PlayerScore = 0
@State var CpuCard = "card14"
@State var PlayerCard = "card5"
var body: some View
{
ZStack
{
VStack()
{
Spacer()
Image("logo")
Spacer()
HStack()
{
Spacer()
Image(CpuCard)
Spacer()
Image(PlayerCard)
Spacer()
}
Spacer()
Button (action:
{
//generate the random numbers between 2 and 14
let playerRandom = Int.random(in: 2...14)
let cpuRandom = Int.random(in: 2...14)
// Update the Card
PlayerCard = "card" + String(playerRandom)
CpuCard = "card" + String(cpuRandom)
if playerRandom > cpuRandom
{ PlayerScore += playerRandom }
else if cpuRandom > playerRandom
{ CpuScore += cpuRandom }
}
,label :
{
Image("dealbutton")
.aspectRatio(22, contentMode: .fit)
}
)
Spacer()
HStack(alignment: .center)
{ Spacer()
VStack(alignment: .center)
{
Text("CPU")
.font(.largeTitle)
.foregroundColor(Color.white)
.bold()
Text(String(CpuScore))
.font(.largeTitle)
.foregroundColor(Color.white)
.bold()
.padding(.top, 10.0)
}.padding()
Spacer()
VStack(alignment: .center)
{
Text("Player")
.font(.largeTitle)
.foregroundColor(Color.white)
.bold()
Text(String(PlayerScore))
.font(.largeTitle)
.foregroundColor(Color.white)
.bold()
.padding(.top, 10.0)
}.padding()
Spacer()
}.padding(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
Spacer()
}.background(Image("backback"))
//.background(Color.accentColor).ignoresSafeArea()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}