Skip to content

Commit

Permalink
Merge pull request #10 from contimatteo/feature/report
Browse files Browse the repository at this point in the history
Feature/report
  • Loading branch information
contimatteo authored Feb 4, 2020
2 parents 3146331 + 6268786 commit 6224b87
Show file tree
Hide file tree
Showing 22 changed files with 293 additions and 206 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Controllers/GameController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class GameController: UIViewController {

private func render() {
// STEP 0: render buttons and dialogs.
DispatchQueue.main.async {
DispatchQueue.main.async {
self.startGameButton.isHidden = !self.gameHandler.gameEnded;
if (self.gameHandler.gameEnded) {
self.gameStatusLabel.text = "pronto per iniziare ?";
Expand Down
35 changes: 18 additions & 17 deletions Briscola-Multiplayer/Controllers/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MenuController: UIViewController {
@IBOutlet weak var gameSpeed: UISlider!
@IBOutlet weak var showRemotePlayerCardsSwitcher: UISwitch!
@IBOutlet weak var showRemotePlayerPointsSwitcher: UISwitch!
@IBOutlet weak var showLocalPlayerPoints: UISwitch!
@IBOutlet weak var startGameButton: UIButton!

//
Expand All @@ -50,22 +51,22 @@ class MenuController: UIViewController {

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
switch segue.identifier {
case "startTheGame":
let gameController: GameController = segue.destination as! GameController;
self.gameOptions!.localPlayerName = localPlayerName.text!;
self.gameOptions!.mode = self.gameMode.selectedSegmentIndex == 0 ? .singleplayer : .multiplayer;
self.gameOptions!.gameSpeed = CONSTANTS.TURN_SECONDS_DELAY - (Double(self.gameSpeed.value) * 0.5);
self.gameOptions!.showRemotePlayerCards = showRemotePlayerCardsSwitcher.isOn;
self.gameOptions!.showRemotePlayerPoints = showRemotePlayerPointsSwitcher.isOn;
self.gameOptions!.showLocalPlayerPoints = true;
gameController.gameOptions = self.gameOptions!;
break;
default:
// nothing to do ...
// let socialsController = segue.destination as? SocialController;
print("[INFO] segue.identifier = \(segue.identifier ?? "?????")")
case "startTheGame":
let gameController: GameController = segue.destination as! GameController;

self.gameOptions!.localPlayerName = localPlayerName.text!;
self.gameOptions!.mode = self.gameMode.selectedSegmentIndex == 0 ? .singleplayer : .multiplayer;
self.gameOptions!.gameSpeed = CONSTANTS.TURN_SECONDS_DELAY - (Double(self.gameSpeed.value) * 0.5);
self.gameOptions!.showRemotePlayerCards = showRemotePlayerCardsSwitcher.isOn;
self.gameOptions!.showRemotePlayerPoints = showRemotePlayerPointsSwitcher.isOn;
self.gameOptions!.showLocalPlayerPoints = showLocalPlayerPoints.isOn;

gameController.gameOptions = self.gameOptions!;
break;
default:
// nothing to do ...
// let socialsController = segue.destination as? SocialController;
print("[INFO] segue.identifier = \(segue.identifier ?? "?????")")
}
}

Expand All @@ -79,7 +80,7 @@ class MenuController: UIViewController {
startGameButton.isEnabled = true;
}
}

}


Expand Down
2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Controllers/ResultsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ResultsController: UIViewController {
//
// MARK: exposed variables

public var gameInstance: GameHandler!;
var gameInstance: GameHandler!;

//
// MARK: variables
Expand Down
2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Controllers/SocialController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension SocialController {

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DatabaseMatchRecord") as! DatabseResultViewCell;

let currentMatch = dbMatchesRecords[indexPath.row];
cell.localPlayerNameLabel.text = String(describing: currentMatch.localPlayer.name);
cell.remotePlayerNameLabel.text = String(describing: currentMatch.remotePlayer.name);
Expand Down
2 changes: 0 additions & 2 deletions Briscola-Multiplayer/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
})
return container
}()



//
// MARK:
Expand Down
20 changes: 10 additions & 10 deletions Briscola-Multiplayer/Delegates/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}

func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
}

func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}

func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}

func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}

func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}


}

