TEST: check if we can make a solid iterable foundation for player moves

This commit is contained in:
Aldin Duraki 2020-05-15 16:31:27 +02:00
parent 92dd65a93f
commit 9fe149e594
3 changed files with 37 additions and 9 deletions

View File

@ -48,6 +48,9 @@ class TimerComponent: GKComponent {
if !MultiplayerNetwork.sharedInstance.isSending { if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves) MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
} }
if DataService.sharedInstance.didReceiveAllData() {
RoundCalculatorServie.sharedInstance.calculateRound()
}
} }
} }

View File

@ -29,14 +29,10 @@ class DataService {
func addRemotePlayerMoves(playerID: String, playerMoves: [PlayerMove]) { func addRemotePlayerMoves(playerID: String, playerMoves: [PlayerMove]) {
self.remotePlayerMoves[playerID] = playerMoves self.remotePlayerMoves[playerID] = playerMoves
}
//test func didReceiveAllData() -> Bool {
var size = self.remotePlayerMoves.count return remotePlayerMoves.count == MatchmakingHelper.sharedInstance.mpMatch?.players.count
if size == 1 {
for (key, value) in remotePlayerMoves {
print("\(key) : \(value)")
}
}
} }
func setGameHost(host: Host) { func setGameHost(host: Host) {

View File

@ -2,14 +2,43 @@
// RoundCalculatorService.swift // RoundCalculatorService.swift
// GoldWars // GoldWars
// //
// Created by student on 13.05.20. // Created by Aldin Duraki on 13.05.20.
// Copyright © 2020 SP2. All rights reserved. // Copyright © 2020 SP2. All rights reserved.
// //
import Foundation import Foundation
import GameKit
import os
class RoundCalculatorServie { class RoundCalculatorServie {
static let sharedInstance = RoundCalculatorServie()
var allPlayerMoves: [String: [PlayerMove]] = [:]
var baseSpecificMove: [Int: [(String, PlayerMove)]] = [:]
func calculateRound() {
for entry in DataService.sharedInstance.remotePlayerMoves {
addPlayerMove(playerID: entry.key, playerMoves: entry.value)
}
addPlayerMove(playerID: GKLocalPlayer.local.displayName, playerMoves: DataService.sharedInstance.localPlayerMoves)
// berechnen nach minimal substraction
for entry in allPlayerMoves {
for move in entry.value {
addFiltedMove(playerName: entry.key, playerMove: move)
}
}
print(baseSpecificMove)
// sende an alle anderen spieler die moves
}
func addPlayerMove(playerID: String, playerMoves: [PlayerMove]) {
self.allPlayerMoves[playerID] = playerMoves
}
func addFiltedMove(playerName: String, playerMove: PlayerMove) {
self.baseSpecificMove[playerMove.toBase]!.append((playerName, playerMove))
}
} }