コード例 #1
0
ファイル: Unit.cs プロジェクト: sergeyzalunin/blazor-pacman
        public async Task <BrowserDimension> GetBrowserDimensionAsync()
        {
            BrowserDimension window;

            try
            {
                window = await Service.GetDimensions();
            }
            catch             //TODO: Try to find better way to handle this
            {
                window = new BrowserDimension();
            }
            return(window);
        }
コード例 #2
0
ファイル: Unit.cs プロジェクト: sergeyzalunin/blazor-pacman
        public virtual async void Move(Position coordinates, Looking direction)
        {
            var currentLeft = coordinates.Left;
            var currentTop  = coordinates.Top;

            if (direction == Looking.Left)
            {
                coordinates.Top  = currentTop;
                coordinates.Left = Math.Max(currentLeft - this.Velocity, 0);
            }
            else
            {
                if (direction == Looking.Up)
                {
                    coordinates.Top  = Math.Max(currentTop - this.Velocity, this.TopScoreBoard);
                    coordinates.Left = currentLeft;
                }
                else
                {
                    BrowserDimension window = await GetBrowserDimensionAsync();

                    if (direction == Looking.Right)
                    {
                        coordinates.Top  = currentTop;
                        coordinates.Left = Math.Min(currentLeft + this.Velocity, window.Width - this.Size - this.Border);
                    }
                    else
                    {
                        coordinates.Top  = Math.Min(currentTop + this.Velocity, window.Height - this.Size - this.Border);
                        coordinates.Left = currentLeft;
                    }
                }
            }

            StateHasChanging();
        }