mirror of
https://github.com/neon443/CookieSwifter.git
synced 2026-03-11 07:09:11 +00:00
broke multibuy need to fix - on a better note i redid the ui - a lot less cluttered
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "1620"
|
||||||
|
version = "1.7">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES"
|
||||||
|
buildArchitectures = "Automatic">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "A912A5FE2D10109500703A89"
|
||||||
|
BuildableName = "CookieSwifter.app"
|
||||||
|
BlueprintName = "CookieSwifter"
|
||||||
|
ReferencedContainer = "container:CookieSwifter.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
shouldAutocreateTestPlan = "YES">
|
||||||
|
<Testables>
|
||||||
|
<TestableReference
|
||||||
|
skipped = "NO"
|
||||||
|
parallelizable = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "A912A60F2D10109C00703A89"
|
||||||
|
BuildableName = "CookieSwifterTests.xctest"
|
||||||
|
BlueprintName = "CookieSwifterTests"
|
||||||
|
ReferencedContainer = "container:CookieSwifter.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</TestableReference>
|
||||||
|
<TestableReference
|
||||||
|
skipped = "NO"
|
||||||
|
parallelizable = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "A912A6192D10109C00703A89"
|
||||||
|
BuildableName = "CookieSwifterUITests.xctest"
|
||||||
|
BlueprintName = "CookieSwifterUITests"
|
||||||
|
ReferencedContainer = "container:CookieSwifter.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</TestableReference>
|
||||||
|
</Testables>
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = ""
|
||||||
|
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "A912A5FE2D10109500703A89"
|
||||||
|
BuildableName = "CookieSwifter.app"
|
||||||
|
BlueprintName = "CookieSwifter"
|
||||||
|
ReferencedContainer = "container:CookieSwifter.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "A912A5FE2D10109500703A89"
|
||||||
|
BuildableName = "CookieSwifter.app"
|
||||||
|
BlueprintName = "CookieSwifter"
|
||||||
|
ReferencedContainer = "container:CookieSwifter.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
59
CookieSwifter/CookieSwifter/AchievementsView.swift
Normal file
59
CookieSwifter/CookieSwifter/AchievementsView.swift
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
//
|
||||||
|
// AchievementsView.swift
|
||||||
|
// CookieSwifter
|
||||||
|
//
|
||||||
|
// Created by Nihaal Sharma on 28/12/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct AchievementButton: View {
|
||||||
|
@ObservedObject var game: CookieGame
|
||||||
|
@Binding var showAchievements: Bool
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
Button(action: {
|
||||||
|
showAchievements.toggle()
|
||||||
|
}) {
|
||||||
|
Text("\(game.achievements.count) Achievements")
|
||||||
|
.font(.title3)
|
||||||
|
.padding(5)
|
||||||
|
.background(Color.purple.opacity(0.2))
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
.sheet(isPresented: $showAchievements) {
|
||||||
|
AchievementsView(achievements: game.achievements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
struct AchievementsView: View {
|
||||||
|
let achievements: [Achievement]
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationView {
|
||||||
|
List(achievements, id: \.title) { achievement in
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text(achievement.title)
|
||||||
|
.font(.headline)
|
||||||
|
Text(achievement.description)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("Achievements")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
AchievementsView(
|
||||||
|
achievements: [
|
||||||
|
Achievement(
|
||||||
|
title: "Cookie Beginner",
|
||||||
|
description: "Earn 100 cookies."
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@ObservedObject var gameManager: CookieGame
|
@ObservedObject var game: CookieGame
|
||||||
@State private var selectedSave: String? = nil
|
@State private var selectedSave: String? = nil
|
||||||
@State private var showSavedGames: Bool = false
|
@State private var showSavedGames: Bool = false
|
||||||
@State private var buyQuantity: Int = 1
|
@State private var buyQuantity: Int = 1
|
||||||
@@ -16,10 +16,7 @@ struct ContentView: View {
|
|||||||
@State var showAchievemetns: Bool = false
|
@State var showAchievemetns: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 10) {
|
VStack {
|
||||||
Text("\(gameManager.cookies)")
|
|
||||||
.font(.largeTitle)
|
|
||||||
.fontWeight(.bold)
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("Game Name")
|
Text("Game Name")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
@@ -27,75 +24,108 @@ struct ContentView: View {
|
|||||||
TextField("", text: $gameName)
|
TextField("", text: $gameName)
|
||||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
|
||||||
|
|
||||||
Picker("Buy", selection: $buyQuantity) {
|
|
||||||
ForEach([1, 10, 100], id: \.self) { option in
|
|
||||||
Text("\(option)").tag(option)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(SegmentedPickerStyle())
|
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.top)
|
|
||||||
ItemsListView(gameManager: gameManager, buyQuantity: $buyQuantity)
|
|
||||||
UpgradesListView(gameManager: gameManager)
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
HStack {
|
HStack {
|
||||||
VStack {
|
Text("\(game.cookies)")
|
||||||
Button("Save Game") {
|
.font(.largeTitle)
|
||||||
let saveDate = "Saved \(Date().formatted())"
|
.fontWeight(.bold)
|
||||||
gameManager.saveGame(name: gameName+saveDate)
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
.background(Color.green)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.cornerRadius(10)
|
|
||||||
|
|
||||||
Button("Load Game") {
|
|
||||||
showSavedGames = true
|
|
||||||
}
|
|
||||||
.padding()
|
|
||||||
.background(Color.blue)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.cornerRadius(10)
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showSavedGames) {
|
|
||||||
SavedGamesListView(gameManager: gameManager, selectedSave: $selectedSave)
|
|
||||||
}
|
|
||||||
.onChange(of: selectedSave) { newValue in
|
|
||||||
if let saveName = newValue {
|
|
||||||
gameManager.loadGame(named: saveName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
CookieTapView(gameManager: gameManager)
|
CookieTapView(game: game)
|
||||||
Text("CPS: \(gameManager.cps)")
|
Text("CPS: \(game.cps)")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
}
|
}
|
||||||
Spacer()
|
|
||||||
|
|
||||||
AchievementButton(
|
|
||||||
gameManager: gameManager,
|
|
||||||
showAchievements: $showAchievemetns
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
TabView {
|
||||||
|
Tab {
|
||||||
|
Picker("Buy", selection: $buyQuantity) {
|
||||||
|
ForEach([1, 10, 100], id: \.self) { option in
|
||||||
|
Text("\(option)").tag(option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(SegmentedPickerStyle())
|
||||||
|
.padding(.top)
|
||||||
|
ScrollView(.vertical) {
|
||||||
|
ItemsListView(game: game, buyQuantity: $buyQuantity)
|
||||||
|
}
|
||||||
|
// Spacer()
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "star.fill")
|
||||||
|
Text("Items")
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab {
|
||||||
|
ScrollView(.vertical) {
|
||||||
|
UpgradesListView(game: game)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "wand.and.stars")
|
||||||
|
Text("Upgrades")
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab {
|
||||||
|
HStack {
|
||||||
|
VStack {
|
||||||
|
Button("Save Game") {
|
||||||
|
let saveDate = "Saved \(Date().formatted())"
|
||||||
|
game.saveGame(name: gameName+saveDate)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color.green)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
|
||||||
|
Button("Load Game") {
|
||||||
|
showSavedGames = true
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.background(Color.blue)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
.sheet(isPresented: $showSavedGames) {
|
||||||
|
SavedGamesListView(game: game, selectedSave: $selectedSave)
|
||||||
|
}
|
||||||
|
.onChange(of: selectedSave) { newValue in
|
||||||
|
if let saveName = newValue {
|
||||||
|
game.loadGame(named: saveName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
VStack {
|
||||||
|
CookieTapView(game: game)
|
||||||
|
Text("CPS: \(game.cps)")
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "gear")
|
||||||
|
Text("Settings")
|
||||||
|
}
|
||||||
|
Tab {
|
||||||
|
ScrollView(.vertical) {
|
||||||
|
AchievementsView(achievements: game.achievements)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Image(systemName: "trophy.fill")
|
||||||
|
.badge(game.achievements.count)
|
||||||
|
Text("hi")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SavedGamesListView: View {
|
struct SavedGamesListView: View {
|
||||||
@ObservedObject var gameManager: CookieGame
|
@ObservedObject var game: CookieGame
|
||||||
@Binding var selectedSave: String?
|
@Binding var selectedSave: String?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
List {
|
List {
|
||||||
ForEach(gameManager.savedGames, id: \ .name) { save in
|
ForEach(game.savedGames, id: \ .name) { save in
|
||||||
HStack {
|
HStack {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
Text(save.name).font(.headline)
|
Text(save.name).font(.headline)
|
||||||
@@ -113,7 +143,7 @@ struct SavedGamesListView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onDelete { indexSet in
|
.onDelete { indexSet in
|
||||||
indexSet.map { gameManager.savedGames[$0].name }.forEach(gameManager.deleteGame(named:))
|
indexSet.map { game.savedGames[$0].name }.forEach(game.deleteGame(named:))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle("Saved Games")
|
.navigationTitle("Saved Games")
|
||||||
@@ -122,13 +152,13 @@ struct SavedGamesListView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct CookieTapView: View {
|
struct CookieTapView: View {
|
||||||
@ObservedObject var gameManager: CookieGame
|
@ObservedObject var game: CookieGame
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 10) {
|
VStack {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
gameManager.cookies += 1
|
game.cookies += 1
|
||||||
gameManager.checkAchievements()
|
game.checkAchievements()
|
||||||
}) {
|
}) {
|
||||||
Text("🍪")
|
Text("🍪")
|
||||||
.font(.system(size: 75))
|
.font(.system(size: 75))
|
||||||
@@ -137,7 +167,7 @@ struct CookieTapView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct ItemsListView: View {
|
struct ItemsListView: View {
|
||||||
@ObservedObject var gameManager: CookieGame
|
@ObservedObject var game: CookieGame
|
||||||
@Binding var buyQuantity: Int
|
@Binding var buyQuantity: Int
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -152,122 +182,92 @@ struct ItemsListView: View {
|
|||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 5)
|
.padding(.horizontal, 5)
|
||||||
VStack(spacing: 10) {
|
VStack {
|
||||||
ForEach(gameManager.items.indices, id: \.self) { index in
|
ForEach(game.items.indices, id: \.self) { index in
|
||||||
HStack(spacing: 10) {
|
ItemView(game: game, buyQuantity: buyQuantity, index: index)
|
||||||
Button(action: {
|
|
||||||
gameManager.buyItem(at: index, quantity: buyQuantity)
|
|
||||||
}) {
|
|
||||||
HStack {
|
|
||||||
Text("\(gameManager.items[index].count) x \(gameManager.items[index].name)")
|
|
||||||
Spacer()
|
|
||||||
Text("🍪 \(gameManager.totalCost(of: index, quantity: buyQuantity))")
|
|
||||||
.font(.caption2)
|
|
||||||
}
|
|
||||||
.padding(5)
|
|
||||||
.background(Color.blue.opacity(0.2))
|
|
||||||
.cornerRadius(10)
|
|
||||||
}
|
|
||||||
.disabled(gameManager.cookies < gameManager.totalCost(of: index, quantity: buyQuantity))
|
|
||||||
// if gameManager.cookies < gameManager.totalCost(of: index, quantity: buyQuantity) {
|
|
||||||
// Gauge(
|
|
||||||
// value: gameManager.cookies,
|
|
||||||
// in: 1..<gameManager
|
|
||||||
// .totalCost(of: index, quantity: buyQuantity),
|
|
||||||
// label: Text("d")
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
SellButton(
|
|
||||||
gameManager: gameManager,
|
|
||||||
index: index,
|
|
||||||
buyQuantity: buyQuantity
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct SellButton: View {
|
|
||||||
@ObservedObject var gameManager: CookieGame
|
struct ItemView: View {
|
||||||
@State var index: Int
|
@ObservedObject var game: CookieGame
|
||||||
@State var buyQuantity: Int
|
@State var buyQuantity: Int
|
||||||
|
@State var index: Int
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 5) {
|
||||||
|
Button(action: {
|
||||||
|
game.buyItem(at: index, quantity: buyQuantity)
|
||||||
|
}) {
|
||||||
|
HStack {
|
||||||
|
Text("\(game.items[index].count) x \(game.items[index].name)")
|
||||||
|
.bold()
|
||||||
|
Spacer()
|
||||||
|
Text("🍪 \(game.totalCost(of: index, quantity: buyQuantity))")
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
.padding(5)
|
||||||
|
.background(Color.blue.opacity(0.2))
|
||||||
|
.cornerRadius(10)
|
||||||
|
}
|
||||||
|
.disabled(game.cookies < game.totalCost(of: index, quantity: buyQuantity))
|
||||||
|
SellButton(
|
||||||
|
game: game,
|
||||||
|
index: $index,
|
||||||
|
buyQuantity: $buyQuantity
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SellButton: View {
|
||||||
|
@ObservedObject var game: CookieGame
|
||||||
|
@Binding var index: Int
|
||||||
|
@Binding var buyQuantity: Int
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: {
|
Button(action: {
|
||||||
gameManager.sellItem(at: index, quantity: buyQuantity)
|
game.sellItem(at: index, quantity: buyQuantity)
|
||||||
}) {
|
}) {
|
||||||
Text("🍪 \(gameManager.totalCost(of: index, quantity: buyQuantity) / 2)")
|
Text("🍪 \(game.totalCost(of: index, quantity: buyQuantity) / 2)")
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.background(Color.red.opacity(0.2))
|
.background(Color.red.opacity(0.2))
|
||||||
.cornerRadius(10)
|
.cornerRadius(10)
|
||||||
}
|
}
|
||||||
.disabled(gameManager.items[index].count < buyQuantity)
|
.disabled(game.items[index].count < buyQuantity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct UpgradesListView: View {
|
struct UpgradesListView: View {
|
||||||
@ObservedObject var gameManager: CookieGame
|
@ObservedObject var game: CookieGame
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
VStack(spacing: 10) {
|
VStack(spacing: 10) {
|
||||||
Text("Upgrades")
|
Text("Upgrades")
|
||||||
.font(.footnote)
|
.font(.footnote)
|
||||||
ForEach(gameManager.upgrades.indices, id: \.self) { index in
|
ForEach(game.upgrades.indices, id: \.self) { index in
|
||||||
Button(action: {
|
Button(action: {
|
||||||
gameManager.purchaseUpgrade(at: index)
|
game.purchaseUpgrade(at: index)
|
||||||
}) {
|
}) {
|
||||||
HStack {
|
HStack {
|
||||||
Text(gameManager.upgrades[index].name)
|
Text(game.upgrades[index].name)
|
||||||
Text(gameManager.upgrades[index].description)
|
.bold()
|
||||||
|
Text(game.upgrades[index].description)
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("🍪 \(gameManager.upgrades[index].cost)")
|
Text("🍪 \(game.upgrades[index].cost)")
|
||||||
}
|
}
|
||||||
.padding(5)
|
.padding(5)
|
||||||
.background(gameManager.upgrades[index].isPurchased ? Color.green.opacity(0.2) : Color.gray.opacity(0.2))
|
.background(game.upgrades[index].isPurchased ? Color.green.opacity(0.2) : Color.gray.opacity(0.2))
|
||||||
.cornerRadius(10)
|
.cornerRadius(10)
|
||||||
}
|
}
|
||||||
.disabled(gameManager.cookies < gameManager.upgrades[index].cost || gameManager.upgrades[index].isPurchased)
|
.disabled(game.cookies < game.upgrades[index].cost || game.upgrades[index].isPurchased)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct AchievementButton: View {
|
|
||||||
@ObservedObject var gameManager: CookieGame
|
|
||||||
@Binding var showAchievements: Bool
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 10) {
|
|
||||||
Button(action: {
|
|
||||||
showAchievements.toggle()
|
|
||||||
}) {
|
|
||||||
Text("\(gameManager.achievements.count) Achievements")
|
|
||||||
.font(.title3)
|
|
||||||
.padding(5)
|
|
||||||
.background(Color.purple.opacity(0.2))
|
|
||||||
.cornerRadius(10)
|
|
||||||
}
|
|
||||||
.sheet(isPresented: $showAchievements) {
|
|
||||||
AchievementsView(achievements: gameManager.achievements)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
struct AchievementsView: View {
|
|
||||||
let achievements: [Achievement]
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
NavigationView {
|
|
||||||
List(achievements, id: \.title) { achievement in
|
|
||||||
VStack(alignment: .leading) {
|
|
||||||
Text(achievement.title)
|
|
||||||
.font(.headline)
|
|
||||||
Text(achievement.description)
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundColor(.gray)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.navigationTitle("Achievements")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
ContentView(game: CookieGame(), gameName: "Preview Bakery")
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// GameManager.swift
|
// CookieGame.swift
|
||||||
// CookieSwifter
|
// CookieSwifter
|
||||||
//
|
//
|
||||||
// Created by Nihaal Sharma on 16/12/2024.
|
// Created by Nihaal Sharma on 16/12/2024.
|
||||||
@@ -99,6 +99,7 @@ class CookieGame: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sellItem(at index: Int, quantity: Int) {
|
func sellItem(at index: Int, quantity: Int) {
|
||||||
|
print("selling \(quantity) of \(index) which is \(items[index ])")
|
||||||
guard items[index].count >= quantity else { return }
|
guard items[index].count >= quantity else { return }
|
||||||
|
|
||||||
items[index].count -= quantity
|
items[index].count -= quantity
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ struct CookieSwifterApp: App {
|
|||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
ContentView(
|
ContentView(
|
||||||
gameManager: CookieGame(),
|
game: CookieGame(),
|
||||||
gameName: (listOfNames.randomElement() ?? "Bob") + "'s Bakery"
|
gameName: (listOfNames.randomElement() ?? "Bob") + "'s Bakery"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
15
wak.toml
15
wak.toml
@@ -1,15 +0,0 @@
|
|||||||
# https://github.com/iamawatermelo/wakapi-anyide v0.6.8
|
|
||||||
|
|
||||||
[meta]
|
|
||||||
version = 1
|
|
||||||
watchers = ['files']
|
|
||||||
|
|
||||||
[files]
|
|
||||||
include = ["*"] # files to include in tracking
|
|
||||||
exclude = [] # files to exclude in tracking
|
|
||||||
exclude_files = [] # files whose contents will be used to exclude other files from tracking
|
|
||||||
exclude_binary_files = true # whether to ignore binary files
|
|
||||||
# language_mapping = {".kicad_sch" = "Kicad Schematic"} # custom language mapping
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "CookieSwifter" # your project name
|
|
||||||
Reference in New Issue
Block a user