Untitled

mail@pastecode.io avatar
unknown
swift
2 months ago
1.3 kB
1
Indexable
Never
//
//  Model.swift
//  lab3Kowalczyk
//
//  Created by Jakub Kowalczyk on 17/04/2024.
//

import Foundation
import SwiftUI

class Model: ObservableObject {
    let correctAnswer: [String] = ["1", "2", "3", "4", "5"]
    @Published var guessedNumbers: [String] = ["", "", "", "", ""]
    @Published var colors: [Color] = [.white, .white, .white, .white, .white]
    @Published var buttonTitleColors: [Color] = [.white, .white, .white, .white, .white]
    
    private var pickedColumn = "0";
    
    func pickNumber(newNumber: String) {
        guessedNumbers[Int(pickedColumn)!] = newNumber
    }
    
    func pickColumn(newColumn: String) {
        pickedColumn = newColumn
    }
    
    func check() {
        for i in 0...4 {
            if correctAnswer[i] == guessedNumbers[i] {
                colors[i] = .green
            }
            else if (correctAnswer.contains(guessedNumbers[i])) {
                colors[i] = .orange
            }
            else {
                colors[i] = .red
            }
            
        }
    }
    
    func restart() {
        guessedNumbers = ["", "", "", "", ""]
        colors = [.white, .white, .white, .white, .white]
        buttonTitleColors = [.white, .white, .white, .white, .white]
    }
}
Leave a Comment