Rookie FindNearestRookie() { Rookie[] allRookies = FindObjectsOfType <Rookie>(); if (allRookies.Length == 0) { return(null); } Rookie nearestRookie = allRookies[0]; float nearestDistance = Vector3.Distance(nearestRookie.transform.position, this.transform.position); foreach (Rookie rookie in allRookies) { if (!rookie.hasBall) { if (Vector3.Distance(rookie.transform.position, this.transform.position) < nearestDistance) { nearestRookie = rookie; nearestDistance = Vector3.Distance(nearestRookie.transform.position, this.transform.position); } } } if (nearestRookie.hasBall) { return(null); } return(nearestRookie); }
public void AddRookie(Rookie rookie) { var id = 1; if (_rookies.Count > 0) { id = _rookies.Last().Id + 1; } rookie.Id = id; _rookies.Add(rookie); using (var writer = File.AppendText(PathToRookiesFile)) { writer.WriteLine(rookie.Id); writer.WriteLine(rookie.Name); writer.WriteLine(rookie.Surname); writer.WriteLine(rookie.Patronymic); writer.WriteLine(rookie.BirthDate); writer.WriteLine(rookie.Character); writer.WriteLine(rookie.ParentAdress?.City); writer.WriteLine(rookie.ParentAdress?.Street); writer.WriteLine(rookie.ParentAdress?.NumberHouse); writer.WriteLine(rookie.ParentAdress?.NumberFlat); writer.WriteLine(rookie.Educational?.CivilProfession); writer.WriteLine(rookie.Educational?.Education); writer.WriteLine(rookie.Educational?.Rank); writer.WriteLine(rookie.Educational?.DataReceiveRank); } UpdaterRookieCount(_rookies.Count); }
void DetermineCorrectAction() { rookieTargeted = FindNearestRookie(); if (rookieTargeted != null) { state = State.Helping; } else { state = State.Attacking; } }
public void KillEnemyComponent() { Rookie rookieRef = transform.parent.GetComponentInParent<Rookie>(); if (rookieRef != null) { rookieRef.Kill(); } else { Trainer trainerRef = transform.parent.GetComponentInParent<Trainer>(); trainerRef.Kill(); } }
private void InitRookieAdding() { rookie = new Rookie(); rookie.BirthDate = birthData.MinDate; rookie.ParentAdress.NumberHouse = (int)HouseNumberNumeric.Minimum; rookie.ParentAdress.NumberFlat = (int)FlatNumberNumeric.Minimum; rookie.Educational.DataReceiveRank = RankReceivingDate.MinDate; type = SaveType; this.Text = "Додати новобранця"; SaveButton.Text = "Додати"; InitRookieTextBoxes(); }
private void InitRookieEditing(int id) { type = EditType; this.Text = "Редагувати новобранця"; SaveButton.Text = "Редагувати"; try { rookie = _commanderDirectory.GetRookie(id); InitRookieTextBoxes(); } catch (Exception e) { MessageBox.Show("Вибачте, сталася помилка", e.Message, MessageBoxButtons.OK); } }
void GiveBallToNearestRookie() { if (rookieTargeted != null) { transform.LookAt(rookieTargeted.transform); } if (hasBall) { if (rookieTargeted != null) { hasBall = false; timeBeforeNextBall = ballRecuperationCD; StartCoroutine(PassBall_C(rookieTargeted)); rookieTargeted = null; } } }
public static void Main(string[] args) { string[] RANDOMS = { "a", "b", "c" }; string[] A_BLOCKS = { "2", "4" }; Category category; string categoryInput = "AAA"; categoryInput = askForCategory(); switch (categoryInput.ToUpper()) { case "R": category = new Rookie(); break; case "A": category = new Intermediate(); break; case "AA": category = new DoubleA(); break; case "AAA": category = new Open(); break; default: return; } Console.WriteLine("Category: " + category.getName()); category.getFormations().ForEach(delegate(string form) { Console.Write(form); }); Console.WriteLine(""); Console.WriteLine("Draw:"); category.getDraw().ForEach(delegate(Jump jump) { Console.WriteLine("New jump:"); Console.Write(jump.printJump()); Console.WriteLine(""); }); }
IEnumerator PassBall_C(Rookie enemy) { Vector3 startPosition = hand.transform.position; Vector3 endPosition = enemy.hand.position; Vector3 enemyPosition = enemy.transform.position; enemyPosition.y = transform.position.y; //Rotate players towards target and play particles transform.rotation = Quaternion.LookRotation(enemyPosition - transform.position); float passTime = Vector3.Distance(startPosition, endPosition) / passSpeed; AnimationCurve speedCurve = GameManager.i.ballManager.passMovementCurve; AnimationCurve angleCurve = GameManager.i.ballManager.passAngleCurve; GameObject ball = Instantiate(ballPrefab); ball.transform.Find("Trail").GetComponent <TrailRenderer>().material = ballTrailMaterial; ball.transform.position = this.hand.position; Ball ballScript = ball.GetComponent <Ball>(); ballScript.SetState(BallMoveState.Moving); ballScript.defaultCollider.enabled = false; for (float i = 0; i < passTime; i += Time.deltaTime) { yield return(new WaitForEndOfFrame()); //Apply speed curve ball.transform.position = Vector3.Lerp(startPosition, enemy.hand.position, speedCurve.Evaluate(i / passTime)); //Apply angle curve ball.transform.position = new Vector3( ball.transform.position.x, ball.transform.position.y + (angleCurve.Evaluate(i / passTime) * passHeight), ball.transform.position.z ); } ball.transform.SetParent(enemy.hand, false); ball.transform.localPosition = Vector3.zero; enemy.hasBall = true; yield return(null); }
private void InitRookieLabels(Rookie rookie) { rookieId = rookie.Id; NameRookie.Text = rookie.Name; Surname.Text = rookie.Surname; Patronomic.Text = rookie.Patronymic; Age.Text = rookie.BirthDate.ToString(); Character.Text = rookie.Character; ParentAddressCity.Text = rookie.ParentAdress?.City ?? DefaultMissingValueLabel; ParentAddressStreet.Text = rookie.ParentAdress?.Street ?? DefaultMissingValueLabel; ParentAddressNumberFlat.Text = rookie.ParentAdress?.NumberFlat.ToString() ?? DefaultMissingValueLabel; ParentAddressNumberHouse.Text = rookie.ParentAdress?.NumberHouse.ToString() ?? DefaultMissingValueLabel; EducationalCivilProfession.Text = rookie.Educational?.CivilProfession ?? DefaultMissingValueLabel; EducationalEducation.Text = rookie.Educational?.Education ?? DefaultMissingValueLabel; EducationalRank.Text = rookie.Educational?.Rank ?? DefaultMissingValueLabel; EducationalDataReceiveRank.Text = rookie.Educational?.DataReceiveRank.ToShortDateString() ?? DefaultMissingValueLabel; }
public void LoadRookies() { _rookies = new List <Rookie>(); using (TextReader reader = new StreamReader(PathToRookiesFile)) { var n = Convert.ToInt32(reader.ReadLine()); while (n-- > 0) { var rookie = new Rookie() { Id = Convert.ToInt32(reader.ReadLine()), Name = reader.ReadLine(), Surname = reader.ReadLine(), Patronymic = reader.ReadLine(), BirthDate = DateTime.Parse(reader.ReadLine()), Character = reader.ReadLine(), }; rookie.ParentAdress = new Adress { City = reader.ReadLine(), Street = reader.ReadLine(), NumberHouse = Convert.ToInt32(reader.ReadLine()), NumberFlat = Convert.ToInt32(reader.ReadLine()) }; rookie.Educational = new Educational { CivilProfession = reader.ReadLine(), Education = reader.ReadLine(), Rank = reader.ReadLine(), DataReceiveRank = DateTime.Parse(reader.ReadLine()) }; _rookies.Add(rookie); } } }
public void UpdateRookie(int rookieId, Rookie rookieToUpdate) { Rookie rookie = null; try { rookie = _rookies.SingleOrDefault(s => s.Id == rookieId); if (rookie == null) { AddRookie(rookieToUpdate); throw new ComanderException( $"Жоден новобранець з айдішіком {rookieId} не був знайдений, тому був створений новий новобранець з айдішником {rookie.Id}."); } } catch (InvalidOperationException ex) { throw new ComanderException( $"Більш ніж один новобранець має аналогчний айдішник - {rookieId}. Видаліть зайвих новобранців з таким же айдішником чи виберіть іншого новобранця.", ex); } rookie.Name = rookieToUpdate.Name; rookie.Surname = rookieToUpdate.Surname; rookie.Patronymic = rookieToUpdate.Patronymic; rookie.BirthDate = rookieToUpdate.BirthDate; rookie.Character = rookieToUpdate.Character; if (rookie.ParentAdress == null) { rookie.ParentAdress = new Adress(); } rookie.ParentAdress.City = rookieToUpdate.ParentAdress.City; rookie.ParentAdress.Street = rookieToUpdate.ParentAdress.Street; rookie.ParentAdress.NumberHouse = rookieToUpdate.ParentAdress.NumberHouse; rookie.ParentAdress.NumberFlat = rookieToUpdate.ParentAdress.NumberFlat; if (rookie.Educational == null) { rookie.Educational = new Educational(); } rookie.Educational.CivilProfession = rookieToUpdate.Educational.CivilProfession; rookie.Educational.Education = rookieToUpdate.Educational.Education; rookie.Educational.Rank = rookieToUpdate.Educational.Rank; rookie.Educational.DataReceiveRank = rookieToUpdate.Educational.DataReceiveRank; var fileLines = File.ReadAllLines(PathToRookiesFile); if (fileLines == null || fileLines.Length <= 0) { throw new Exception("File is empty. Can not update rookie in file."); } for (int i = 1; i < fileLines.Length; i++) { if (string.Equals(fileLines[i], rookie.Id.ToString())) { fileLines[i + 1] = rookie.Name; fileLines[i + 2] = rookie.Surname; fileLines[i + 3] = rookie.Patronymic; fileLines[i + 4] = rookie.BirthDate.ToString(); fileLines[i + 5] = rookie.Character; fileLines[i + 6] = rookie.ParentAdress.City; fileLines[i + 7] = rookie.ParentAdress.Street; fileLines[i + 8] = rookie.ParentAdress.NumberHouse.ToString(); fileLines[i + 9] = rookie.ParentAdress.NumberFlat.ToString(); fileLines[i + 10] = rookie.Educational.CivilProfession; fileLines[i + 11] = rookie.Educational.Education; fileLines[i + 12] = rookie.Educational.Rank; fileLines[i + 13] = rookie.Educational.DataReceiveRank.ToString(); break; } } File.WriteAllLines(PathToRookiesFile, fileLines); }