diff --git a/DouShouQiConsole/DouShouQiConsole.xcodeproj/project.pbxproj b/DouShouQiConsole/DouShouQiConsole.xcodeproj/project.pbxproj index 013f732..d8d7311 100644 --- a/DouShouQiConsole/DouShouQiConsole.xcodeproj/project.pbxproj +++ b/DouShouQiConsole/DouShouQiConsole.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 167C5A152B57F0BC006FB682 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 167C5A142B57F0BC006FB682 /* main.swift */; }; + 16CE03F62B57F58E00A85305 /* Extension in Frameworks */ = {isa = PBXBuildFile; productRef = 16CE03F52B57F58E00A85305 /* Extension */; }; + 16CE03F82B57F59200A85305 /* Model in Frameworks */ = {isa = PBXBuildFile; productRef = 16CE03F72B57F59200A85305 /* Model */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -32,6 +34,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 16CE03F82B57F59200A85305 /* Model in Frameworks */, + 16CE03F62B57F58E00A85305 /* Extension in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -43,6 +47,7 @@ children = ( 167C5A132B57F0BC006FB682 /* DouShouQiConsole */, 167C5A122B57F0BC006FB682 /* Products */, + 16CE03F42B57F58E00A85305 /* Frameworks */, ); sourceTree = ""; }; @@ -62,6 +67,13 @@ path = DouShouQiConsole; sourceTree = ""; }; + 16CE03F42B57F58E00A85305 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -78,6 +90,10 @@ dependencies = ( ); name = DouShouQiConsole; + packageProductDependencies = ( + 16CE03F52B57F58E00A85305 /* Extension */, + 16CE03F72B57F59200A85305 /* Model */, + ); productName = DouShouQiConsole; productReference = 167C5A112B57F0BC006FB682 /* DouShouQiConsole */; productType = "com.apple.product-type.tool"; @@ -280,6 +296,17 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 16CE03F52B57F58E00A85305 /* Extension */ = { + isa = XCSwiftPackageProductDependency; + productName = Extension; + }; + 16CE03F72B57F59200A85305 /* Model */ = { + isa = XCSwiftPackageProductDependency; + productName = Model; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 167C5A092B57F0BC006FB682 /* Project object */; } diff --git a/DouShouQiConsole/DouShouQiConsole/main.swift b/DouShouQiConsole/DouShouQiConsole/main.swift index f81fce8..40a5085 100644 --- a/DouShouQiConsole/DouShouQiConsole/main.swift +++ b/DouShouQiConsole/DouShouQiConsole/main.swift @@ -58,7 +58,7 @@ let initialBoardConfiguration: [[Cell]] = [ if let board = Board(withGrid: initialBoardConfiguration) { // Afficher le plateau de jeu - print(board.dispaly()) + print(board.display()) } else { print("Erreur lors de l'initialisation du plateau de jeu.") } diff --git a/Extension/Package.swift b/Extension/Package.swift index d9374c0..ffc8005 100644 --- a/Extension/Package.swift +++ b/Extension/Package.swift @@ -14,15 +14,16 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../Model"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "Extension", - dependencies: []), + dependencies: ["Model"]), .testTarget( name: "ExtensionTests", - dependencies: ["Extension"]), + dependencies: ["Extension", "Model"]), ] ) diff --git a/Extension/Sources/Extension/Board.swift b/Extension/Sources/Extension/Board.swift index e4042ef..818fd25 100644 --- a/Extension/Sources/Extension/Board.swift +++ b/Extension/Sources/Extension/Board.swift @@ -8,14 +8,17 @@ import Foundation import Model + public extension Board { func display() { for row in grid { for cell in row { - if let _ = cell.piece{ - print(cell.display(), terminator: " ")} - else{ - print(cell.display(), terminator: " ")} + if let piece = cell.piece { + + print(cell.cellType.symbol + piece.owner.symbol + piece.animal.symbol, terminator: " ")} + else { + + print(cell.cellType.symbol, terminator: " ")} } print() } diff --git a/Model/Sources/Model/Animal.swift b/Model/Sources/Model/Animal.swift index 543dff5..1869392 100644 --- a/Model/Sources/Model/Animal.swift +++ b/Model/Sources/Model/Animal.swift @@ -7,5 +7,30 @@ import Foundation -public enum Animal: String { case rat, cat, dog, wolf, leopard, tiger, lion, elephant } +public enum Animal: String { case rat, cat, dog, wolf, leopard, tiger, lion, elephant + + + + public var description: String { + switch self { + case .rat: + return "Rat" + case .cat: + return "Cat" + case .dog: + return "Dog" + case .wolf: + return "Wolf" + case .leopard: + return "Leopard" + case .tiger: + return "Tiger" + case .lion: + return "Lion" + case .elephant: + return "Elephant" + } + } +} + diff --git a/Model/Sources/Model/Board.swift b/Model/Sources/Model/Board.swift index b20ac86..3909a4b 100644 --- a/Model/Sources/Model/Board.swift +++ b/Model/Sources/Model/Board.swift @@ -28,5 +28,17 @@ public struct Board { } return grid[row][column] } + + public var description: String { + var boardDescription = "" + for row in grid { + for cell in row { + boardDescription += cell.description + " " + } + boardDescription += "\n" + } + return boardDescription + } } + diff --git a/Model/Sources/Model/Cell.swift b/Model/Sources/Model/Cell.swift index 8bf1075..5e0c616 100644 --- a/Model/Sources/Model/Cell.swift +++ b/Model/Sources/Model/Cell.swift @@ -9,21 +9,23 @@ import Foundation public struct Cell { public let cellType: CellType - public let initialOwner: Owner + public var initialOwner: Owner public var piece: Piece? - public init(ofType cellType: CellType, ownedBy initialOwner: Owner = .noOne, withPiece piece: Piece? = nil) { + public init(ofType cellType: CellType, ownedBy initialOwner: Owner = .noOne, withPiece piece: Piece? = nil) { self.cellType = cellType self.initialOwner = initialOwner self.piece = piece } - public var Cell { - func display() -> String { - let cellSymbol = self.cellType.symbol - let pieceSymbol = self.piece?.display() ?? " " - return "\(cellSymbol)\(pieceSymbol)" - } - } - + public var description: String { + var pieceDescription = "nil" + if let piece = piece { + pieceDescription = piece.description + } + return "Cell(type: (cellType), owner: (initialOwner), piece: (pieceDescription))" + } } + + + diff --git a/Model/Sources/Model/CellType.swift b/Model/Sources/Model/CellType.swift index 1430450..f59fc22 100644 --- a/Model/Sources/Model/CellType.swift +++ b/Model/Sources/Model/CellType.swift @@ -9,4 +9,20 @@ import Foundation public enum CellType { case unknown, jungle, water, trap, den + + public var description: String { + switch self { + case .unknown: + return "unknown cell" + case .jungle: + return "jungle cell" + case .water: + return "water cell" + case .trap: + return "trap cell" + case .den: + return "den cell" + } + } } + diff --git a/Model/Sources/Model/Owner.swift b/Model/Sources/Model/Owner.swift index 9a27739..7bd92d9 100644 --- a/Model/Sources/Model/Owner.swift +++ b/Model/Sources/Model/Owner.swift @@ -9,5 +9,17 @@ import Foundation public enum Owner { case noOne, player1, player2 + + public var description: String { + switch self { + case .player1: + return "1" + case .player2: + return "2" + case .noOne: + return "x" + } + } } + diff --git a/Model/Sources/Model/Piece.swift b/Model/Sources/Model/Piece.swift index 9ea8a75..1d6f8c4 100644 --- a/Model/Sources/Model/Piece.swift +++ b/Model/Sources/Model/Piece.swift @@ -17,6 +17,6 @@ public struct Piece { } public var description: String { - return "[\(owner):\(animal)]" - } + return "[(owner):(animal)]" + } }