예제 #1
0
파일: Player.cs 프로젝트: janoskaz/game
		public bool Fight(Being creature)
		{
			Being b1 = this;
			Being b2 = creature;
			
			while(b1.Alive() && b2.Alive())
			{
				// decide, who will attack first
				int attacker = this.WhoAttacks(creature);
				if (attacker==2)
				{
					b2 = this;
					b1 = creature;
				}
				// perform attack
				b1.Attack(b2);
				if(b2.Alive() || attacker==0) // if enemy 2 is alive, of if the attacks are parallel
				{
					b2.Attack(b1);
					Thread.Sleep(600);
				}
				b1 = this;
				b2 = creature;
				Thread.Sleep(600);
			}
			Console.WriteLine("Press any key to continue");
			Console.ReadKey();
			return this.Alive();
		}
예제 #2
0
파일: Player.cs 프로젝트: janoskaz/game
		public int WhoAttacks(Being creature)
		{
			int init1 = this.CalculateInitiative();
			int init2 = creature.CalculateInitiative();
			
			if (init1 > init2)
				return 1;
			if (init2>init1)
				return 2;
			return 0;					
		}
예제 #3
0
파일: Being.cs 프로젝트: janoskaz/game
 /// <summary>
 /// Attack another being.
 /// </summary>
 /// <param name='b'>
 /// B.
 /// </param>
 public void Attack(Being b)
 {
     int attack = this.CalculateAttack();
     Console.WriteLine(b.Defend(attack));
 }
예제 #4
0
파일: ThisGame.cs 프로젝트: janoskaz/game
        public static Being LoadBeingFromXml(XmlElement node)
        {
            // get name of being
            string name = node.Attributes["name"].Value;
            string symbol = node.Attributes["symbol"].Value;

            Characteristics ch = new Characteristics(0,0,0,0);
            Characteristics cch = new Characteristics(0,0,0,0);
            Inventory bag = new Inventory(0);
            Inventory equiped = new Inventory(0);
            string[] b = new string[6];

            foreach (XmlNode subnode in node.ChildNodes)
            {
                string nodeName = subnode.Name;
                switch (nodeName)
                {
                case "Characteristics":
                {
                    ch = LoadCharacteristicsFromXml((XmlElement)subnode);
                    break;
                }
                case "CurrentCharacteristics":
                {
                    cch = LoadCharacteristicsFromXml((XmlElement)subnode);
                    break;
                }
                case "Bag":
                {
                    bag = LoadInventoryFromXml((XmlElement)subnode);
                    break;
                }
                case "Equiped":
                {
                    equiped = LoadInventoryFromXml((XmlElement)subnode);
                    break;
                }
                case "Body":
                {
                    b = LoadBodyFromXML((XmlElement)subnode);
                    break;
                }

                }

            }
            Being being = new Being(name, ch, cch, bag.maxsize);
            being.bag = bag;
            being.equiped = equiped;
            being.SetBody(new Body(b));
            being.SetSymbol(symbol);

            return being;
        }