Exemplo n.º 1
0
        public Player(Game game, Team team, String name, int number, TacticalPosition tacticalPosition, Side side, int defense, int goalkeeping, int offense,
            int shot, int speed, int stamina, float x, float y)
            : base(game)
        {
            this.Team = team;
            this.Name = name;
            this.number = number;
            this.TacticalPosition = tacticalPosition;
            this.Side = side;
            this.defense = defense;
            this.goalkeeping = goalkeeping;
            this.Offense = offense;
            this.Shot = shot;
            this.Speed = speed;
            this.stamina = stamina;

            if(this.TacticalPosition.Equals(TacticalPosition.goalkeeper))
                this.WalkingSpeed = 150;
            else this.WalkingSpeed = 250;

            speedFactor = WalkingSpeed;
            TopSpeedFactor = 1.8f;
            TopSpeed = (WalkingSpeed * TopSpeedFactor) * (speed / 100f);    //gets the player's max (initial) running speed from his speed stat

            FreePassForce = 0.0f;
            PassForce = 0.0f;
            FreeKick = false;

            HasBall = false;
            running = false; IsAnimated = false; IsPressedAnimation = false;
            Numb = false;
            NumbTime = 500f;
            timer = 0f;

            ReflexTimer = 0f;
            ReflexTime = (float)(500.0f - (goalkeeping * 250.0f / 100.0f)); //250 valor min; 500 valor max;

            //set the initial position and acceleration
            Reset(x, y);
        }
Exemplo n.º 2
0
        public Match(Game game, Team homeTeam, Team awayTeam, CameraType cameraType, Difficulty difficulty, Weather weather, int duration, bool player2Cpu)
            : base(game)
        {
            CameraType = cameraType;
            Difficulty = difficulty;
            Weather = weather;
            Duration = duration;

            HomeTeam = homeTeam;
            AwayTeam = awayTeam;
            AwayTeam.IsHomeTeam = false;
            Player1Index = 0;
            Player2Index = 0;
            Player2Cpu = player2Cpu;

            Scenario = new Scenario2D(Game);
            Scenario2DPainter = new Scenario2DPainter(Game.GraphicsDevice, Scenario);
            timer = -1;
            Pause = false;
            DisplayRadar = true;
            hold = true;
            KickOff = true;
            KickOffStart = true;
            HomeTeamStart = true;
            FreeKickStart = false;
            TmpTeam = null;

            Ball = new Ball(game, Weather);
            Field = new Field(game);

            Panel = new Panel(game);
            //passing
            MaxPassSpeed = 800;
            MaxErrorAngle = 15;
            PerfectPassFactor = 2.8f;
            Rand = new Random();
            Audience = new Song[3];
        }
