/// <summary> /// Check if the players are allowed to do another type of a limited round or the game has already passed /// </summary> /// <param name="round">Which round the game is currently on</param> /// <returns>True if round is legal, false if not</returns> public bool CheckRoundAvailability(RoundTypes round) { if (round == RoundTypes.Assess && currentRoundValue == roundValues[RoundTypes.Assess]) { if (assessRoundsComplete < 2) { return true; } else { return false; } } else if (round == RoundTypes.Escalate && currentRoundValue <= roundValues[RoundTypes.Escalate]) { if (escalationRoundsComplete == 0) { return true; } else { return false; } } else { return true; } }
private static string GetRoundName(RoundTypes round) { switch (round) { case RoundTypes.GROUP: break; case RoundTypes.KNOCKOUT_64: return("Knockout 64"); case RoundTypes.KNOCKOUT_32: return("Knockout 32"); case RoundTypes.KNOCKOUT_16: return("Knockout 16"); case RoundTypes.KNOCKOUT_8: return("Knockout 8"); case RoundTypes.QUATERFINALS: return("Quarterfinals"); case RoundTypes.SEMIFINALS: return("Semifinals"); case RoundTypes.FINALS: return("Finals"); } return("Unknown Ground"); }
/// <summary> /// Set the choice of the local player /// </summary> /// <param name="type">Which round type they are selecting</param> public void SetMyChoice(RoundTypes type) { myChoice = type; switch (type) { case RoundTypes.Assess: MultiplayerController.Instance.SendAssessRequest(); break; case RoundTypes.Escalate: MultiplayerController.Instance.SendEscalationRequest(); break; case RoundTypes.Fight: MultiplayerController.Instance.SendFightRequest(); break; case RoundTypes.RunAway: MultiplayerController.Instance.SendFleeRequest(); break; } //Setting the choices of players dependant on who is keeping track Debug.Log("Check track?????????????????????????????????????????????????????"); if (GameInfo.current.isKeepingTrack) { SetNames(); Debug.Log("Keeping track"); RoundInfo.current.userOneMiniGameChoice = type.ToString(); } else { RoundInfo.current.userTwoMiniGameChoice = type.ToString(); Debug.Log("Not Keeping track"); } CheckChoices(); }
private static void ReadGamesList(RoundTypes roundTypeFilter, IDataReader reader, List <TournamentGames> tournamentGamesList) { while (reader.Read()) { TournamentGames game = GetTournamentGameFromReader(reader); if (GameIsIncludedInFilter(roundTypeFilter, game)) { tournamentGamesList.Add(game); } } }
public Group[] GetListOfGroupsInTournament(int tournamentId, RoundTypes roundFilter) { Dictionary <string, object> parameters = new Dictionary <string, object> { { "@tournamentId", tournamentId } }; using (var cmd = CreateCommand("ListGroupsForTournament", parameters)) { Dictionary <int, Group> groups = new Dictionary <int, Group>(); using (var reader = cmd.ExecuteReader()) { List <Group> groupList = new List <Group>(); while (reader.Read()) { Group group = GetGroupFromReader(reader); if (!groups.ContainsKey(group.id) && IsGroupIncludedInFilter(group, roundFilter)) { Player player = new Player { id = (int)reader["PlayerId"], firstName = (string)reader["FirstName"], surname = (string)reader["Surname"] }; group.playersInGroup.Add(player); groups[group.id] = group; } else if (IsGroupIncludedInFilter(group, roundFilter)) { var existingGroup = groups[group.id]; Player player = new Player { id = (int)reader["PlayerId"], firstName = (string)reader["FirstName"], surname = (string)reader["Surname"] }; existingGroup.playersInGroup.Add(player); } } foreach (var group in groups) { groupList.Add(group.Value); } return(groupList.ToArray()); } } }
/// <summary> /// Called when the enemy's choice is received /// </summary> /// <param name="type"></param> public void SetEnemyChoice(RoundTypes type) { RoundInfo.current.PopulateFromGameInfo(); enemyChoice = type; //Setting the choices of players dependant on who is keeping track if (GameInfo.current.isKeepingTrack) { SetNames(); RoundInfo.current.userTwoMiniGameChoice = type.ToString(); } else { RoundInfo.current.userOneMiniGameChoice = type.ToString(); } CheckChoices(); }
private static Group CreateKnockoutGroup(RoundTypes round, IDataStore dataStore, int player1Id, int player2Id) { var group = new Group(); group.name = GetRoundName(round); group.roundId = (int)round; group.playersInGroup.Add(new Player() { id = player1Id }); group.playersInGroup.Add(new Player() { id = player2Id }); group.id = dataStore.CreateGroup(group); return(group); }
/// <summary> /// Whenever the player makes their choice or the enemy's choice is received /// Check to see if both choices are made and then take action /// </summary> void CheckChoices() { if (enemyChoice != RoundTypes.none && myChoice != RoundTypes.none) { //If either player is trying to run away, inform the other player and set them as the winner if (myChoice == RoundTypes.RunAway || enemyChoice == RoundTypes.RunAway) { roundsPlayed++; ResultsUI.instance.runAwayPanel.SetActive(true); if (myChoice == RoundTypes.RunAway) { ResultsUI.instance.runAwayPanelValue.text = "You have run away"; } else { ResultsUI.instance.runAwayPanelValue.text = "Your enemy has run away\n\nYou have won"; MiniGameTracker.instance.GiveXP(50); } GameInfo.current.SendToGameSparks(); } //If both choices match then load the correct scene else if (enemyChoice == myChoice) { roundsPlayed++; RoundInfo.current.miniGameOutcome = myChoice.ToString(); LoadMiniGame(); } //If the enemy's choice has a higher value than the local players choice then the local player will need to select again else if (roundValues[enemyChoice] > roundValues[myChoice]) { //Make user choose again Debug.Log("I Need to choose again"); myChoice = RoundTypes.none; ResultsUI.instance.enemyChosePanel.SetActive(true); ResultsUI.instance.enemyChoseValue.text = enemyChoice.ToString(); } //Likewise if the local players choice has a higher value than the enemy's choice, the enemy will need to choose again //They will have the same calculation on their device and will know so no information needs to be sent else if (roundValues[myChoice] > roundValues[enemyChoice]) { //Make enemy choose again Debug.Log("Enemy needs to choose again"); enemyChoice = RoundTypes.none; } } }
public TournamentGames[] GetTournamentGames(int tournamentId, RoundTypes roundTypeFilter = RoundTypes.ANY_TYPE) { Dictionary <string, object> parameters = new Dictionary <string, object> { { "@tournamentId", tournamentId } }; using (var cmd = CreateCommand("GetTournamentGames", parameters)) { using (var reader = cmd.ExecuteReader()) { List <TournamentGames> tournamentGamesList = new List <TournamentGames>(); ReadGamesList(roundTypeFilter, reader, tournamentGamesList); return(tournamentGamesList.ToArray()); } } }
private static bool GameIsIncludedInFilter(RoundTypes roundTypeFilter, TournamentGames game) { if ((RoundTypes)game.roundId == roundTypeFilter || roundTypeFilter == RoundTypes.ANY_TYPE) { return(true); } if (roundTypeFilter == RoundTypes.KNOCKOUT_ANY && ((RoundTypes)game.roundId == RoundTypes.KNOCKOUT_64 || (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_32 || (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_16 || (RoundTypes)game.roundId == RoundTypes.KNOCKOUT_8 || (RoundTypes)game.roundId == RoundTypes.QUATERFINALS || (RoundTypes)game.roundId == RoundTypes.SEMIFINALS || (RoundTypes)game.roundId == RoundTypes.FINALS)) { return(true); } return(false); }
/// <summary> /// Performed at the end of each round to update any necessary information /// </summary> /// <param name="round">Which type of round just ended</param> public void RoundOver(RoundTypes round) { //Update both players RHP switch (round) { case RoundTypes.Assess: assessRoundsComplete++; break; case RoundTypes.Escalate: escalationRoundsComplete++; break; case RoundTypes.Fight: EndGame(); break; case RoundTypes.RunAway: EndGame(); break; } }
/// <summary> /// Loads the appropriate minigame /// </summary> void LoadMiniGame() { Debug.Log("Loading the game: " + myChoice.ToString()); if (myChoice == RoundTypes.Assess) { UIManager.instance.GoToLevel("RoundOne"); Lizard.current.TakeAwayRHP(5); } if (myChoice == RoundTypes.Escalate) { UIManager.instance.GoToLevel("RoundTwo"); Lizard.current.TakeAwayRHP(10); } if (myChoice == RoundTypes.Fight) { UIManager.instance.GoToLevel("RoundThree"); Lizard.current.TakeAwayRHP(20); } enemyChoice = RoundTypes.none; myChoice = RoundTypes.none; }
private bool IsGroupIncludedInFilter(Group group, RoundTypes filter) { if (group.roundId == (int)filter) { return(true); } if (filter == RoundTypes.ANY_TYPE) { return(true); } if (filter == RoundTypes.KNOCKOUT_ANY && ( filter == RoundTypes.KNOCKOUT_64 || filter == RoundTypes.KNOCKOUT_32 || filter == RoundTypes.KNOCKOUT_16 || filter == RoundTypes.KNOCKOUT_8 || filter == RoundTypes.QUATERFINALS || filter == RoundTypes.SEMIFINALS || filter == RoundTypes.FINALS )) { return(true); } return(false); }
protected List <Group> CreateGroups(IDataStore datastore, Player[] tournamentPlayers, RoundTypes round) { List <Group> tournamentGroups = CreateTournamentGroupForPlayers(datastore, tournamentPlayers, round); AddPlayersToTournamentGroups(tournamentPlayers, tournamentGroups); return(tournamentGroups); }
private List <Group> CreateTournamentGroupForPlayers(IDataStore datastore, Player[] tournamentPlayers, RoundTypes round) { List <Group> tournamentGroups = new List <Group>(); int numberOfGroups = CalculateNumberOfGroups(tournamentPlayers); int name = 65; for (int i = 0; i < numberOfGroups; i++) { Group group = new Group(); group.name = "Group " + (char)(name + i); group.id = datastore.CreateGroup(group); group.roundId = (int)round; tournamentGroups.Add(group); } return(tournamentGroups); }
private static List <Game> GenerateRegularKnockoutStageRound(PlayerScore[] playerScores, Tournament tournament, RoundTypes round, IDataStore dataStore) { List <PlayerScore> scores = playerScores.ToList(); List <Game> games = new List <Game>(); for (int i = 0; i < scores.Count; i += 2) { int player1Id = scores[i].id; int player2Id = scores[i + 1].id; var group = CreateKnockoutGroup(round, dataStore, player1Id, player2Id); games.Add(new Game() { Group = group, Player1 = new Player() { id = player1Id }, Player2 = new Player() { id = player2Id }, Tournament = tournament }); } return(games); }
private static List <Game> GenerateFirstKnockoutStageRound(PlayerScore[] playerScores, Tournament tournament, RoundTypes round, IDataStore dataStore) { List <PlayerScore> scores = playerScores.ToList(); List <Game> games = new List <Game>(); while (scores.Count > 0) { for (int j = 1; j < scores.Count; j++) { if (PlayersAreInTheSameGroup(scores[0], scores[j])) { continue; } int player1Id = scores[0].id; int player2Id = scores[j].id; var group = CreateKnockoutGroup(round, dataStore, player1Id, player2Id); games.Add(new Game() { Group = group, Player1 = new Player() { id = player1Id }, Player2 = new Player() { id = player2Id }, Tournament = tournament }); scores.Remove(scores[j]); scores.Remove(scores[0]); } } return(games); }