public void endGame() { userCount = 0; characterCount = 0; observer = new ConcreteSubject(); givenWord = ""; xpRate = 1; abilityXpRate = 1; lastAbilityUser = ""; playerList = new List <Player>(); lastWord = new WordPrototype("empty"); usedClone = false; target = new Adapter(); pointsColorAbstraction = new PointsColorRefinedAbstraction(); skinAbstraction = new SkinAbstraction(); facade = new Facade(); collection = new Collection(); iterator = collection.CreateIterator(); firstLevel = new FirstLevelWord(); secondLevel = new SecondLevelWord(); thirdLevel = new ThirdLevelWord(); h1 = new ReverseWordHandler(); h2 = new FullWordHandler(); h3 = new PartWordHandler(); h4 = new LengthWordHandler(); _stateContext = new StateContext(new WinterState()); chatroom = new Chatroom(); originator = new Originator(); caretaker = new Caretaker(); parametersGroup = new ParametersGroup(); }
public async Task CheckWord(string word, string username) { h1.SetSuccessor(h2); h2.SetSuccessor(h3); h3.SetSuccessor(h4); double chainPoints = h1.HandleRequest(word, givenWord); if (chainPoints >= 1) { parametersGroup.Accept(new ColorVisitor()); if (parametersGroup.getParameter(0).Opacity > 0.1) { parametersGroup.Accept(new OpacityVisitor()); parametersGroup.Accept(new FontSizeVisitor()); } Console.WriteLine("params"); Console.WriteLine("Color: " + parametersGroup.getParameter(0).Color); Console.WriteLine("Opacity: " + parametersGroup.getParameter(0).Opacity); Console.WriteLine("FontSize: " + parametersGroup.getParameter(0).FontSize); await Clients.All.SendAsync( "ReceiveWordStyle", Math.Round(parametersGroup.getParameter(0).Opacity, 2), Math.Round(parametersGroup.getParameter(0).FontSize, 2), parametersGroup.getParameter(0).Color); List <Player> playerListCopy = new List <Player>(); playerList.ForEach(delegate(Player player) { playerListCopy.Add((Player)player.Clone()); }); originator.State = playerListCopy; caretaker.Memento = originator.CreateMemento(); } if (chainPoints < 1) { for (int i = 0; i < playerList.Count; i++) { if (playerList[i].username == username) { playerList[i].points = playerList[i].points + Convert.ToInt32(10 * chainPoints); } } await Clients.All.SendAsync("ReceiveAllUsernames", playerList); } else { await Clients.Caller.SendAsync("GetWinMessage", lastAbilityUser); await Clients.Others.SendAsync("GetLoseMessage"); await Clients.All.SendAsync("SeasonState", _stateContext.State.GetType().Name); _stateContext.Request(); Singleton.Instance.EndTime = DateTime.Now; await Clients.All.SendAsync("ReceiveTimer", Singleton.Instance.Difference()); for (int i = 0; i < playerList.Count; i++) { playerList[i].receivedEmoji = ""; playerList[i].receivedFrom = ""; if (playerList[i].username == username) { WinnerLoser winnerLoser = new WinnerLoser(playerList[i]); winnerLoser.SetWinner(); playerList[i].points = playerList[i].points + Convert.ToInt32(10 * chainPoints) + abilityXpRate * xpRate * playerList[i].characterKoeficient; Console.WriteLine("CheckWord abilityXPRate " + abilityXpRate); } else { WinnerLoser winnerLoser = new WinnerLoser(playerList[i]); winnerLoser.SetLoser(); } if (playerList[i].talisman != null) { Console.WriteLine("Suveike vartotojo talismanas"); int points = playerList[i].talisman.ActivateTalisman(); playerList[i].points += points; Console.WriteLine("Pridedama: " + playerList[i].username + " talismano tasku: " + points); } if (playerList[i].points >= 100) { await Clients.All.SendAsync("RedirectToLobby", playerList[i].username); endGame(); return; } } if (abilityXpRate != 1) { lastAbilityUser = ""; abilityXpRate = 1; Console.WriteLine("CheckWord abilityXPRate =1"); } if (observer.SubjectState == 4) { playerList = facade.ChangeToSecondLevel(playerList); foreach (var player in playerList) { player.permissionProxy.giveShopPermission(); } } if (observer.SubjectState == 9) { playerList = facade.ChangeToThirdLevel(playerList); } await Clients.All.SendAsync("ReceiveAllUsernames", playerList); if (usedClone) { givenWord = lastWord.word; usedClone = false; } else { iterator.Step = 1; givenWord = iterator.Next().word; } Console.WriteLine("Last word: " + lastWord.word); Console.WriteLine("Game word: " + givenWord); WordPrototype gameWord = new WordPrototype(givenWord); lastWord = (WordPrototype)gameWord.Clone(); await Clients.All.SendAsync("ReceiveCountdown", 5, givenWord); observer.SubjectState++; observer.Notify(); await Clients.All.SendAsync("GetGameRound", observer.SubjectState); } }