Added ModelView and a new Game button on View

This commit is contained in:
2023-04-10 15:25:56 +02:00
parent 51e1d63929
commit 5665c75030
3 changed files with 36 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ import SwiftUI
struct SetApp: App { struct SetApp: App {
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
SetGameView(game: SetGame()) SetGameView(game: SetGameModelView())
} }
} }
} }

View File

@@ -0,0 +1,30 @@
//
// SetGameModelView.swift
// Set
//
// Created by Oliver Hnát on 10.04.2023.
//
import Foundation
class SetGameModelView: ObservableObject {
typealias Card = SetGame.Card
@Published private var model: SetGame
init() {
self.model = SetGame()
}
var cardsOnTable: Array<Card> {
model.cardsOnTable
}
func newGame() {
self.model = SetGame()
}
}

View File

@@ -9,7 +9,7 @@ import SwiftUI
struct SetGameView: View { struct SetGameView: View {
var game: SetGame @ObservedObject var game: SetGameModelView
var body: some View { var body: some View {
VStack { VStack {
AspectVGrid(items: game.cardsOnTable, aspectRatio: 2/3) { card in AspectVGrid(items: game.cardsOnTable, aspectRatio: 2/3) { card in
@@ -17,7 +17,7 @@ struct SetGameView: View {
} }
Spacer() Spacer()
Spacer() Spacer()
// Button(action: {game.newGame()}, label: {Text("New game")}) Button(action: {game.newGame()}, label: {Text("New game").font(.largeTitle)})
} }
} }
@@ -25,13 +25,13 @@ struct SetGameView: View {
struct CardView: View { struct CardView: View {
var card: SetGame.Card var card: SetGameModelView.Card
var numberOfSymbols: Int var numberOfSymbols: Int
var color: Color var color: Color
var symbol: CardSymbol var symbol: CardSymbol
var shading: CardShading var shading: CardShading
init(card: SetGame.Card) { init(card: SetGameModelView.Card) {
self.card = card self.card = card
self.numberOfSymbols = card.numberOnCard self.numberOfSymbols = card.numberOnCard
self.color = card.color self.color = card.color
@@ -96,7 +96,7 @@ struct CardView: View {
struct ContentView_Previews: PreviewProvider { struct ContentView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
let game = SetGame() let game = SetGameModelView()
SetGameView(game: game) SetGameView(game: game)
.preferredColorScheme(.dark) .preferredColorScheme(.dark)
SetGameView(game: game) SetGameView(game: game)