public async Task ExecuteGroupAsync(CommandContext ctx, [Description("Who to fight with?")] DiscordUser opponent) { if (this.Shared.IsEventRunningInChannel(ctx.Channel.Id)) throw new CommandFailedException("Another event is already running in the current channel!"); if (opponent.Id == ctx.User.Id) throw new CommandFailedException("You can't duel yourself..."); if (opponent.Id == ctx.Client.CurrentUser.Id) { await ctx.RespondAsync( $"{ctx.User.Mention} {string.Join("", Enumerable.Repeat(DiscordEmoji.FromName(ctx.Client, ":black_large_square:"), 5))} :crossed_swords: " + $"{string.Join("", Enumerable.Repeat(DiscordEmoji.FromName(ctx.Client, ":white_large_square:"), 5))} {opponent.Mention}" + $"\n{ctx.Client.CurrentUser.Mention} {DiscordEmoji.FromName(ctx.Client, ":zap:")} {ctx.User.Mention}" ); await this.InformAsync(ctx, StaticDiscordEmoji.DuelSwords, $"{ctx.Client.CurrentUser.Mention} wins!"); return; } var duel = new DuelGame(ctx.Client.GetInteractivity(), ctx.Channel, ctx.User, opponent); this.Shared.RegisterEventInChannel(duel, ctx.Channel.Id); try { await duel.RunAsync(); await this.InformAsync(ctx, StaticDiscordEmoji.DuelSwords, $"{duel.Winner.Username} {duel.FinishingMove ?? "wins"}!"); await this.Database.UpdateUserStatsAsync(duel.Winner.Id, GameStatsType.DuelsWon); await this.Database.UpdateUserStatsAsync(duel.Winner.Id == ctx.User.Id ? opponent.Id : ctx.User.Id, GameStatsType.DuelsLost); } finally { this.Shared.UnregisterEventInChannel(ctx.Channel.Id); } }
public DualModePage(gameMode[] modeSels) : base() { // layout definition InitializeComponent(); p1mode = modeSels[0]; p2mode = modeSels[1]; // game grid definition outerGrid.Width = Styles.WindowSizeGenerator.screenWidth; outerGrid.Height = Styles.WindowSizeGenerator.screenHeight; ColumnDefinition aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualGameModuleRight, GridUnitType.Pixel); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualAdditionModuleWidth, GridUnitType.Star); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); outerGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(Styles.WindowSizeGenerator.dualGameModuleRight, GridUnitType.Pixel); outerGrid.ColumnDefinitions.Add(aCol); Border border1 = new Border(); border1.BorderBrush = new SolidColorBrush(Colors.Gray); border1.BorderThickness = new Thickness(2, 2, 2, 2); Border border2 = new Border(); border2.BorderBrush = new SolidColorBrush(Colors.Gray); border2.BorderThickness = new Thickness(2, 2, 2, 2); games = t.NewDuelGame( p1mode.player == 1?"":PlayersName.getName(0), p2mode.player == 1?"":PlayersName.getName(1) ); int[] gridSize = new int[2] { games.Item1.Height, games.Item1.Width }; // game grid GameGrid gameGrid1 = new GameGrid(gridSize); border1.Child = gameGrid1; outerGrid.Children.Add(border1); border1.SetValue(Grid.RowProperty, 1); border1.SetValue(Grid.ColumnProperty, 1); GameGrid gameGrid2 = new GameGrid(gridSize); border2.Child = gameGrid2; outerGrid.Children.Add(border2); border2.SetValue(Grid.RowProperty, 1); border2.SetValue(Grid.ColumnProperty, 3); games.Item1.AddDisplay(gameGrid1); games.Item2.AddDisplay(gameGrid2); // set score board and next block board Grid scoreNextBlockGrid = new Grid(); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); aCol = new ColumnDefinition(); aCol.Width = new GridLength(1, GridUnitType.Star); scoreNextBlockGrid.ColumnDefinitions.Add(aCol); RowDefinition aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(Styles.WindowSizeGenerator.screenHeight / 30, GridUnitType.Pixel); scoreNextBlockGrid.RowDefinitions.Add(aRow); aRow = new RowDefinition(); aRow.Height = new GridLength(1, GridUnitType.Auto); scoreNextBlockGrid.RowDefinitions.Add(aRow); outerGrid.Children.Add(scoreNextBlockGrid); scoreNextBlockGrid.SetValue(Grid.ColumnProperty, 2); scoreNextBlockGrid.SetValue(Grid.RowProperty, 1); double scoreHeight = Styles.WindowSizeGenerator.scoreBoardHeight; double scoreWidth = Styles.WindowSizeGenerator.scoreBoardWidth; ScoreGrid score1 = new ScoreGrid(scoreHeight, scoreWidth); ScoreGrid score2 = new ScoreGrid(scoreHeight, scoreWidth); // set next block board double nextBlockHeight = Styles.WindowSizeGenerator.nextBoardHeight; double nextBlockWidth = Styles.WindowSizeGenerator.nextBoardWidth; NextBlock nextBlock1 = new NextBlock(nextBlockHeight, nextBlockWidth); NextBlock nextBlock2 = new NextBlock(nextBlockHeight, nextBlockWidth); scoreNextBlockGrid.Children.Add(nextBlock1); nextBlock1.SetValue(Grid.ColumnProperty, 1); nextBlock1.SetValue(Grid.RowProperty, 2); nextBlock1.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); nextBlock1.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); scoreNextBlockGrid.Children.Add(nextBlock2); nextBlock2.SetValue(Grid.ColumnProperty, 3); nextBlock2.SetValue(Grid.RowProperty, 2); nextBlock2.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); nextBlock2.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); games.Item1.AddDisplay(nextBlock1); games.Item2.AddDisplay(nextBlock2); scoreNextBlockGrid.Children.Add(score1); scoreNextBlockGrid.Children.Add(score2); score1.SetValue(Grid.ColumnProperty, 1); score1.SetValue(Grid.RowProperty, 0); score1.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); score1.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); score2.SetValue(Grid.ColumnProperty, 3); score2.SetValue(Grid.RowProperty, 0); score2.SetValue(Grid.HorizontalAlignmentProperty, HorizontalAlignment.Left); score2.SetValue(Grid.VerticalAlignmentProperty, VerticalAlignment.Top); score1.DataContext = games.Item1.ScoreSystem; score2.DataContext = games.Item2.ScoreSystem; // set background pictures. PicGen pic = new Cat3Gen(); double picSizeRatio = 1.1; PicGenGrid pg1 = new PicGenGrid(pic, SquareGenerator.picSquareSize / picSizeRatio); aCanvas.Children.Add(pg1); pg1.SetValue(Canvas.ZIndexProperty, 0); Canvas.SetLeft(pg1, (Styles.WindowSizeGenerator.screenWidth - pg1.getPicSize()[1] * SquareGenerator.picSquareSize / picSizeRatio) / 2); Canvas.SetBottom(pg1, Styles.WindowSizeGenerator.gameModuleTop + (-1 * pg1.getPicSize()[0] * SquareGenerator.picSquareSize / picSizeRatio) / 2.2); aRect1 = new Rectangle(); aRect1.Fill = new SolidColorBrush(Colors.Transparent); aRect1.Width = gameGrid1.getGameGridSize()[1]; aRect1.Height = gameGrid1.getGameGridSize()[0]; outerGrid.Children.Add(aRect1); aRect1.SetValue(Grid.ColumnProperty, 1); aRect1.SetValue(Grid.RowProperty, 1); //game.GameEndEvent += gameEnd; games.DuelGameEndEvent += gameEndEffect; // set the mask rect (used when game is over) aRect2 = new Rectangle(); aRect2.Fill = new SolidColorBrush(Colors.Transparent); aRect2.Width = gameGrid1.getGameGridSize()[1]; aRect2.Height = gameGrid1.getGameGridSize()[0]; outerGrid.Children.Add(aRect2); aRect2.SetValue(Grid.ColumnProperty, 3); aRect2.SetValue(Grid.RowProperty, 1); }