void Start() { //This is how you create a Dictionary. Notice how this takes //two generic terms. In this case you are using a string and a //BadGuy as your two values. Dictionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); //You can place variables into the Dictionary with the //Add() method. badguys.Add("gangster", bg1); badguys.Add("mutant", bg2); BadGuy magneto = badguys["mutant"]; BadGuy temp = null; //This is a safer, but slow, method of accessing //values in a dictionary. if (badguys.TryGetValue("birds", out temp)) { //success! } else { //failure! } }
private void Update() { float normalizeElapse = (Time.time - timer) / completeEdgeTime; transform.position = path.LerpNext(currentIndex, nextIndex, normalizeElapse); if (normalizeElapse > 1) { timer = Time.time; currentIndex += 1; if (currentIndex >= path.points.Count) { currentIndex = 0; } nextIndex = currentIndex + 1; if (nextIndex >= path.points.Count) { nextIndex = 0; } } if (Time.time - shootTimer > 1.2f) { BadGuy.LaunchProjectile(prefab_projectile, transform.position); shootTimer = Time.time; } }
void Start() { //这是创建字典的方式。注意这是如何采用 //两个通用术语的。在此情况中,您将使用字符串和 //BadGuy 作为两个值。 Dictionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); //可以使用 Add() 方法将变量 //放入字典中。 badguys.Add("gangster", bg1); badguys.Add("mutant", bg2); BadGuy magneto = badguys["mutant"]; BadGuy temp = null; //这是一种访问字典中值的更安全 //但缓慢的方法。 if (badguys.TryGetValue("birds", out temp)) { //成功! } else { //失败! } }
static void Main(string[] args) { Show.HorizontalDivider(); GoodGuy Harry = new GoodGuy("Harry Potter", 999); GoodGuy Hermione = new GoodGuy("Hermione Granger", 200); GoodGuy Ron = new GoodGuy("Ron Weasley", 100); BadGuy Voldemort = new BadGuy("Tom Riddle", 800); BadGuy Bellatrix = new BadGuy("Bellatrix Lestrange", 600); BadGuy Draco = new BadGuy("Draco Malfoy", 400); Show.HorizontalDivider(); Voldemort.steal(Harry, 200); Voldemort.steal(Draco, 200); Bellatrix.steal(Draco, 200); Harry.Capture(Bellatrix); Harry.give(Hermione, 400); Harry.give(Ron, 400); Show.HorizontalDivider(); System.Console.ReadKey(); }
static void Main(string[] args) { Show.HorizontalDivider(); GoodGuy harry = new GoodGuy("Harry Potter", 999); GoodGuy hermione = new GoodGuy("Hermione Granger", 200); GoodGuy ron = new GoodGuy("Ron Weasley", 100); BadGuy voldemort = new BadGuy("Tom Riddle", 800); BadGuy bellatrix = new BadGuy("Bellatrix Lestrange", 600); BadGuy draco = new BadGuy("Draco Malfoy", 400); Show.HorizontalDivider(); voldemort.Steal(harry, 200); voldemort.Steal(draco, 200); bellatrix.Steal(draco, 200); harry.Capture(bellatrix); harry.Give(hermione, 400); harry.Give(ron, 400); Show.HorizontalDivider(); System.Console.ReadKey(); }
void Start() { Dictionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); badguys.Add("gangster", bg1); badguys.Add("mutant", bg2); BadGuy magneto = badguys["mutant"]; BadGuy temp = null; if (badguys.TryGetValue("birds", out temp)) { Debug.Log("Successful"); } else { Debug.Log("Sorry, Its Gonna Failure"); } }
IEnumerator Shoot() { RaycastHit2D hitInfo = Physics2D.Raycast(firePoint.position, firePoint.right); if (hitInfo) { BadGuy badguy = hitInfo.transform.GetComponent <BadGuy>(); if (badguy != null) { badguy.TakeDamage(damage); } //Instantiate(impactEffect, hitInfo.point, Quaternion.identity); //rotation in a fancy way linerenderer.SetPosition(0, firePoint.position); linerenderer.SetPosition(1, hitInfo.point); } else { linerenderer.SetPosition(0, firePoint.position); linerenderer.SetPosition(1, firePoint.position + firePoint.right * 100); } linerenderer.enabled = true; yield return(new WaitForSeconds(0.02f)); linerenderer.enabled = false; }
// Start is called before the first frame update void Start() { /* * This is how you create a Dictionary. * Notice how this takes two generic terms. * In this case you are using a string and a BadGuy as your two values. */ Dictionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); // You can place variables into the Dictionary with the Add() method. badguys.Add("gangster", bg1); badguys.Add("mutant", bg2); BadGuy magneto = badguys["mutant"]; BadGuy temp = null; // This is a safer, but slow, method of accessing values in a dictionary. // if(badguys.TryGetValue("bir", out temp)) if (badguys.TryGetValue("mutant", out temp)) { Debug.Log("Match !!"); Debug.Log(temp.name + " " + temp.power); } else if (temp == null) { Debug.Log("Not Found Guy !!"); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// public void Capture(BadGuy badGuy) { double amount = badGuy.Money; this.Money += amount; badGuy.Money = 0; Show.CaptureMessage(this, badGuy, amount); }
void InitializeArray() { BadGuy[] badGuys = new BadGuy[] { new BadGuy("Robotnik", 20), new BadGuy("Thanos", 1000), new BadGuy("Rugal", 200), new BadGuy("Freeza", 80), }; Debug.Log("-- while --"); int index = 0; while (index < badGuys.Length) { Debug.LogFormat("[{0}] {1}", index, badGuys[index]); index++; } Debug.Log("-- For --"); for (int i = 0; i < badGuys.Length; i++) { Debug.LogFormat("[{0}] {1}", index, badGuys[i]); } Debug.Log("-- Foreach --"); foreach (BadGuy badGuy in badGuys) { Debug.Log(badGuy); } }
public BadGuy RemoveBadGuy() { var temp = badGuy; badGuy = null;; return(temp); }
public static void StealMessage(BadGuy badGuy, GoodGuy goodGuy, double amount) // parameters came from BadGuy class steal method { Show.Formatted(badGuy.Name + " stole " + amount + " from " + goodGuy.Name); // formatted writeLine Show.Money(badGuy); // uses the submethod to automatically grab badGuy.name and badGuy.money // to pass them as the string and double parameters in the main Money method. Show.Money(goodGuy); }
void Start() { // Dictionaries should be declared with <KEY, Value> Dicitionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); // Add method adds element in to the dictionary with // the pair of key and value badguys.Add("gangster", bg1); badguys.Add("mutant", bg2); // You can save the value of the dictionary element // only if the lefthand member has the same type BadGuy magneto = badguys["mutant"]; BadGuy temp = null; // Slow but safer mehtod to access to dictionary values if (badguys.TryGetValue("birds", out temp)) { // success! } else { // failure! } }
// Start is called before the first frame update void Start() { Dictionary <string, BadGuy> badGuys = new Dictionary <string, BadGuy>(); BadGuy bg1 = new BadGuy("Harvey", 50); BadGuy bg2 = new BadGuy("Magneto", 100); badGuys.Add("gangster", bg1); badGuys.Add("mutant", bg2); BadGuy temp = null; /// If you don't know the key, and need a default value //badGuys.ElementAt(0); if (badGuys.TryGetValue(value, out temp)) { //success print("Find value" + temp.power + " " + temp.name); } else { //failed print("not found"); } }
// Use this for initialization void Start() { //2 generic types: key(reference to access the 2nd type), value Dictionary <string, BadGuy> badguys = new Dictionary <string, BadGuy>(); //store different search words that can be used to identify specific bad guys BadGuy bg1 = new BadGuy("Harvey", 60); BadGuy bg2 = new BadGuy("Magento", 100); //add to the dictionary - both the key and the value badguys.Add("gangsta", bg1); badguys.Add("mutant", bg2); //accesing an object in the dictionary: insert a key into [] for a corresponding badguy return BadGuy magento = badguys["mutant"]; BadGuy temp = null; //will throw an exception error if a key is provided but no such key exists in the dictionary //use TryGetValue if not sure if the key exists(key's type, out param of value type) //safer but slightly slower than directly referencing the specific key. //use the key within [] for efficiency - only use when the specified key is definitely in the dictionary if (badguys.TryGetValue("birds", out temp)) { //success - the key is in the dictionary, returns true } else { //failure - the key is in the dictionary, returns true } }
public PingouinLauncherWeapon(BadGuy o) : base(true) { owner = o; cooldown = 1050.0f; name = "Lance pingouin !"; damage = 1; ammo = InfiniteAmmo; }
static void Main(string[] args) { BadGuy bg = new BadGuy(); bg.BadMethod(); //unsafe //{ // int* p = stackalloc int[9999999]; //} }
public static void LaunchProjectile2D(BadGuyProjectile prefab, Vector3 launchPosition, bool heightBased = false) { BadGuyProjectile bgp = GameObject.Instantiate(prefab, launchPosition, Quaternion.identity); if (!heightBased) { bgp.Launch(BadGuy.DirectionToPlayer2D(launchPosition), 10); } else { bgp.Launch(BadGuy.DirectionToPlayer(launchPosition), 10); } }
public void OnTriggerEnter2D(Collider2D hitInfo) { BadGuy badguy = hitInfo.GetComponent <BadGuy>(); if (badguy != null) { badguy.TakeDamage(damage); //Instantiate(impactEfffect, transform.position, transform.rotation); Destroy(gameObject); } }
public void AddBadGuy(BadGuy badGuy, bool isJustCreated = false) { this.badGuy = badGuy; badGuy.transform.parent = this.transform; if (isJustCreated) { badGuy.transform.localPosition = Vector3.zero; } else { badGuy.MoveToTarget(this.transform.position); } }
}//end GetRoom() //GetBadGuy() public static BadGuy GetBadGuy() { BadGuy b1 = new BadGuy("Loki", 20, 20, 25, 20, 2, 8, "Asgardian God of Mischief"); BadGuy b2 = new BadGuy("Ultron", 20, 20, 40, 15, 3, 9, "Artificial Intelligence set to erase humanity"); BadGuy b3 = new BadGuy("Chitauri", 5, 5, 20, 5, 1, 2, "A race of shapeshifters who want to conquer Earth"); Random randy = new Random(); List <BadGuy> BadGuys = new List <BadGuy>() { b1, b2, b3, b3, b3, b3 }; return(BadGuys[randy.Next(0, BadGuys.Count)]); } //End GetBadGuy()
public bool BadGuyCreate(BadGuyCreate model) { using (var ctx = new ApplicationDbContext()) { var newBadGuy = new BadGuy() { Name = model.Name, Level = model.Level, Class = model.Class, PlanetId = model.PlanetId, UserId = _userId }; ctx.BadGuys.Add(newBadGuy); return(ctx.SaveChanges() == 1); } }
public bool BadGuyCreate(BadGuyCreate model) { var newBadGuy = new BadGuy() { Name = model.Name, Level = model.Level, XpDropped = model.XpDropped, PlanetId = model.PlanetId, UserId = _ownerId }; using (var ctx = new ApplicationDbContext()) { ctx.BadGuys.Add(newBadGuy); return(ctx.SaveChanges() == 1); } }
// Update is called once per frame void Update() { switch (badGuyStates) { case BadGuyStates.Idle: if (BadGuy.LineToPlayer(eyeSight.position)) { badGuyStates = BadGuyStates.SeekingPlayer; lastPosition = transform.position; } break; case BadGuyStates.SeekingPlayer: if (Time.time - followTimer > followPrecision) { followTimer = Time.time; BadGuy.FollowPlayerShell(navMeshAgent, 3, Random.Range(0, 360)); } if (Time.time - fireRateTimer > fireRateTimer) { if (BadGuy.LineToPlayer(eyeSight.position, 10)) { navMeshAgent.isStopped = true; badGuyStates = BadGuyStates.ShotPlayer; coolTimer = Time.time; BadGuy.LaunchProjectile2D(prefab_projectile, eyeSight.position); fireRateTimer = Time.time; } } break; case BadGuyStates.ShotPlayer: if (Time.time - coolTimer < coolDown) { navMeshAgent.isStopped = false; navMeshAgent.SetDestination(lastPosition + Vector3.right * Random.Range(-3, 3)); } else { badGuyStates = BadGuyStates.Idle; } break; } }
private void InitializeStack() { Stack <BadGuy> badGuys = new Stack <BadGuy>(); badGuys.Push(new BadGuy("A", 10)); badGuys.Push(new BadGuy("B", 20)); badGuys.Push(new BadGuy("C", 30)); badGuys.Push(new BadGuy("D", 40)); Debug.Log("Contagem da pilha = " + badGuys.Count); while (badGuys.Count > 0) { BadGuy nextGuy = badGuys.Pop(); Debug.Log(nextGuy); Debug.Log("Contagem da pilha = " + badGuys.Count); } }
private void InitializeQueue() { Queue <BadGuy> badGuys = new Queue <BadGuy>(); badGuys.Enqueue(new BadGuy("A", 10)); badGuys.Enqueue(new BadGuy("B", 20)); badGuys.Enqueue(new BadGuy("C", 30)); badGuys.Enqueue(new BadGuy("D", 40)); Debug.Log("Contagem da fila = " + badGuys.Count); while (badGuys.Count > 0) { BadGuy nextGuy = badGuys.Dequeue(); Debug.Log(nextGuy); Debug.Log("Contagem da fila = " + badGuys.Count); } }
public void Start() { badGuy = battle.badGuy.GetComponent <BadGuy>(); if (battle.enemy2Spawned) { badGuy2 = battle.badGuy2.GetComponent <BadGuy>(); } if (battle.enemy3Spawned) { badGuy3 = battle.badGuy3.GetComponent <BadGuy>(); } badGuyTarget = battle.badGuy.GetComponent <BadGuyTarget>(); if (battle.enemy1Turn) { badGuy.badGuyAnim(); //battle.enemy1Turn = false; if (badGuy.finishedFlashing == true) { AttackPlayer(); } } if (battle.enemy2Turn) { badGuy2.badGuyAnim(); //battle.enemy2Turn = false; if (badGuy2.finishedFlashing == true) { AttackPlayer(); } } if (battle.enemy3Turn) { badGuy3.badGuyAnim(); //battle.enemy3Turn = false; if (badGuy3.finishedFlashing == true) { AttackPlayer(); } } }
/// <summary> /// Convert event into old version (0.8) enemy list. /// See EnemyEditor /// </summary> /// <returns></returns> public List <BadGuy> ExtractEnemiesFromEvents() { List <BadGuy> oldWayEnemies = new List <BadGuy>(); foreach (Event e in events) { foreach (Command c in e.Commands) { if (typeof(AddEnemyCommand) == c.GetType()) { BadGuy enemy = ((AddEnemyCommand)c).Enemy; enemy.ScrollValue = e.ScrollValue; oldWayEnemies.Add(enemy); } } } return(oldWayEnemies); }
//recieves game object information from TargetSelection script and handles damage. public void AttackSystem(GameObject gg, GameObject bg, bool ggAttack = false, bool bgAttack = false) { //Grab scrips from objects GoodGuy ggScript = gg.GetComponent <GoodGuy>(); BadGuy bgScript = bg.GetComponent <BadGuy>(); if (ggAttack) { bgScript.currentHP -= ggScript.attk; battle.hasAttacked = true; } if (bgAttack) { ggScript.currentHP -= bgScript.attk; battle.hasAttacked = true; } }
private void Launch() { BadGuy sapin = null; if (RandomMachine.GetRandomFloat(0, 1) > 0.79f) { sapin = new TGPA.Game.Entities.BackgroundActiveElement.Sapin2(new Vector2(TGPAContext.Instance.ScreenWidth + 1, TGPAContext.Instance.ScreenHeight - 31), RandomMachine.GetRandomFloat(0.5f, 1f)); } else { sapin = new TGPA.Game.Entities.BackgroundActiveElement.Sapin(new Vector2(TGPAContext.Instance.ScreenWidth + 1, TGPAContext.Instance.ScreenHeight - 31), RandomMachine.GetRandomFloat(0.5f, 1f)); } Vector2 loc = sapin.Location; loc.Y -= sapin.DstRect.Height; sapin.Location = loc; TGPAContext.Instance.AddEnemy(sapin); }
/// <param name="commandLine">Format : addenemy type relativex relativey bonus pattern flag1,flag2 flip</param> public bool ParseLine(string commandLine, Vector2 screenResolution) { string[] tokens = commandLine.Split(' '); if (tokens.Length < 4) return false; //Convert relative position to absolute Vector2 location = TGPAConvert.RelativeToAbsoluteLoc(tokens[2], tokens[3], screenResolution); //Enemy creation String optionalParameter = ""; if (tokens.Length == 5) { optionalParameter = tokens[4]; } this.Enemy = BackgroundActiveElement.String2BackgroundActiveElement(tokens[1], location, optionalParameter); return true; }
// Update is called once per frame void Update() { player = goodGuy.GetComponent<GoodGuy>(); enemy = badGuy.GetComponent<BadGuy>(); }
public static void CaptureMessage(GoodGuy goodGuy, BadGuy badGuy, double amount) { Show.Formatted(goodGuy.Name + " captured " + badGuy.Name + " and got " + amount); Show.Money(goodGuy); Show.Money(badGuy); }
// Use this for initialization void Start() { player = spawnGoodGuy.GetComponent<GoodGuy>(); enemy = SpawnBadGuy.GetComponent<BadGuy>(); heroCheck = GameObject.Find("GameController").GetComponent<HeroCheck>(); }
/// <param name="commandLine">Format : addenemy type relativex relativey bonus pattern flag1,flag2 flip</param> public bool ParseLine(string commandLine, Vector2 screenResolution) { string[] tokens = commandLine.Split(' '); if (tokens.Length != 8) return false; MovePattern pattern = null; //Convert relative position to absolute Vector2 location = TGPAConvert.RelativeToAbsoluteLoc(tokens[2], tokens[3], screenResolution); //Flip SpriteEffects flip = SpriteEffects.None; if (tokens[7].Equals(SpriteEffects.FlipHorizontally.ToString())) { flip = SpriteEffects.FlipHorizontally; } else if (tokens[7].Equals(SpriteEffects.FlipVertically.ToString())) { flip = SpriteEffects.FlipVertically; } //Flags //flag1,flag2,flag3 string[] flags = null; if (!tokens[6].Equals("")) flags = tokens[6].Split(','); //Bonus Bonus bonus = null; if (!tokens[4].Equals("nobonus")) { try { bonus = new Bonus(tokens[4]); } catch (Exception e) { Logger.Log(LogLevel.Error, "TGPA Exception : " + e.Message); } } //Pattern read if (tokens[5].Equals("nopattern")) pattern = null; else { //pattern = new MovePattern(); string[] points = tokens[5].Split('+'); foreach (String couple in points) { //Not a pattern ID if (couple.Contains(",") && couple.Contains("(")) { string[] xy = couple.Replace("(", "").Replace(")", "").Split(','); //pattern.AddPoint(new Point(Convert.ToInt32(xy[0]), Convert.ToInt32(xy[1]))); } else { MovePattern.DefinedMovePattern patternID = (MovePattern.DefinedMovePattern)Enum.Parse(typeof(MovePattern.DefinedMovePattern), couple, true); pattern = new MovePattern(patternID); } } } //Enemy creation this.Enemy = BadGuy.String2BadGuy(tokens[1], location, bonus, pattern, flip, flags); if (this.Enemy.Location.X == -1) { location.X = -this.Enemy.DstRect.Width - 1; } if (this.Enemy.Location.Y == -1) { location.Y = -this.Enemy.DstRect.Height - 1; } this.Enemy.Location = location; return true; }
public AddEnemyCommand(BadGuy enemy) { this.Enemy = enemy; }
private static void Money(BadGuy badGuy) { Show.Money(badGuy.Name, badGuy.Money); }
///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// public void Steal(BadGuy otherBadGuy, double amount) { this.Money += amount; otherBadGuy.Money -= amount; Show.StealMessage(this, otherBadGuy, amount); }
public AddBackgroundElementCommand(BadGuy enemy) { this.Enemy = enemy; }
public static void StealMessage(BadGuy badGuy, BadGuy otherBadGuy, double amount) { Show.Formatted(badGuy.Name + " stole " + amount + " from " + otherBadGuy.Name); Show.Money(badGuy); Show.Money(otherBadGuy); }