public void Tournament(Users Players, Tournament card) { foreach (KeyValuePair <string, List <AdventureCard> > i in u_cards) { //adding total battle points in dictionary<username, totalbattlepoints> int totalBattlePoints = 0; totalBattlePoints = getTotalBattlePoints(i.Value); if (u_battlePoints.ContainsKey(i.Key)) { logger.warn("TournamentManager.cs :: Cards are already added in."); //Debug.Log ("already added in"); } else { u_battlePoints.Add(i.Key, totalBattlePoints); logger.warn("TournamentManager.cs :: adding cards to Player" + i.Key + " with Total Battle Points: " + totalBattlePoints); } } int maxValue = 0; string highestUser = ""; string tieUser = ""; //changing dictionary to list and sorting them from largest to smallest foreach (KeyValuePair <string, int> i in u_battlePoints) { Debug.Log("user name: " + i.Key + "and total value point: " + i.Value); if (i.Value > maxValue) { maxValue = i.Value; highestUser = i.Key; continue; } if (i.Value == maxValue) { tieBreaker = true; tieUser = i.Key; } } if (tieBreaker) { //Users tieBreaker = new Users (2, 0); logger.info("TournamentManagr.cs :: Tie between two players. No Winner. "); } winner = highestUser; }
//check for allies, tests, weapons, foes etc....... public void submitCardsQuest() { logger.info("SubmitCards.cs :: Checking the current submission of cards for a quest"); listOfStages = new List <List <AdventureCard> > (); //get num stages and stage objects test = false; Quest storycard = GameObject.FindGameObjectWithTag("StoryCard").GetComponent <Quest>(); int numStages = storycard.getStages(); GameObject[] stages = GameObject.FindGameObjectsWithTag("Stage"); //check each stage submit is correct for (int i = 0; i < numStages; i++) { logger.info("SubmitCards.cs :: Checking if stage " + i + " is eligible for submission"); //Debug.Log(stages[i].GetComponent<RectTransform>().position.x); <-----------Goes negative to positive bool foe = false; bool testCurrentStage = false; bool weapons = false; //make a list of children (cards) List <AdventureCard> cards = new List <AdventureCard>(); foreach (Transform j in stages[i].transform) { //if contains a weapon Debug.Log(j.gameObject.GetComponent <AdventureCard> ().getType()); if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Weapon") { //check if duplicates of weapons logger.info("SubmitCards.cs :: There is a " + j.gameObject.GetComponent <AdventureCard> ().getName() + " card"); weapons = true; if (sameName(j.gameObject.GetComponent <AdventureCard> ().getName(), cards)) { logger.warn("SubmitCards.cs :: There are weapons of the same name. This submission is not eligible"); return; } } //check if multiple tests in one stage and across all stages if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Test" && testCurrentStage == true) { logger.warn("SubmitCards.cs :: There are multiple 'Test' cards in this stage. This submission is not eligible"); return; } else if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Test" && test == true) { logger.warn("SubmitCards.cs :: There are multiple 'Test' cards among all stages. This submission is not eligible"); return; } else if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Test" && test == false) { test = true; testCurrentStage = true; logger.info("SubmitCards.cs :: There is a " + j.gameObject.GetComponent <AdventureCard> ().getName() + " card"); } //check if multiple foes are in single stage if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Foe" && foe == true) { logger.warn("SubmitCards.cs :: There are multiple 'Foe' cards in this stage. This submission is not eligible"); return; } else if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Foe" && foe == false) { logger.info("SubmitCards.cs :: There is a " + j.gameObject.GetComponent <AdventureCard> ().getName() + " card"); foe = true; } //if contains an ally then return if (j.gameObject.GetComponent <AdventureCard> ().getType() == "Ally") { logger.info("SubmitCards.cs :: This stage contains an 'Ally'. This submission is not eligible"); return; } cards.Add(j.gameObject.GetComponent <AdventureCard>()); logger.info("SubmitCards.cs :: Adding the card " + j.gameObject.GetComponent <AdventureCard> ().getName() + " to the current stage"); //Debug.Log (j.gameObject.GetComponent<AdventureCard>().getName()); } //return if both a foe and test are present or neither are present if (testCurrentStage && foe) { logger.warn("SubmitCards.cs :: This stage contains a 'Foe' and a 'Test' card. This submission is not elligible"); return; } else if (!testCurrentStage && !foe) { logger.warn("SubmitCards.cs :: This stage does not contain a 'Foe' or 'Test' card. This submission is not elligible"); return; } if (testCurrentStage && weapons) { logger.warn("SubmitCards.cs :: This stage contains a 'Test' and a 'Weapon' card. This submission is not eligible"); return; } logger.info("SubmitCards.cs :: Adding the current stage to the quest"); listOfStages.Insert(i, cards); } int[] bpps = new int[numStages]; for (int y = 0; y < numStages; y++) { bpps[y] = 0; } foreach (List <AdventureCard> k in listOfStages) { foreach (AdventureCard h in k) { logger.info("SubmitCards.cs :: Calculating battle points for the current stage"); if (h.getType() == "Test") { bpps [listOfStages.IndexOf(k)] = 0; logger.info("SubmitCards.cs :: This stage has a 'Test' and requires no battle points"); } else { if (h.getType() == "Weapon") { bpps [listOfStages.IndexOf(k)] += h.getBattlePoints(); } else if (h.getType() == "Foe") { if (storycard.getBonusFoe() == h.getName() || storycard.getBonusFoe() == "All") { logger.info("SubmitCards.cs :: the 'Foe' name and bonus foe of the 'Quest' match. Using the higher of the two battle points"); bpps [listOfStages.IndexOf(k)] += h.getBonusBattlePoints(); } else { bpps [listOfStages.IndexOf(k)] += h.getBattlePoints(); logger.info("SubmitCards.cs :: the 'Foe' '" + h.getName() + "' does not match the bonus foe of the 'Quest'. Using the lower of the two battle points"); } } } } Debug.Log("bpps = " + bpps[listOfStages.IndexOf(k)]); } for (int t = 1; t < numStages + 1; t++) { if (bpps[t - 1] != 0) { if (t < bpps.Length) { if (bpps[t - 1] > bpps[t]) { return; } } } } Debug.Log("adding stages"); foreach (List <AdventureCard> s in listOfStages) { foreach (AdventureCard a in s) { GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager> ().advDeck.GetComponent <AdventureDeck> ().adventureDeck.Add(a.getName()); } } GameObject.Find("QuestManager").GetComponent <QuestManager> ().setStages(listOfStages); foreach (GameObject k in stages) { Destroy(k); } GameObject.Find("QuestManager").GetComponent <QuestManager> ().setToggle(true); GameManager gm = GameObject.Find("GameManager").GetComponent <GameManager> (); gm.playerTurn++; if (gm.playerTurn > 3) { gm.playerTurn = 0; } gm.togglePlayerCanvas(gm.playerTurn); gm.questInProgress = true; Destroy(this.gameObject); //get cards attatched to each stage //create each respective stage (number to beat , or test) }