Speaking of a suicide otk from the legend of the Furnace Stone.

Source: Internet
Author: User
Tags rounds

OTK is one turn kill, but this time we want to talk about the OTK is suicide, is that he gave himself to OTK.

In fact, the program does not have any errors, just happen to encounter such a cycle of death.

PS: The end of the article has the code git address

Launch Conditions and Effects:

Ogine (Ockinnett effect is your life card and skill changed to inflict equal damage)

Queen of Pain (whenever the attendant causes damage, restore the same amount of health for your hero)

Ogine when the pain queen in the presence of the attack, the pain Queen's special effects judgment, back to life 1, and trigger Ogine special effects, buckle himself 1 points of blood, again trigger the pain of the Queen damage effect, again back to life 1, and trigger Ockinnett effect, buckle himself 1 blood, and then cause the cycle of death, Until you hang up.

Interested children shoes can watch this video below: http://h.163.com/15/0313/16/AKJOMG4O00314RES.html

Of course, the speculation in the video is definitely wrong, according to the programmer's point of view should be into the dead loop.

Program Simulation:

We want to be able to simulate this scenario, and try to implement the battle logic of the stone, the following figure is our simulation effect, the general realization of some cards and functions.

Basic class Design

The first is BaseUnit, a class that implements most of the underlying content, derives cards and heroes based on this class, and then cards derive magic cards, weapon cards, companion cards, and so on.

The base class contains attributes such as the amount of blood, armor, holy Shield, number of attacks, and so on, which can be used to achieve some of the basic attacks in the furnace, without considering the implementation of AOE skills and the halo design of wolves.

Basic wind rage, actcount can be +1, charge, war roar when actcount+1, the default entourage on the Actcount is 0;

But these are not the focus, our focus is on the decision after the attack how to achieve, here BaseUnit also did not realize the follower of the logic, death logic, just put a shelf .

