Skip to content

Commit

Permalink
Merge branch 'main' of github.com:iamalexman/Memojis
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalexman committed Jun 9, 2024
2 parents c9ce872 + b8389a9 commit a5530c8
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 65 deletions.
2 changes: 2 additions & 0 deletions Memojis.docc/Memojis.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Test your brain! Flip the cards to find a maching emoji pair.
- The player can tap the `restart` button to restart the game.

- The player can tap the `shuffle` button to shuffle the cardset.

> Tip: The game for only one player.
}
}

Expand Down
28 changes: 14 additions & 14 deletions Memojis.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

/* Begin PBXBuildFile section */
5E1B2DC02C068A1D0006DD19 /* Memojis.docc in Sources */ = {isa = PBXBuildFile; fileRef = 5E1B2DBF2C068A1D0006DD19 /* Memojis.docc */; };
5E1B2DD72C1656F60006DD19 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E1B2DD62C1656F60006DD19 /* Preview Assets.xcassets */; };
5E5DE5ED2718D02800C79175 /* MemojisApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5DE5EC2718D02800C79175 /* MemojisApp.swift */; };
5E5DE5EF2718D02800C79175 /* MemojiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5DE5EE2718D02800C79175 /* MemojiView.swift */; };
5E5DE5F12718D02900C79175 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E5DE5F02718D02900C79175 /* Assets.xcassets */; };
5E5DE5F42718D02900C79175 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5E5DE5F32718D02900C79175 /* Preview Assets.xcassets */; };
5E5DE5FB271A189F00C79175 /* MemojiModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5DE5FA271A189F00C79175 /* MemojiModel.swift */; };
5E5DE5FD271A1A4400C79175 /* MemojiViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5DE5FC271A1A4400C79175 /* MemojiViewModel.swift */; };
5E5DE5FF2720CAC200C79175 /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5DE5FE2720CAC200C79175 /* Grid.swift */; };
Expand All @@ -34,11 +34,11 @@

