async private void dispatcherTimer_Tick(object sender, EventArgs e) { if (isGameOver) { dispatcherTimer.Stop(); return; } else if (MyGrid.Children.Count == 2) //score for KOSTY { dispatcherTimer.Stop(); MessageBox.Show("You win !"); string scorestr = Convert.ToString(score_l); Temp = String.Concat("Your score = ", scorestr); BallRepository br = BallRepository.Initialize(); await Task.Run(() => { br.WriteResult(score_l); }); MessageBox.Show(Temp); return; } checkCollisions(); int ballColumn = Grid.GetColumn(Ball); Grid.SetColumn(Ball, ballColumn + dx); int ballRow = Grid.GetRow(Ball); Grid.SetRow(Ball, ballRow + dy); }
public ComponentManager(ContentManager contentManager, Microsoft.Xna.Framework.GraphicsDeviceManager graphicsDeviceManager) { _contentManager = contentManager; _resourceRepository = new ResourceRepository(new BasicResourceRepositoryConfiguration(), _contentManager); Font = _resourceRepository.GetFont(); _spaceShipTexture = _resourceRepository.GetTextureByType(typeof(SpaceShip)); var graphicsDevice = graphicsDeviceManager.GraphicsDevice; Configuration = new BasicGameConfiguration( _spaceShipTexture.Height, Font ); graphicsDeviceManager.PreferredBackBufferWidth = Configuration.ScreenSize.Width; graphicsDeviceManager.PreferredBackBufferHeight = Configuration.ScreenSize.Height; graphicsDeviceManager.ApplyChanges(); SpaceShip = new SpaceShip(Configuration, new Size(_spaceShipTexture.Width, _spaceShipTexture.Height)); _ballTexture = _resourceRepository.GetTextureByType(typeof(BasicBall)); BallRepository = new BallRepository(Configuration, new Size(_ballTexture.Width, _ballTexture.Height)); Balls = new List <IBall>(); _drawer = new ComponentDrawer(graphicsDevice, Font); Prizes = new List <IPrize>(); Shoots = new List <IShoot>(); MediaPlayer.Volume = .03f; }
async private void checkCollisions() { int userBlockColumn = Grid.GetColumn(UserBlock); int ballColumn = Grid.GetColumn(Ball); int ballRow = Grid.GetRow(Ball); if (ballRow == 21 && dy > 0) { if (userBlockColumn >= (ballColumn - 2) && userBlockColumn <= ballColumn) { dy = -dy; } else if ((userBlockColumn == (ballColumn - 3) && dx < 0) || (userBlockColumn == (ballColumn + 1) && dx > 0)) { dy = -dy; dx = -dx; } else //score for KOSTY { isGameOver = true; MessageBox.Show("Game over"); BallRepository br = BallRepository.Initialize(); await Task.Run(() => { br.WriteResult(score_l); }); string scorestr = Convert.ToString(score_l); Temp = String.Concat("Your score = ", scorestr); MessageBox.Show(Temp); return; } } if ((ballColumn == 0 && dx < 0) || (ballColumn == 23 && dx > 0)) { dx = -dx; } if (ballRow == 0 && dy < 0) { dy = -dy; } UIElement upDownBlock = MyGrid.Children.Cast <Rectangle>().Where(i => (Grid.GetRow(i) == ballRow + dy) && (Grid.GetColumn(i) == ballColumn)).FirstOrDefault(); if (upDownBlock != null) { dy = -dy; MyGrid.Children.Remove(upDownBlock); score_l = score_l + 1; } UIElement leftRightBlock = MyGrid.Children.Cast <Rectangle>().Where(i => (Grid.GetColumn(i) == ballColumn + dx) && (Grid.GetRow(i) == ballRow)).FirstOrDefault(); if (leftRightBlock != null) { dx = -dx; MyGrid.Children.Remove(leftRightBlock); score_l = score_l + 1; } UIElement skos = MyGrid.Children.Cast <Rectangle>().Where(i => (Grid.GetColumn(i) == ballColumn + dx) && (Grid.GetRow(i) == ballRow + dy)).FirstOrDefault(); if (skos != null) { dx = -dx; dy = -dy; MyGrid.Children.Remove(skos); score_l = score_l + 1; } }