Using system;using system.collections.generic;using system.linq;using system.text;using HeartStone.Interface; namespace Heartstone.basedomain{public class Baseunit:iunitaction{public BaseUnit (Basehero phero) {OwnerHero = PHero; Name = "Unknown"; Ac = 0; Actcount = 0; Ad = 0; Basead = 0; BASEHP = 0;this. Herotype = Herotype.none;this. Hp = 0;this. Shield = false;} public virtual void Dispose () {Console.WriteLine ("{0} dead", this. Name); return;} Public Basehero Ownerhero {get; set;} <summary>///occupation Type///</summary>public herotype herotype {get; set;} public string Name {get; set;} private int _hp;///<summary>///blood volume//</summary>public int Hp{get {return _hp;} set{//the maximum amount of blood must not exceed the base amount if (Value > BASEHP) _hp = BASEHP;ELSE_HP = value;}} <summary>///base Blood volume//</summary>public int BASEHP {get; set;} private int _ac {get; set;} <summary>///Armor///</summary>public int Ac{get {return _ac;} set{//armor can not exceed the base blood amount if (Value > BASEHP) _ac = Basehp;else_ac = Value;}} <summary>///Attack///</summary>public int Ad {get; set;} <summary>///basic Attack///</summary>public int Basead {get; set;} <summary>///attack times, charge play +1, wind rage per turn +1///</summary>public int Actcount {get; set;} private bool _shield = false;///<summary>///Holy Shield///</summary>public bool Shield{get {return _shield;} set {_shield = value;}} public virtual void Attack (BaseUnit targeted, baseunit from, int AD) {targeted. Defense (targeted, from, AD);} public virtual void Defense (BaseUnit targeted, baseunit from, int ad) {if (Shield) Shield = False;else{int Acdefend = 0;if ( Targeted. Ac > 0) {acdefend = targeted. Ac-ad;if (acdefend >= 0) targeted. Ac-= ad;//attack 5, armor 10,10-5 greater than or equal to 0, the armor is higher than the attack, as long as the reduction of armor can be else{//attack 5, Armor 2,2-5=-3, less than 0, said armor is not enough, to reduce targeted. Ac = 0;targeted. Hp + = Acdefend;}} Elsetargeted. Hp-= AD; Console.WriteLine ("{0} is affected by {1} {2}, current armor {3}, life {4}", targeted. Name, from. Name, ad, targeted. Ac, targeted. HP); from. Makedamage (targeted, from, AD);}} <summarY&GT;///Executive Treatment///</summary>///<param name= "targeted" ></param>///<param name= "from" ></ param>///<param name= "ad" ></param>public void Treat (BaseUnit targeted, baseunit from, int ad) {var hero = f Rom as Basehero;bool flag = true;if (hero! = NULL) flag = Hero.treatflag;elseflag = from. OWNERHERO.TREATFLAG;IF (flag) {targeted. Hp + = AD; Console.WriteLine ("{0} was treated with {1} {2}", targeted. Name, from. Name, AD);} Else{if (targeted. Hp >= 0) {//from created damage defense (targeted, from, AD);}}} public virtual void Makedamage (BaseUnit targeted, baseunit from, int ad) {return;}}}

  

The realization of Ogine

The effect of Ogine is that your treatment becomes an equal amount of damage, so the opponent's treatment is still treated, so I added a property to the hero, Treatflag, to mark the healing state of the hero.

So the therapeutic effect of the card, such as the Ring of Earth or the old driver, all cards in the game, that is, when new must pass an owner, to indicate the card belongs to whom, then it is easy to find the hero's treatment.

Using system;using system.collections.generic;using system.linq;using system.text;using HeartStone.BaseDomain; namespace Heartstone.units.unitcard{public class Okinny:basecard{public Okinny (Basehero phero): Base (Phero) {Crystal = 4; Basecrystal = 4; Ad = 3; Basead = 3; BASEHP = 5; Hp = 5; Name = "Ogine";//Priest professional card Herotype = herotype.minister;//Ogine Battlefield effect Phero.treatflag = false; Console.WriteLine ("{0} Summon debut", Name);} ~okinny () {this. Ownerhero.treatflag = true;} public override void Dispose () {//Ogine dead to reset this. Ownerhero.treatflag = True;base. Dispose ();}}}

  

The fulfillment of the Queen of pain

The effect of the Queen of Pain is to restore the same amount of life when the damage is done, so the Queen of pain needs to rewrite the Makedamage method and then give her hero an equal amount of life.

Using system;using system.collections.generic;using system.linq;using system.text;using HeartStone.BaseDomain; namespace Heartstone.units.unitcard{public class Queenpain:basecard{public Queenpain (Basehero phero): Base (PHero) { Crystal = 2; Basecrystal = 2; Ad = 1; Basead = 1; BASEHP = 4; Hp = 4; Name = "Queen of Pain";//Priest professional card herotype = Herotype.minister; Console.WriteLine ("{0} Summon debut", Name);} public override void Makedamage (BaseUnit targeted, baseunit from, int. AD) {Treat (from. Ownerhero, this, ad); base. Makedamage (targeted, from, AD);}}}

  

The realization of treatment

The implementation of the treatment needs to be judged Treatflag, if the Treatflag is false, then it will cause an equal amount of damage, and then call from again. Makedamage method, so that you can cycle the pain of the queen to create damage, of course, in order to prevent the real cycle of death, it is necessary to determine the health of the target, if the target health value is less than 0, then stop the loop.

<summary>///perform treatment///</summary>///<param name= "targeted" ></param>///<param name= " From "></param>///<param name=" ad "></param>public void Treat (BaseUnit targeted, BaseUnit from, int AD) {var hero = from as Basehero;bool flag = true;if (hero! = NULL) flag = Hero.treatflag;elseflag = from. OWNERHERO.TREATFLAG;IF (flag) {targeted. Hp + = AD; Console.WriteLine ("{0} was treated with {1} {2}", targeted. Name, from. Name, AD);} Else{if (targeted. Hp >= 0) {//from created damage defense (targeted, from, AD);}}}

  

The realization of heroes and skills

The hero's skills take into account that the warrior is instantaneous, the mage can choose the target, of course there will be only the ability to choose their own companions or only choose the hero skills, and so on. So here we add a taregtobject to mark who this skill can point to.

And then it's the code that implements each hero, and I've achieved 3 heroes, and here's a demonstration of the priest's realization.

Using system;using system.collections.generic;using system.linq;using system.text;using HeartStone.BaseDomain; namespace Heartstone.units.hero{public class herominister:basedomain.basehero{///<summary>///constructor///</ Summary>public Herominister (): Base () {Name = "priest";//Initialize own skill Heroskill = new Ministerskill (this);}} public class Ministerskill:baseheroskill{public Ministerskill (Basehero phero): Base (Phero) {TargetObject = Targetedobject.allunit;} <summary>///Priest's skills///</summary>public override void Skill (BaseUnit taregted) {Console.WriteLine ("{0} The skill was used, target {1} ", Thishero.name, taregted. Name); This.thisHero.Treat (taregted, Thishero, 2);}}

  

Simulation effect

Then we can do a simple simulation without considering the crystal, directly simulating the environment

static void Main (string[] args) {herominister minister = new Herominister (); Herowarrior Warrior = new Herowarrior ();//Warrior rounds, Warriors use skills, End warrior. Heroskill.skill (Warrior); Console.WriteLine ("================ round ends ================");//Pastor round, priest Obingini, Agony queen, with healing injuries warrior Okinny Okinny = new Okinny ( Minister); Queenpain Queenpain = new Queenpain (minister); minister. Heroskill.skill (Warrior); Console.WriteLine ("================ round ends ================");//Warrior rounds, Warriors use skills, End warrior. Heroskill.skill (Warrior); Console.WriteLine ("================ round ends ================");//Pastor round, Ogine attack, agony queen attack, priest Stroke Okinny.attack (warrior, Okinny, OKINNY.AD); Queenpain.attack (Warrior, Queenpain, Queenpain.ad); Console.WriteLine ("================ round ends ================"); Console.readkey ();}

  

Written in the last

Usually play when the furnace Stone is a simple game, simulation of this scene should be very easy, but the real to realize when there is still a lot of places lack of consideration, after a day of modification to finally come out of the prototype of this simulation, there are a lot of PvP logic did not realize, For example, AOE's spells have yet to come up with a good way to implement them.

Git:https://git.oschina.net/jangojing/heartstonetest.git

Speaking of a suicide otk from the legend of the Furnace Stone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.