2 changes: 1 addition & 1 deletion Briscola-Multiplayer/Libraries/AI-PlayerEmulator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AIPlayerEmulator {
//
// MARK:

public func playCard(playerIndex: Int, playersHands: Array<Array<CardModel>>, cardsOnTable: Array<CardModel?>) -> Int {
func playCard(playerIndex: Int, playersHands: Array<Array<CardModel>>, cardsOnTable: Array<CardModel?>) -> Int {
var cardToPlay: Int?;
var classifToFind: CardClassification;
let currentPlayerHand = playersHands[playerIndex];
Expand Down
4 changes: 2 additions & 2 deletions Briscola-Multiplayer/Libraries/DatabaseHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DatabaseHandler {
// MARK: Public Methods


public func getMatches() -> [DB_Match] {
func getMatches() -> [DB_Match] {
let request = NSFetchRequest<NSFetchRequestResult>(entityName: MATCH_TABLE_NAME);
request.returnsObjectsAsFaults = false
// request.predicate = NSPredicate(format: "age = %@", "12")
Expand All @@ -75,7 +75,7 @@ class DatabaseHandler {
return results;
}

public func saveMatch(_ match: DB_Match) {
func saveMatch(_ match: DB_Match) {
let context = container.viewContext;

let entity = NSEntityDescription.entity(forEntityName: MATCH_TABLE_NAME, in: context)
Expand Down
8 changes: 4 additions & 4 deletions Briscola-Multiplayer/Libraries/FacebookManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class FacebookManager {
//
// MARK

public func login(from: UIViewController, didCompleteHandler: LoginManagerLoginResultBlock!) {
func login(from: UIViewController, didCompleteHandler: LoginManagerLoginResultBlock!) {
// self.loginManager.logIn(permissions: self.permissions, from: from, handler: handler);
if (AccessToken.current != nil) { return; }

Expand All @@ -48,7 +48,7 @@ class FacebookManager {
}
}

public func logout() {
func logout() {
self.loginManager.logOut()
self.removeCurrentUserData()
}
Expand All @@ -73,14 +73,14 @@ class FacebookManager {
});
}

public func getUserProfileUrl() -> String? {
func getUserProfileUrl() -> String? {
guard let userProfile = self.currentUserProfile else { return nil; }
let userId = userProfile["id"] as! String;

return "https://graph.facebook.com/\(userId)/picture?type=large";
}

public func shareTextOnFaceBook(controller: SocialController, match: DB_Match) {
func shareTextOnFaceBook(controller: SocialController, match: DB_Match) {
let shareContent = ShareLinkContent()

// url
Expand Down
30 changes: 15 additions & 15 deletions Briscola-Multiplayer/Libraries/GameHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
import Foundation


public class GameHandler {
class GameHandler {
//
// MARK: Variables
private var mode: GameType = .singleplayer;
public var gameEnded: Bool = true;
var gameEnded: Bool = true;

private var aiPlayerEmulator: AIPlayerEmulator? = nil;

public var players: Array<PlayerModel> = [];
public var playerTurn: Int = 0;
public var initialCards: Array<CardModel> = [];
public var deckCards: Array<CardModel> = [];
public var cardsOnTable: Array<CardModel?> = [];
public var trumpCard: CardModel?;
var players: Array<PlayerModel> = [];
var playerTurn: Int = 0;
var initialCards: Array<CardModel> = [];
var deckCards: Array<CardModel> = [];
var cardsOnTable: Array<CardModel?> = [];
var trumpCard: CardModel?;

//
// MARK: Public Methods

public func initSinglePlayer(numberOfPlayers: Int, localPlayerIndex: Int, playersName: [String]) {
func initSinglePlayer(numberOfPlayers: Int, localPlayerIndex: Int, playersName: [String]) {
self.mode = .singleplayer;
gameEnded = false;

Expand All @@ -44,7 +44,7 @@ public class GameHandler {
playersType.insert(.local, at: i);
} else {
playersType.insert(.emulator, at: i);

}
}
_initializePlayers(numberOfPlayers: numberOfPlayers, playersType: playersType, playersName: playersName);
Expand All @@ -61,7 +61,7 @@ public class GameHandler {
}
}

public func initMultiPlayer(numberOfPlayers: Int, localPlayerIndex: Int, playersType: [PlayerType], playersName: [String], deckCards: [CardModel]? = nil) {
func initMultiPlayer(numberOfPlayers: Int, localPlayerIndex: Int, playersType: [PlayerType], playersName: [String], deckCards: [CardModel]? = nil) {
self.mode = .multiplayer;
gameEnded = false;

Expand Down Expand Up @@ -93,7 +93,7 @@ public class GameHandler {
// }
}

public func playCard(playerIndex: Int, card: CardModel? = nil) -> Bool {
func playCard(playerIndex: Int, card: CardModel? = nil) -> Bool {
if (playerIndex != playerTurn || gameEnded) { return false; }

// HUMAN
Expand All @@ -111,7 +111,7 @@ public class GameHandler {
return true;
}

public func loadCards() -> Array<CardModel> {
func loadCards() -> Array<CardModel> {
var initialCards: Array<CardModel> = [];
var cards: Array<CardModel> = [];
let types: Array<CardType> = [.bastoni, .denari, .coppe, .spade];
Expand All @@ -134,11 +134,11 @@ public class GameHandler {
return cards;
}

public func nextTurn() {
func nextTurn() {
playerTurn = (playerTurn + 1) % players.count;
}

public func endTurn() {
func endTurn() {
// some player hasn't been played the card yet.
let isTurnReadyToEnd: Bool = cardsOnTable.first(where: {$0 == nil}) == nil;
if (!isTurnReadyToEnd) {
Expand Down
20 changes: 10 additions & 10 deletions Briscola-Multiplayer/Libraries/SessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ class SessionManager: NSObject {
// An object that implements the `SessionControllerDelegate` protocol
weak var delegate: SessionControllerDelegate?

public let peerID = MCPeerID(displayName: UIDevice.current.name)
let peerID = MCPeerID(displayName: UIDevice.current.name)

public lazy var session: MCSession = {
lazy var session: MCSession = {
let session = MCSession(peer: self.peerID)
session.delegate = self
return session
}()

public var serviceAdvertiser: MCNearbyServiceAdvertiser
public var serviceBrowser: MCNearbyServiceBrowser
var serviceAdvertiser: MCNearbyServiceAdvertiser
var serviceBrowser: MCNearbyServiceBrowser

// Connected peers are stored in the MCSession
// Manually track connecting and disconnected peers
public var connectingPeersDictionary = NSMutableDictionary()
public var disconnectedPeersDictionary = NSMutableDictionary()
var connectingPeersDictionary = NSMutableDictionary()
var disconnectedPeersDictionary = NSMutableDictionary()

//
// MARK: Initializer
Expand Down Expand Up @@ -82,15 +82,15 @@ class SessionManager: NSObject {
//
// MARK: Services start / stop

public func startServices() {
func startServices() {
serviceBrowser.delegate = self
serviceBrowser.startBrowsingForPeers()

serviceAdvertiser.delegate = self
serviceAdvertiser.startAdvertisingPeer()
}

public func stopServices() {
func stopServices() {
serviceAdvertiser.stopAdvertisingPeer()
serviceAdvertiser.delegate = nil

Expand All @@ -112,14 +112,14 @@ class SessionManager: NSObject {
return false;
}

public func sendData(data: [Any]) -> Bool {
func sendData(data: [Any]) -> Bool {
if (session.connectedPeers.count < 1) { return false; }
guard let data = UtilityHelper.arrayToData(data) else { return false; }

return send(data);
}

public func sendData(data: Data) -> Bool {
func sendData(data: Data) -> Bool {
if (session.connectedPeers.count < 1) { return false; }

return send(data);
Expand Down
20 changes: 10 additions & 10 deletions Briscola-Multiplayer/Models/Card.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
import Foundation
import UIKit

public class CardModel: Equatable {
class CardModel: Equatable {

//
// MARK: Protocol Adapters

public static func == (lhs: CardModel, rhs: CardModel) -> Bool {
static func == (lhs: CardModel, rhs: CardModel) -> Bool {
return lhs.number == rhs.number && lhs.type == rhs.type;
}

//
// MARK: Variables

public var name: String;
public var type: CardType;
public var tag: Int = 0;
var name: String;
var type: CardType;
var tag: Int = 0;

public var number: Int;
public var points: Int;
public var imageUrl: String;
public var image: UIImage;
var number: Int;
var points: Int;
var imageUrl: String;
var image: UIImage;

public var hasPoints: Bool { get { return points > 0; } }
var hasPoints: Bool { get { return points > 0; } }

//
// MARK: Initialzers
Expand Down
Loading

0 comments on commit 6224b87

Please sign in to comment.