public MainWindow() { InitializeComponent(); if (!File.Exists(fileName)) { game.Init(); } else { Stream stream = File.Open("Dodgeball.dat", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); game = (Games.Game)bf.Deserialize(stream); stream.Close(); } DataContext = this; //DispatcherTimer settings and Dispatcher start dispatcherTimer = new DispatcherTimer(); //adding event dispatcherTimer.Tick += new EventHandler(DispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 1500); dispatcherTimer.Start(); buttons.AddRange(new[] { SquareZero, SquareOne, SquareTwo, SquareThree, SquareFour, SquareFive, SquareSix, SquareSeven, SquareEight }); TamagotchiImage.Source = new BitmapImage(ImageUri); MissesText.Text = "Misses: " + game.Misses; HitsText.Text = "Hits: " + game.Points; }
public void Score(Ladder ladder, Games.Game game) { if (game.LadderScored.HasValue && game.LadderScored.Value) { throw new DomainException(ErrorCode.GameAlreadyScored, $"Game {game.Id} already scored"); } var playerStandings = new Dictionary <string, LadderStanding>(); var winningTeam = game.Teams.First(x => x.Players.First().Outcome == Enums.PlayerOutcome.Won); var otherTeams = game.Teams.Where(t => t != winningTeam); // Score winners var winningScoreTeam = new ScoreTeam(); TransformPlayers(ladder, playerStandings, winningTeam, winningScoreTeam); // Score losers var otherScoreTeams = new List <ScoreTeam>(); foreach (var otherTeam in otherTeams) { var otherScoreTeam = new ScoreTeam(); TransformPlayers(ladder, playerStandings, otherTeam, otherScoreTeam); otherScoreTeams.Add(otherScoreTeam); } // Calculate new ratings for each player var result = new Glicko2() .Calculate(winningScoreTeam, otherScoreTeams.ToArray()) .SelectMany(x => x.Players) .ToDictionary(x => x.Id); foreach (var user in game.Teams.SelectMany(t => t.Players.Select(x => x.User))) { var data = result[user.Id]; bool hasWon = winningTeam.Players.Any(x => x.UserId == user.Id); this.UpdatePlayerRating(ladder, playerStandings[user.Id], user, data.Rating, data.Vol, data.Rd, hasWon); } game.LadderScored = true; }
private async Task TicTacToeEndAsync() { await Context.Message.DeleteAsync(); if (GameHandler.DoesGameExist(Context.Guild.Id, GameType.TICTACTOE)) { Games.Game game = GameHandler.GetGame(Context.Guild.Id, GameType.TICTACTOE); if (game != null) { if (game.Players[0] == Context.User.Id || game.Players[1] == Context.User.Id || (Context.User as IGuildUser).GuildPermissions.Administrator) { IMessage msg = await Context.Channel.GetMessageAsync(game.RenderId); await msg.DeleteAsync(); string render = game.RenderGame(); await Context.Channel.SendFileAsync(render, $"**TicTacToe**\n" + $"Game Ended By " + Context.User.Mention); GameHandler.EndGame(game); } } else { await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...", false); return; } } else { await MessageUtil.SendErrorAsync((Context.Channel as ITextChannel), "TicTacToe Error", "No game could be found here...", false); return; } }
public Pather(Games.Game game) { this.game = game; }
public Pather(Games.Game game) { this.game = game; }