/* Begin PBXFileReference section */
5E1B2DBF2C068A1D0006DD19 /* Memojis.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Memojis.docc; sourceTree = "<group>"; };
5E1B2DD62C1656F60006DD19 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
5E5DE5E92718D02800C79175 /* Memojis.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Memojis.app; sourceTree = BUILT_PRODUCTS_DIR; };
5E5DE5EC2718D02800C79175 /* MemojisApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemojisApp.swift; sourceTree = "<group>"; };
5E5DE5EE2718D02800C79175 /* MemojiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemojiView.swift; sourceTree = "<group>"; };
5E5DE5F02718D02900C79175 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5E5DE5F32718D02900C79175 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
5E5DE5FA271A189F00C79175 /* MemojiModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemojiModel.swift; sourceTree = "<group>"; };
5E5DE5FC271A1A4400C79175 /* MemojiViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemojiViewModel.swift; sourceTree = "<group>"; };
5E5DE5FE2720CAC200C79175 /* Grid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = "<group>"; };
Expand All @@ -57,6 +57,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5E1B2DD52C1191680006DD19 /* Preview Content */ = {
isa = PBXGroup;
children = (
5E1B2DD62C1656F60006DD19 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
5E5DE5E02718D02800C79175 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -86,19 +94,11 @@
path = Memojis;
sourceTree = "<group>";
};
5E5DE5F22718D02900C79175 /* Preview Content */ = {
isa = PBXGroup;
children = (
5E5DE5F32718D02900C79175 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
5E855A672BFBC24D006680F5 /* Sources */ = {
isa = PBXGroup;
children = (
5E5DE5F02718D02900C79175 /* Assets.xcassets */,
5E5DE5F22718D02900C79175 /* Preview Content */,
5E1B2DD52C1191680006DD19 /* Preview Content */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -189,7 +189,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5E5DE5F42718D02900C79175 /* Preview Assets.xcassets in Resources */,
5E1B2DD72C1656F60006DD19 /* Preview Assets.xcassets in Resources */,
5E5DE5F12718D02900C79175 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -357,7 +357,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.2;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -394,7 +394,7 @@
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 17.2;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
67 changes: 67 additions & 0 deletions Memojis.xcodeproj/xcshareddata/xcschemes/MemojisDoc.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
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 = "5E1B2DC62C0B8DBA0006DD19"
BuildableName = "MemojisDoc.framework"
BlueprintName = "MemojisDoc"
ReferencedContainer = "container:Memojis.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5E1B2DC62C0B8DBA0006DD19"
BuildableName = "MemojisDoc.framework"
BlueprintName = "MemojisDoc"
ReferencedContainer = "container:Memojis.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
28 changes: 15 additions & 13 deletions Memojis/Model/MemojiModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import Foundation
import SwiftUI

///```
///```swift
///
///struct MemojiModel<CardContent> where CardContent: Equatable
///
///```
struct MemojiModel<CardContent> where CardContent: Equatable {

Expand Down Expand Up @@ -45,7 +47,7 @@ struct MemojiModel<CardContent> where CardContent: Equatable {
createCardContent: (Int) -> CardContent) {

cards = []
/// add numberOfPairsOfCards * 2 cards to cards array
/// Add numberOfPairsOfCards * 2 cards to cards array
for pairIndex in 0..<numberOfPairsOfCards {
let content = createCardContent(pairIndex)
cards.append(Card(content: content, id: pairIndex * 2))
Expand Down Expand Up @@ -75,53 +77,53 @@ struct MemojiModel<CardContent> where CardContent: Equatable {

// MARK: - Bonus Time

/// this could give matching bonus points
/// This could give matching bonus points
/// if the user matches the card
/// before a certain amount of time passes during which the card is face up

/// can be zero which means "no bonus available" for this card
/// Can be zero which means "no bonus available" for this card
var bonusTimeLimit: TimeInterval = 6

/// how long this card has ever been face up
/// How long this card has ever been face up
public var faceUpTime: TimeInterval {
if let lastFaceUpDate {
return pastFaceUpTime + Date().timeIntervalSince(lastFaceUpDate)
} else {
return pastFaceUpTime
}
}
/// the last time this card was turned face up (and is still face up)
/// The last time this card was turned face up (and is still face up)
var lastFaceUpDate: Date?
/// the accumulated time this card has been face up in the past
/// The accumulated time this card has been face up in the past
/// (i.e. not including the current time it's been face up if it is currently so)
var pastFaceUpTime: TimeInterval = 0

/// how much time left before the bonus opportunity runs out
/// How much time left before the bonus opportunity runs out
var bonusTimeRemaining: TimeInterval {
max(0, bonusTimeLimit - faceUpTime)
}
/// percentage of the bonus time remaining
/// Percentage of the bonus time remaining
var bonusRemaining: Double {
(bonusTimeLimit > 0 && bonusTimeRemaining > 0)
? bonusTimeRemaining / bonusTimeLimit
: 0
}
/// whether the card was matched during the bonus time period
/// Whether the card was matched during the bonus time period
var hasEarnedBonus: Bool {
isMatched && bonusTimeRemaining > 0
}
/// whether we are currently face up, unmatched and have not yet used up the bonus window
/// Whether we are currently face up, unmatched and have not yet used up the bonus window
var isConsumingBonusTime: Bool {
isFaceUp && !isMatched && bonusTimeRemaining > 0
}

/// called when the card transitions to face up state
/// Called when the card transitions to face up state
public mutating func startUsingBonusTime() {
if isConsumingBonusTime, lastFaceUpDate == nil {
lastFaceUpDate = Date()
}
}
/// called when the card goes back face down (or gets matched)
/// Called when the card goes back face down (or gets matched)
public mutating func stopUsingBonusTime() {
pastFaceUpTime = faceUpTime
lastFaceUpDate = nil
Expand Down
46 changes: 21 additions & 25 deletions Memojis/View/MemojiView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

import SwiftUI

///```
///struct MemojiView: View
///
///var body: some View {
/// ZStack {
/// VStack {
/// game
/// HStack {
/// restart
/// shuffle
/// }
///```swift
///struct MemojiView: View {
/// var body: some View {
/// ZStack {
/// VStack {
/// game
/// HStack {
/// restart
/// shuffle
/// }
/// }
/// deck
/// }
/// deck
/// }
///}
///```
Expand Down Expand Up @@ -103,7 +103,7 @@ struct MemojiView: View {
.animation(.easeInOut(duration: 0.7).repeatForever(autoreverses: true), value: isAnimating)
.foregroundColor(Constants.color)
.onTapGesture {
/// "deal" cards
/// "Deal" cards
for card in model.cards {
withAnimation(dealAnimation(for: card)) {
deal(card)
Expand All @@ -130,9 +130,6 @@ struct MemojiView: View {
var restart: some View {
Button("Restart") {
withAnimation {
model.cards.forEach { card in
card.isMatched = false
}
deal = []
model.restart()
}
Expand All @@ -150,18 +147,17 @@ struct MemojiView: View {
static let undealtWidth = undealtHeight * aspectRatio
}
}

///
/// CardView contains card and animated state
///
///```
///struct CardView: View
///
///var body: some View {
/// ZStack {
/// Group {
/// Pie
/// card.content
///```swift
///struct CardView: View {
/// var body: some View {
/// ZStack {
/// Group {
/// Pie
/// card.content
/// }
/// }
/// }
///}
Expand Down
7 changes: 7 additions & 0 deletions Memojis/View/Pie.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import SwiftUI

///
/// - Parameter startAngle: Angle
/// - Parameter endAngle: Angle
/// - Parameter clockwise: Bool
///
struct Pie: Shape {

var startAngle: Angle
Expand All @@ -21,6 +26,8 @@ struct Pie: Shape {
}
}

/// - Parameter rect: CGRect
/// - Returns: `Path`
func path(in rect: CGRect) -> Path {
let center = CGPoint(x: rect.midX, y: rect.midY)
let radius = min (rect.width,rect.height) / 2
Expand Down
Loading

0 comments on commit a5530c8

Please sign in to comment.