Update(Tp1): Fonctionne

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

@ -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 = "<group>";
};
@ -62,6 +67,13 @@
path = DouShouQiConsole;
sourceTree = "<group>";
};
16CE03F42B57F58E00A85305 /* Frameworks */ = {
isa = PBXGroup;
children = (
);
name = Frameworks;
sourceTree = "<group>";
};
/* 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 */;
}

@ -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.")
}

@ -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"]),
]
)

@ -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()
}

@ -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"
}
}
}

@ -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
}
}

@ -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))"
}
}

@ -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"
}
}
}

@ -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"
}
}
}

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

Loading…
Cancel
Save