Ejemplo n.º 1
0
        private async Task ResetMap()
        {
            MapResetCount++;

            var match = await _administrationService.GetMatchAsync(Game.GameId);

            _mapWidth = match.Map.Width;

            var cellViewModels = new List <CellViewModel>();

            for (int i = 0; i < match.Map.Rows.Count; i++)
            {
                for (int j = 0; j < match.Map.Rows[i].Length; j++)
                {
                    cellViewModels.Add(new CellViewModel
                    {
                        X        = j,
                        Y        = i,
                        State    = Convert.ToString(match.Map.Rows[i][j]),
                        CellSize = 20,
                    });
                }
            }

            CellCollection = new ObservableCollection <CellViewModel>(cellViewModels);

            var playerCollection = new ObservableCollection <PlayerStateViewModel>();

            for (int i = 0; i < Game.PlayerCollection.Count; i++)
            {
                playerCollection.Add(new PlayerStateViewModel
                {
                    ColorId   = i,
                    Condition = match.PlayerStates[i].Condition,
                    Player    = Game.PlayerCollection[i]
                });
            }

            PlayerCollection = playerCollection;

            CanvasWidth  = match.Map.Width * 20;
            CanvasHeight = match.Map.Height * 20;
        }
        private async Task ResetMap()
        {
            MapResetCount++;

            var match = await _administrationService.GetMatchAsync(Game.GameId);

            _mapWidth = match.Map.Width;


            // Map background & cookies
            var geoWalls  = new GeometryGroup();
            var dwCookies = new DrawingGroup();

            _cookieSprites = new Dictionary <Point, CookieSprite>();

            for (int i = 0; i < match.Map.Rows.Count; i++)
            {
                for (int j = 0; j < match.Map.Rows[i].Length; j++)
                {
                    switch (match.Map.Rows[i][j])
                    {
                    case '#':
                        geoWalls.Children.Add(new RectangleGeometry(new System.Windows.Rect(j, i, 1, 1)));
                        break;

                    case '.':
                        var cookie = new CookieSprite(j, i);
                        dwCookies.Children.Add(cookie.SpriteDrawing);
                        _cookieSprites[new Point(j, i)] = cookie;
                        break;
                    }
                }
            }

            var dwWalls = new GeometryDrawing(Brushes.Blue, null, geoWalls);

            // Tecman
            _tecmanSprite = new TecmanSprite(match.Map.TecmanPosition);

            // Ghosts
            _ghostSprites = match.Map.GhostPositions.Select((p, i) => new GhostSprite(p, i)).ToArray();

            var bgDrawing = new DrawingGroup();

            bgDrawing.Children.Add(dwWalls);
            bgDrawing.Children.Add(dwCookies);
            bgDrawing.Children.Add(_tecmanSprite.SpriteDrawing);
            foreach (GhostSprite ghost in _ghostSprites)
            {
                bgDrawing.Children.Add(ghost.SpriteDrawing);
            }

            var bgImage = new DrawingImage(bgDrawing);

            BackgroundImage = bgImage;


            // Player stats

            var playerCollection = new ObservableCollection <PlayerStateViewModel>();

            for (int i = 0; i < Game.PlayerCollection.Count; i++)
            {
                playerCollection.Add(new PlayerStateViewModel
                {
                    ColorId   = i,
                    Condition = match.PlayerStates[i].Condition,
                    Player    = Game.PlayerCollection[i],
                    Score     = match.PlayerStates[i].Score
                });
            }

            PlayerCollection = playerCollection;
        }