Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/game results #5

Merged
merged 7 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions Briscola-Multiplayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
2A02042C23CA142C00D7F469 /* PersistentContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A02042B23CA142C00D7F469 /* PersistentContainer.swift */; };
2A02043323CA14C300D7F469 /* GameDatabase.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2A02043123CA14C300D7F469 /* GameDatabase.xcdatamodeld */; };
2A02043523CA197000D7F469 /* DatabaseHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A02043423CA197000D7F469 /* DatabaseHandler.swift */; };
2A0203EB23CA0F1A00D7F469 /* Player.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 2A0203E923CA0F1A00D7F469 /* Player.xcdatamodeld */; };
2A15020923DB3558000A5886 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A15020823DB3558000A5886 /* Types.swift */; };
2A15020B23DB3F41000A5886 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A15020A23DB3F41000A5886 /* Extensions.swift */; };
2A15020D23DB3F5B000A5886 /* Protocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A15020C23DB3F5B000A5886 /* Protocols.swift */; };
2A15020F23DB4744000A5886 /* SessionObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A15020E23DB4744000A5886 /* SessionObjects.swift */; };
2A2CB76123D6E2BA009E4C51 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2CB76023D6E2BA009E4C51 /* Utilities.swift */; };
2A2CDAC223D206300050F840 /* FacebookManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A2CDAC123D206300050F840 /* FacebookManager.swift */; };
2A3D8FA223B9417A00B40C1D /* AI-PlayerEmulator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A3D8FA123B9417A00B40C1D /* AI-PlayerEmulator.swift */; };
2AA65A4323DE60F40059547B /* SocialController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA65A4223DE60F40059547B /* SocialController.swift */; };
2AA9C1B323B79DA400B3E4A4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA9C1B223B79DA400B3E4A4 /* AppDelegate.swift */; };
2AA9C1B523B79DA400B3E4A4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA9C1B423B79DA400B3E4A4 /* SceneDelegate.swift */; };
2AA9C1BA23B79DA400B3E4A4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2AA9C1B823B79DA400B3E4A4 /* Main.storyboard */; };
Expand All @@ -33,7 +33,6 @@
2AA9F59B23D3626B00AE69B4 /* SessionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA9F59A23D3626B00AE69B4 /* SessionManager.swift */; };
2AA9F59D23D363AF00AE69B4 /* GameController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA9F59C23D363AF00AE69B4 /* GameController.swift */; };
2AFAFA5223C3D83C00F186EE /* ResultsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFAFA5123C3D83C00F186EE /* ResultsController.swift */; };
2AFAFA5423C3D8AD00F186EE /* SocialsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFAFA5323C3D8AD00F186EE /* SocialsController.swift */; };
2AFAFA5623C3D8CB00F186EE /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFAFA5523C3D8CB00F186EE /* NavigationController.swift */; };
2AFAFA5823C3DE2700F186EE /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AFAFA5723C3DE2700F186EE /* MenuController.swift */; };
88E0A91621DC02CD48DD7A87 /* Pods_Briscola_Multiplayer_Briscola_MultiplayerUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88AA94EBE5798D378EA6C4BB /* Pods_Briscola_Multiplayer_Briscola_MultiplayerUITests.framework */; };
Expand Down Expand Up @@ -65,14 +64,14 @@
2A02042B23CA142C00D7F469 /* PersistentContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistentContainer.swift; sourceTree = "<group>"; };
2A02043223CA14C300D7F469 /* GameDatabase.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = GameDatabase.xcdatamodel; sourceTree = "<group>"; };
2A02043423CA197000D7F469 /* DatabaseHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseHandler.swift; sourceTree = "<group>"; };
2A0203EA23CA0F1A00D7F469 /* Player.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Player.xcdatamodel; sourceTree = "<group>"; };
2A15020823DB3558000A5886 /* Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
2A15020A23DB3F41000A5886 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
2A15020C23DB3F5B000A5886 /* Protocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Protocols.swift; sourceTree = "<group>"; };
2A15020E23DB4744000A5886 /* SessionObjects.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionObjects.swift; sourceTree = "<group>"; };
2A2CB76023D6E2BA009E4C51 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
2A2CDAC123D206300050F840 /* FacebookManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FacebookManager.swift; sourceTree = "<group>"; };
2A3D8FA123B9417A00B40C1D /* AI-PlayerEmulator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AI-PlayerEmulator.swift"; sourceTree = "<group>"; };
2AA65A4223DE60F40059547B /* SocialController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialController.swift; sourceTree = "<group>"; };
2AA9C1AF23B79DA400B3E4A4 /* Briscola-Multiplayer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Briscola-Multiplayer.app"; sourceTree = BUILT_PRODUCTS_DIR; };
2AA9C1B223B79DA400B3E4A4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2AA9C1B423B79DA400B3E4A4 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -93,7 +92,6 @@
2AA9F59A23D3626B00AE69B4 /* SessionManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionManager.swift; sourceTree = "<group>"; };
2AA9F59C23D363AF00AE69B4 /* GameController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameController.swift; sourceTree = "<group>"; };
2AFAFA5123C3D83C00F186EE /* ResultsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultsController.swift; sourceTree = "<group>"; };
2AFAFA5323C3D8AD00F186EE /* SocialsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialsController.swift; sourceTree = "<group>"; };
2AFAFA5523C3D8CB00F186EE /* NavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = "<group>"; };
2AFAFA5723C3DE2700F186EE /* MenuController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuController.swift; sourceTree = "<group>"; };
2BD14A3BF1FF1F988C1ACC2D /* Pods_Briscola_Multiplayer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Briscola_Multiplayer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -210,10 +208,10 @@
isa = PBXGroup;
children = (
2AFAFA5123C3D83C00F186EE /* ResultsController.swift */,
2AFAFA5323C3D8AD00F186EE /* SocialsController.swift */,
2AFAFA5523C3D8CB00F186EE /* NavigationController.swift */,
2AFAFA5723C3DE2700F186EE /* MenuController.swift */,
2AA9F59C23D363AF00AE69B4 /* GameController.swift */,
2AA65A4223DE60F40059547B /* SocialController.swift */,
);
path = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -524,12 +522,11 @@
buildActionMask = 2147483647;
files = (
2A02043323CA14C300D7F469 /* GameDatabase.xcdatamodeld in Sources */,
2AA9F59F23D3646F00AE69B4 /* SessionManagerDelegate.swift in Sources */,
2A02043523CA197000D7F469 /* DatabaseHandler.swift in Sources */,
2A02042C23CA142C00D7F469 /* PersistentContainer.swift in Sources */,
2A15020923DB3558000A5886 /* Types.swift in Sources */,
2A3D8FA223B9417A00B40C1D /* AI-PlayerEmulator.swift in Sources */,
2A0203EB23CA0F1A00D7F469 /* Player.xcdatamodeld in Sources */,
2A0203EB23CA0F1A00D7F469 /* (null) in Sources */,
2AA9F59B23D3626B00AE69B4 /* SessionManager.swift in Sources */,
2AA9C1EA23B7A3FD00B3E4A4 /* Card.swift in Sources */,
2AA9C1B323B79DA400B3E4A4 /* AppDelegate.swift in Sources */,
Expand All @@ -540,10 +537,10 @@
2AA9C1F523B7CED400B3E4A4 /* Player.swift in Sources */,
2AFAFA5623C3D8CB00F186EE /* NavigationController.swift in Sources */,
2A2CB76123D6E2BA009E4C51 /* Utilities.swift in Sources */,
2AFAFA5423C3D8AD00F186EE /* SocialsController.swift in Sources */,
2A15020D23DB3F5B000A5886 /* Protocols.swift in Sources */,
2AA9C1F023B7A4F300B3E4A4 /* GameHandler.swift in Sources */,
2A2CDAC223D206300050F840 /* FacebookManager.swift in Sources */,
2AA65A4323DE60F40059547B /* SocialController.swift in Sources */,
2A15020F23DB4744000A5886 /* SessionObjects.swift in Sources */,
2AFAFA5223C3D83C00F186EE /* ResultsController.swift in Sources */,
2AA9C1B523B79DA400B3E4A4 /* SceneDelegate.swift in Sources */,
Expand Down
37 changes: 25 additions & 12 deletions Briscola-Multiplayer/Controllers/GameController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GameController: UIViewController {

private var playersCardImgViews: Array<Array<UIImageView>> = [];
private var tableCardImgViews: Array<UIImageView> = [];
private var playersNamesLabels: Array<UILabel> = [];
private var playersPointsLabels: Array<UILabel> = [];

//
Expand Down Expand Up @@ -67,14 +68,15 @@ class GameController: UIViewController {

private func initSinglePlayerGame() {
// SINGLE-PLAYER
let playersTypes: [PlayerType] = [.local, .emulator];
var playersNames: [String] = [CONSTANTS.EMULATOR_PLAYER_NAME, CONSTANTS.EMULATOR_PLAYER_NAME];
playersNames[localPlayerIndex!] = gameOptions.localPlayerName;

// prepare player's cards variables.
prepareAssets();

// load all the cards and load 3 cards foreach player, load
// the trump card, create players and load 3 cards for these.
gameHandler.initSinglePlayer(numberOfPlayers: gameOptions.numberOfPlayers, localPlayerIndex: localPlayerIndex!, playersType: playersTypes);
gameHandler.initSinglePlayer(numberOfPlayers: gameOptions.numberOfPlayers, localPlayerIndex: localPlayerIndex!, playersName: playersNames);

// gestures
initGestures()
Expand All @@ -98,16 +100,20 @@ class GameController: UIViewController {

// SINGLE-PLAYER
localPlayerIndex = localPlayerNewIndex;

var playersTypes: [PlayerType] = [.remote, .remote];
playersTypes[localPlayerIndex!] = .local;

var playersNames: [String] = [CONSTANTS.REMOTE_PLAYER_NAME, CONSTANTS.REMOTE_PLAYER_NAME];
playersNames[localPlayerIndex!] = gameOptions.localPlayerName;

DispatchQueue.main.async {
// prepare player's cards variables.
self.prepareAssets();

// load all the cards and load 3 cards foreach player, load
// the trump card, create players and load 3 cards for these.
self.gameHandler.initMultiPlayer(numberOfPlayers: self.gameOptions.numberOfPlayers, localPlayerIndex: self.localPlayerIndex!, playersType: playersTypes, deckCards: deckCardsConverted);
self.gameHandler.initMultiPlayer(numberOfPlayers: self.gameOptions.numberOfPlayers, localPlayerIndex: self.localPlayerIndex!, playersType: playersTypes, playersName: playersNames, deckCards: deckCardsConverted);

// gestures
self.initGestures()
Expand All @@ -125,6 +131,8 @@ class GameController: UIViewController {
self.playersCardImgViews.append([]);
self.tableCardImgViews.append(UIImageView(image: nil));
self.tableCardImgViews.append(UIImageView(image: nil));
self.playersNamesLabels.append(UILabel());
self.playersNamesLabels.append(UILabel());
self.playersPointsLabels.append(UILabel());
self.playersPointsLabels.append(UILabel());

Expand All @@ -150,6 +158,8 @@ class GameController: UIViewController {

// player's points and name labels

self.playersNamesLabels[currentPlayerIndex] = self.lp_labelName;
self.playersNamesLabels[remotePlayer1Index] = self.rp1_labelName;
self.playersPointsLabels[currentPlayerIndex] = self.lp_LabelPoints;
self.playersPointsLabels[remotePlayer1Index] = self.rp1_LabelPoints;
}
Expand Down Expand Up @@ -217,6 +227,7 @@ class GameController: UIViewController {
// display points
DispatchQueue.main.async {
for (pIndex, player) in self.gameHandler.players.enumerated() {
self.playersNamesLabels[pIndex].text = String(player.name);
self.playersPointsLabels[pIndex].text = String(player.deckPoints);
}
}
Expand Down Expand Up @@ -266,7 +277,7 @@ class GameController: UIViewController {
if (!allRequiredPlayersAreConnected) { return; }

let sharedCardsDeck: [String] = (gameHandler.loadCards()).map { $0.name; };
let initObject: SS_InitObj = SS_InitObj(senderPlayerIndex: localPlayerIndex!, cardsDeck: sharedCardsDeck);
let initObject: SS_InitObj = SS_InitObj(senderPlayerIndex: localPlayerIndex!, cardsDeck: sharedCardsDeck, senderPlayerName: gameOptions.localPlayerName);

DispatchQueue.main.async {
let sended = self.sessionManager!.sendData(data: initObject.toData());
Expand All @@ -293,12 +304,17 @@ class GameController: UIViewController {
// MARK: Navigation

public func goToNextView() {
let nextController = ResultsController();

// setting properties of new controller
nextController.gameInstance = gameHandler;
self.performSegue(withIdentifier: "goToGameResultView", sender: self);
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let resultController = segue.destination as? ResultsController;

self.navigationController!.pushViewController(nextController, animated: true)
if resultController != nil {
if (segue.identifier == "goToGameResultView") {
resultController!.gameInstance = self.gameHandler;
}
}
}

}
Expand All @@ -308,9 +324,6 @@ class GameController: UIViewController {

extension GameController: SessionControllerDelegate {

//
// MARK: Triggers

func sessionDidChangeState() {
// Ensure UI updates occur on the main queue.
DispatchQueue.main.async {
Expand Down
6 changes: 3 additions & 3 deletions Briscola-Multiplayer/Controllers/MenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MenuController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

gameOptions = GameOptions(mode: .singleplayer, numberOfPlayers: 2, indexOfStarterPlayer: 0);
gameOptions = GameOptions(mode: .singleplayer, numberOfPlayers: 2, indexOfStarterPlayer: 0, localPlayerName: CONSTANTS.LOCAL_PLAYER_NAME);
}

//
Expand All @@ -32,7 +32,7 @@ class MenuController: UIViewController {
let gameController = segue.destination as? GameController;
if (gameController != nil) {
if (segue.identifier == "singlePlayerButton") {
self.gameOptions?.mode = .singleplayer
self.gameOptions?.mode = .singleplayer;
}

if (segue.identifier == "multiPlayerButton") {
Expand All @@ -42,7 +42,7 @@ class MenuController: UIViewController {
gameController!.gameOptions = self.gameOptions!;
}

let socialsController = segue.destination as? SocialsController;
let socialsController = segue.destination as? SocialController;
if (socialsController != nil) {}
}

Expand Down
10 changes: 1 addition & 9 deletions Briscola-Multiplayer/Controllers/NavigationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@
import Foundation
import UIKit

class NavigationController: UINavigationController{

override func viewDidLoad() {
super.viewDidLoad()

// let gameController = UIStoryboard.init(name: "GameViewController", bundle: Bundle.main).instantiateViewController(withIdentifier: "GameViewController") as? GameViewController
// self.navigationController?.pushViewController(gameController!, animated: true)
}
}
class NavigationController: UINavigationController {}
Loading