Update(Tp1): Fonctionne

pull/1/head
Louis DUFOUR 2 years ago
parent 4aef44cec5
commit 051e68e176

@ -8,6 +8,8 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
167C5A152B57F0BC006FB682 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 167C5A142B57F0BC006FB682 /* main.swift */; }; 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 */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
@ -32,6 +34,8 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
16CE03F82B57F59200A85305 /* Model in Frameworks */,
16CE03F62B57F58E00A85305 /* Extension in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -43,6 +47,7 @@
children = ( children = (
167C5A132B57F0BC006FB682 /* DouShouQiConsole */, 167C5A132B57F0BC006FB682 /* DouShouQiConsole */,
167C5A122B57F0BC006FB682 /* Products */, 167C5A122B57F0BC006FB682 /* Products */,
16CE03F42B57F58E00A85305 /* Frameworks */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
@ -62,6 +67,13 @@
path = DouShouQiConsole; path = DouShouQiConsole;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
16CE03F42B57F58E00A85305 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
@ -78,6 +90,10 @@
dependencies = ( dependencies = (
); );
name = DouShouQiConsole; name = DouShouQiConsole;
packageProductDependencies = (
16CE03F52B57F58E00A85305 /* Extension */,
16CE03F72B57F59200A85305 /* Model */,
);
productName = DouShouQiConsole; productName = DouShouQiConsole;
productReference = 167C5A112B57F0BC006FB682 /* DouShouQiConsole */; productReference = 167C5A112B57F0BC006FB682 /* DouShouQiConsole */;
productType = "com.apple.product-type.tool"; productType = "com.apple.product-type.tool";
@ -280,6 +296,17 @@
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* 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 */; rootObject = 167C5A092B57F0BC006FB682 /* Project object */;
} }

@ -58,7 +58,7 @@ let initialBoardConfiguration: [[Cell]] = [
if let board = Board(withGrid: initialBoardConfiguration) { if let board = Board(withGrid: initialBoardConfiguration) {
// Afficher le plateau de jeu // Afficher le plateau de jeu
print(board.dispaly()) print(board.display())
} else { } else {
print("Erreur lors de l'initialisation du plateau de jeu.") print("Erreur lors de l'initialisation du plateau de jeu.")
} }

@ -14,15 +14,16 @@ let package = Package(
dependencies: [ dependencies: [
// Dependencies declare other packages that this package depends on. // Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"), // .package(url: /* package url */, from: "1.0.0"),
.package(path: "../Model"),
], ],
targets: [ targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite. // 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. // Targets can depend on other targets in this package, and on products in packages this package depends on.
.target( .target(
name: "Extension", name: "Extension",
dependencies: []), dependencies: ["Model"]),
.testTarget( .testTarget(
name: "ExtensionTests", name: "ExtensionTests",
dependencies: ["Extension"]), dependencies: ["Extension", "Model"]),
] ]
) )

@ -8,14 +8,17 @@
import Foundation import Foundation
import Model import Model
public extension Board { public extension Board {
func display() { func display() {
for row in grid { for row in grid {
for cell in row { for cell in row {
if let _ = cell.piece{ if let piece = cell.piece {
print(cell.display(), terminator: " ")}
else{ print(cell.cellType.symbol + piece.owner.symbol + piece.animal.symbol, terminator: " ")}
print(cell.display(), terminator: " ")} else {
print(cell.cellType.symbol, terminator: " ")}
} }
print() print()
} }

@ -7,5 +7,30 @@
import Foundation 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"
}
}
}

@ -28,5 +28,17 @@ public struct Board {
} }
return grid[row][column] 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
}
} }

@ -9,21 +9,23 @@ import Foundation
public struct Cell { public struct Cell {
public let cellType: CellType public let cellType: CellType
public let initialOwner: Owner public var initialOwner: Owner
public var piece: Piece? 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.cellType = cellType
self.initialOwner = initialOwner self.initialOwner = initialOwner
self.piece = piece self.piece = piece
} }
public var Cell { public var description: String {
func display() -> String { var pieceDescription = "nil"
let cellSymbol = self.cellType.symbol if let piece = piece {
let pieceSymbol = self.piece?.display() ?? " " pieceDescription = piece.description
return "\(cellSymbol)\(pieceSymbol)" }
} return "Cell(type: (cellType), owner: (initialOwner), piece: (pieceDescription))"
} }
} }

@ -9,4 +9,20 @@ import Foundation
public enum CellType { public enum CellType {
case unknown, jungle, water, trap, den 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"
}
}
} }

@ -9,5 +9,17 @@ import Foundation
public enum Owner { public enum Owner {
case noOne, player1, player2 case noOne, player1, player2
public var description: String {
switch self {
case .player1:
return "1"
case .player2:
return "2"
case .noOne:
return "x"
}
}
} }

@ -17,6 +17,6 @@ public struct Piece {
} }
public var description: String { public var description: String {
return "[\(owner):\(animal)]" return "[(owner):(animal)]"
} }
} }

Loading…
Cancel
Save