private void ShootThreadMethod(object param) { Ball ball = param as Ball; ball.State = BallState.Shootted; if (ball.Owner != null && ball.Owner.Equals(this)) { if (ShootAccuracyPoints > 0 && ShootAccuracyPoints < 50) { double yFinishPos = r.Next(300, 398); double xFinishPos = Type.ToString().Contains("Away") ? 10 : 1030; while ((ball.Position.X > 20 && Type.ToString().Contains("Away")) || (Type.ToString().Contains("Home") && ball.Position.X != 1030) && ball.State == BallState.Shootted) { ball.State = BallState.Shootted; double xPos = Type.ToString().Contains("Home") ? ShootPowerPoints / 15 + ball.Position.X : -ShootPowerPoints / 15 + ball.Position.X; double yPos = CoordinateConverter.CalculateYIncrementator(Position, new Point(xFinishPos, yFinishPos), xPos); ball.Position = new Point(xPos, yPos); } } if (ShootAccuracyPoints > 50 && ShootAccuracyPoints < 70) { double yFinishPos = r.Next(260, 430); double xFinishPos = Type.ToString().Contains("Away") ? 10 : 1030; while ((ball.Position.X > 20 && Type.ToString().Contains("Away")) || (Type.ToString().Contains("Home") && ball.Position.X != 1030) && ball.State == BallState.Shootted) { ball.State = BallState.Shootted; double xPos = Type.ToString().Contains("Home") ? ShootPowerPoints / 15 + ball.Position.X: -ShootPowerPoints / 15 + ball.Position.X; double yPos = CoordinateConverter.CalculateYIncrementator(Position, new Point(xFinishPos, yFinishPos), xPos); ball.Position = new Point(xPos, yPos); } } if (ShootAccuracyPoints > 70 && ShootAccuracyPoints < 100) { double yFinishPos = r.Next(233, 466); double xFinishPos = Type.ToString().Contains("Away") ? 10 : 1030; while ((ball.Position.X > 20 && Type.ToString().Contains("Away") && ball.State == BallState.Shootted) || ((Type.ToString().Contains("Home") && ball.Position.X < 1015) && ball.State == BallState.Shootted)) { ball.State = BallState.Shootted; double xPos = Type.ToString().Contains("Home") ? ShootPowerPoints / 15 + ball.Position.X: -ShootPowerPoints / 15 + ball.Position.X; double yPos = CoordinateConverter.CalculateYIncrementator(Position, new Point(xFinishPos, yFinishPos), xPos); ball.Position = new Point(xPos, yPos); } } } ; State = PlayerState.Free; }
private void PassThreadMethod(object param) { Tuple <Ball, Player> tuple = param as Tuple <Ball, Player>; //double proportion = ((Double)Math.Abs(GameEngine.CurrentGame.Ball.Position.X - tuple.Item2.Position.X) == 0 ? 1 : (Double)Math.Abs(GameEngine.CurrentGame.Ball.Position.X - tuple.Item2.Position.X)) // / ((Double)Math.Abs(GameEngine.CurrentGame.Ball.Position.Y - tuple.Item2.Position.Y) == 0 ? 1 : (Double)Math.Abs(GameEngine.CurrentGame.Ball.Position.Y - tuple.Item2.Position.Y)); //double xIncrementer = proportion > 1 ? 5*proportion : 5; //double yIncrementer = proportion > 1 ? 5 : 5 * proportion; tuple.Item1.State = BallState.Passed; double xPos = 0; double yPos = 0; if (tuple.Item1.Owner != null && tuple.Item1.Owner.Equals(this)) { while (!tuple.Item1.IsCanPick(tuple.Item2.Position)) { if (Math.Abs(tuple.Item2.Position.X - xPos) >= 3) { xPos = tuple.Item2.Position.X > tuple.Item1.Position.X ? 3 + tuple.Item1.Position.X : -3 + tuple.Item1.Position.X; } if (Math.Abs(tuple.Item2.Position.Y - yPos) >= 3) { yPos = CoordinateConverter.CalculateYIncrementator(Position, tuple.Item2.Position, xPos); } tuple.Item1.Position = new Point(xPos, yPos); } if (Type.ToString().Contains("Home")) { tuple.Item1.Owner = tuple.Item2; tuple.Item2.IsSelected = true; this.IsSelected = false; tuple.Item1.State = BallState.Controlled; } else { tuple.Item1.Owner = tuple.Item2; tuple.Item1.State = BallState.Controlled; } } ; State = PlayerState.Free; }