deux joueurs peuvent jouer, pas encore de règles

main
Mathis RIBEMONT 2 years ago
parent 0c6d2f80d3
commit 8bd0b38862

BIN
.DS_Store vendored

Binary file not shown.

@ -9,7 +9,7 @@ let package = Package(
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "model",
targets: ["model"]),
targets: ["model",]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.

@ -1,22 +0,0 @@
//
// File.swift
//
//
// Created by etudiant on 25/01/2023.
//
import Foundation
public class Lecteur {
init() {
}
public func lireInt() -> Int {
Int(readLine())
}
public func lireLigne() -> Int {
readLine()
}
}

@ -0,0 +1,18 @@
//
// File.swift
//
//
// Created by etudiant on 31/01/2023.
//
import Foundation
public class Afficheur {
public init() {
}
public func afficherLigne(message msg: String){
print(msg)
}
}

@ -0,0 +1,26 @@
//
// File.swift
//
//
// Created by etudiant on 31/01/2023.
//
import Foundation
public class Lecteur {
public init() {
}
public func lireInt() -> Int{
if let value = readLine() {
return Int(value) ?? -1
} else {
return -1
}
}
public func lireLigne() -> String? {
return readLine()
}
}

@ -11,14 +11,15 @@ public struct Game {
private var board: Board
private var players: [Player]
private var numero: Int = 0
private var afficheur: Afficheur
public init?(withBoard board: Board, playedBy players: [Player]) {
public init?(withBoard board: Board, playedBy players: [Player], writeOn afficheur: Afficheur) {
self.board = board
self.players = players
self.afficheur = afficheur
}
public init?(withGrid grid: [[Int?]], playedBy players: [Player]) {
public init?(withGrid grid: [[Int?]], playedBy players: [Player], writeOn afficheur: Afficheur) {
let b = Board(withGrid: grid)
guard b != nil else {
@ -28,9 +29,10 @@ public struct Game {
board = b!
self.players = players
self.afficheur = afficheur
}
public init?(withNbRow nbRow: Int = 6, withNbCol nbCol: Int = 7, playedBy players: [Player]) {
public init?(withNbRow nbRow: Int = 6, withNbCol nbCol: Int = 7, playedBy players: [Player], writeOn afficheur: Afficheur) {
let b = Board(nbR: nbRow, nbC: nbCol)
guard b != nil else {
@ -40,14 +42,22 @@ public struct Game {
board = b!
self.players = players
self.afficheur = afficheur
}
public mutating func tour() -> Player?{
let player = players[numero]
var result = BoardResult.unknown
while(result != BoardResult.ok ){
while( result != BoardResult.ok ){
afficheur.afficherLigne(message: "Joueur \(player.name), dans quelle colonne voulez-vous insérer un jeton ?")
result = board.insertPiece(id: numero + 1, column: player.playInColumn())
}
joueurSuivant();
afficheur.afficherLigne(message: board.description)
return nil
}
public mutating func joueurSuivant() {
numero = (numero + 1) % players.count
}
}

@ -0,0 +1,12 @@
//
// File.swift
//
//
// Created by etudiant on 31/01/2023.
//
import Foundation
public protocol Rule {
func executeRule() -> Bool
}

@ -24,6 +24,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
EC57C43C298974A700CD485F /* puissance4 */ = {isa = PBXFileReference; lastKnownFileType = folder; name = puissance4; path = ..; sourceTree = "<group>"; };
EC62D5D12976881000CAB764 /* puissance4 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = puissance4; sourceTree = BUILT_PRODUCTS_DIR; };
EC62D5D42976881000CAB764 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -40,9 +41,18 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
EC57C43B298974A700CD485F /* Packages */ = {
isa = PBXGroup;
children = (
EC57C43C298974A700CD485F /* puissance4 */,
);
name = Packages;
sourceTree = "<group>";
};
EC62D5C82976881000CAB764 = {
isa = PBXGroup;
children = (
EC57C43B298974A700CD485F /* Packages */,
EC62D5D32976881000CAB764 /* puissance4 */,
EC62D5D22976881000CAB764 /* Products */,
EC62D5DB2976889500CAB764 /* Frameworks */,

@ -21,14 +21,15 @@ import model
// b.removePiece(row: 1, column: 1)
// print(b.description)
var lecteur = Lecteur()
let lecteur = Lecteur()
let afficheur = Afficheur()
var b = Board()
if var board = b {
var player1 = Human(named: "Bingeamain", playedOn: board, readOn: lecteur)
var player2 = Human(named: "illohanne", playedOn: board, readOn: lecteur)
if let board = b {
let player1 = Human(named: "Bingeamain", playedOn: board, readOn: lecteur)
let player2 = Human(named: "illeauhanne", playedOn: board, readOn: lecteur)
var game = Game(withBoard: board, playedBy: [player1, player2])
var game = Game(withBoard: board, playedBy: [player1, player2], writeOn: afficheur)
while true {
game?.tour()

Loading…
Cancel
Save