Exemplo n.º 3
0
        public void Parse(Game game, ArrayList teams /*, Scenario2DPainter scenario2DPainter */)
        {
            String line;
            Team team = null;   //current team

            if (File.Exists(filePath))
            {
                StreamReader file = null;
                try
                {
                    file = new StreamReader(filePath);
                    while ((line = file.ReadLine()) != null)
                    {
                        line = line.TrimStart(' '); //remove whitespaces from the start of the line
                        if (line.Equals("") || line.StartsWith("//"))    //ignore empty and comment lines
                            continue;
                        else if (line.StartsWith("T:")) //new team
                        {
                            String teamName = line.Substring(2).TrimStart(' ');
                            team = new Team(game, teamName, Color.White);

                            //add team to teams
                            teams.Add(team);
                        }
                        else if (line.StartsWith("C:"))
                        {
                            String color = line.Substring(2).TrimStart(' ');

                            byte r = byte.Parse(color.Substring(0, 3));
                            byte g = byte.Parse(color.Substring(3, 3));
                            byte b = byte.Parse(color.Substring(6, 3));

                            team.Color = new Color(r, g, b);
                        }
                        else if (line.StartsWith("P:")) //positioning
                        {
                            String teamStrategy = line.Substring(2).TrimStart(' ');
                            team.SetStrategy(teamStrategy);
                        }
                        else if (team != null)   //read players
                        {
                            String playerName = "", position = "", side = "";
                            int number, defense, goalkeeping, offense, shot, speed, stamina;
                            int extraWhiteSpaces = 0;

                            Player newPlayer = null;
                            String[] tokens = line.Split(' ');

                            int i = 0;  //in the end of the cycle it will be the index of the player number
                            double num;
                            //get player name
                            while (!double.TryParse(tokens[i], out num))    //while not a number
                            {
                                if (tokens[i].Equals(""))  //extra white space between player's names
                                {
                                    extraWhiteSpaces++;
                                    i++;
                                    continue;
                                }
                                if (i == 0) playerName += tokens[i];
                                else playerName += " " + tokens[i];
                                i++;
                            }
                            int j = i;
                            i -= extraWhiteSpaces;
                            while (j < tokens.Length)   //extra white space between the rest of the info
                            {
                                if (tokens[j].Equals(""))
                                {
                                    extraWhiteSpaces++;
                                }
                                j++;
                            }
                            //get player properties
                            if (tokens.Length - i == 9 + extraWhiteSpaces) //correct amount of info
                            {
                                //limit the skill level allowed
                                int maxSkill = 100;
                                try
                                {
                                    i += extraWhiteSpaces;
                                    number = int.Parse(tokens[i++]);
                                    position = tokens[i++];
                                    side = tokens[i++];
                                    defense = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);
                                    goalkeeping = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);
                                    offense = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);
                                    shot = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);
                                    speed = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);
                                    stamina = (int.Parse(tokens[i++]) > maxSkill) ? maxSkill : int.Parse(tokens[i - 1]);

                                    TacticalPosition position2 = TacticalPosition.goalkeeper;
                                    Side side2 = Side.center;

                                    if (position.Equals("defender")) position2 = TacticalPosition.defender;
                                    else if (position.Equals("dfmidfielder")) position2 = TacticalPosition.dfmidfielder;
                                    else if (position.Equals("midfielder")) position2 = TacticalPosition.midfielder;
                                    else if (position.Equals("ofmidfielder")) position2 = TacticalPosition.ofmidfielder;
                                    else if (position.Equals("striker")) position2 = TacticalPosition.striker;

                                    if (side.Equals("left")) side2 = Side.left;
                                    else if (side.Equals("right")) side2 = Side.right;

                                    //create new player
                                    newPlayer = new Player(game, team, playerName, number, position2, side2, defense, goalkeeping, offense, shot, speed, stamina /*scenario2DPainter*/, 0f, 0f);

                                    //insert player in team
                                    team.Players.Add(newPlayer);
                                }
                                catch (FormatException)
                                {
                                    Console.WriteLine("Wrong line format for player " + playerName + "!");
                                }
                            }
                            else Console.WriteLine("Incorrect amount of info in line: " + line);

                        }
                        Console.WriteLine(line);
                    }
                }
                finally
                {
                    if (file != null)
                        file.Close();
                }
            }
            else Console.WriteLine("Teams file not found!");
        }
Exemplo n.º 4
0
 public Player GetClosestPlayer(Team team, Player ignore)
 {
     int closest = 0;    //current closest
     float tempDist = float.MaxValue;
     float newDist = 0f;
     for (int i = 0; i < team.Players.Count; i++)
     {
         Player p = (Player)team.Players[i];
         if (p.Equals(ignore))
             continue;
         newDist = (float)Math.Sqrt(Math.Pow((p.Position.X - Position.X), 2) + Math.Pow((p.Position.Y - Position.Y), 2));
         if (newDist <= tempDist)
         {
             closest = i;
             tempDist = newDist;
         }
     }
     return (Player)team.Players[closest];
 }
Exemplo n.º 5
0
 public TeamAI(Game game, Team team)
     : base(game)
 {
     Team = team;
 }
Exemplo n.º 6
0
        public void UnloadContent()
        {
            Team = null;

            for (int i = 0; i != Players.Count; i++)
                Players[i] = null;

            Players.Clear();

            PlayerPassing = null;
        }