private void HighlightSelectedBalls(int x, int y, bool[,] visit) { int[] dx = { -1, 0, 1, 0 }; int[] dy = { 0, 1, 0, -1 }; visit[x, y] = true; var ball = CurrentField.GetBall(x, y); if (ball is OjamaBall) { return; } var color = ball.Color; ball.IsOnMouse = true; for (var i = 0; i < 4; ++i) { var tx = x + dx[i]; var ty = y + dy[i]; if (!CurrentField.IsInFieldRange(tx, ty) || visit[tx, ty] || CurrentField.GetBall(tx, ty).Color != color) { continue; } HighlightSelectedBalls(tx, ty, visit); } }
private void GameControlOnMouseLeftButtonUp( object sender, MouseButtonEventArgs mouseButtonEventArgs) { if (!IsRunning) { return; } var screenPoint = new Point(Cursor.Position.X, Cursor.Position.Y); var controlPoint = _gameControl.PointFromScreen(screenPoint); var ratioX = _camera.WorldWidth / _gameControl.ActualWidth; var ratioY = _camera.WorldHeight / _gameControl.ActualHeight; var worldPosition = new Vector2((float)(controlPoint.X * ratioX), (float)(controlPoint.Y * ratioY)); Microsoft.Xna.Framework.Point bordPos; if (!CurrentField.ToBordPointFromRenderPosition(worldPosition, out bordPos) || !CurrentField.IsInFieldRange(bordPos.X, bordPos.Y)) { return; } var gameConfig = CurrentField.GameConfig; var visit = new bool[gameConfig.Column + 1, gameConfig.Row + 1]; var tempCount = CurrentField.DfsDestroyableBalls(bordPos.X, bordPos.Y, visit); if (tempCount < gameConfig.MinChain) { return; } var ball = CurrentField.GetBall(bordPos.X, bordPos.Y); if (ball is OjamaBall) { return; } OutPut = bordPos; IsRunning = false; }
public override void Render(GameTime gameTime) { var scale = new Vector2(Camera.RatioX, Camera.RatioY) * 32.0f / _ojamaTexture.Width; var gameConfig = GameMain.GameConfig; for (var x = 1; x <= gameConfig.Column; ++x) { var ojamas = CurrentField.GetOjamasInQueue(x); var ball = CurrentField.GetBall(x, 1); var pos = Camera.ToRenderPosition(new Vector2(ball.X, 0.0f)); SpriteBatch.Draw(_ojamaTexture, pos, scale: scale * 0.8f, color: Color.Black); var ojamaCount = ojamas.Count(ojama => !ojama.IsHard); SpriteBatch.DrawString(_font, "x" + ojamaCount, pos, Color.White, 0.0f, Vector2.Zero, scale * 4.0f, SpriteEffects.None, 0.0f); pos.Y += _ojamaTexture.Height * scale.Y; var hardOjamaCount = ojamas.Count(ojama => ojama.IsHard); SpriteBatch.Draw(_hardOjamaTexture, pos, scale: scale * 0.8f, color: Color.Black); SpriteBatch.DrawString(_font, "x" + hardOjamaCount, pos, Color.White, 0.0f, Vector2.Zero, scale * 4.0f, SpriteEffects.None, 0.0f); } }