コード例 #1
0
ファイル: ChooseTank.cs プロジェクト: bvuong1993/blackrose
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (_typeTank == -1)
            {
                MessageBox.Show("Please choose a tank");
                return;
            }

            switch (_typeTank)
            {
                case 0:
                    Tank = new Tank(Resources.Tank_A);
                    break;
                case 1:
                    Tank = new Tank(Resources.Tank_B);
                    break;
                case 2:
                    Tank = new Tank(Resources.Tank_C);
                    break;
                case 3:
                    Tank = new Tank(Resources.Tank_D);
                    break;
                default:
                    break;
            }

            DialogResult = DialogResult.OK;
        }
コード例 #2
0
ファイル: TestClassTank.cs プロジェクト: bvuong1993/blackrose
 public void Dispose()
 {
     if (_tank != null)
     {
         _tank.Dispose();
         _tank = null;
     }
 }
コード例 #3
0
ファイル: Condition.cs プロジェクト: bvuong1993/blackrose
 /// <summary>
 /// Return the result of Conditional with some input
 /// </summary>
 /// <param name="yourTank"></param>
 /// <param name="enemyTank"></param>
 /// <param name="enemyBullet"></param>
 /// <returns></returns>
 public bool GetResult(Tank yourTank, Tank enemyTank, Bullet enemyBullet)
 {
     if (Type == TypeCondition.And)
     {
         return Children.All(t => t.GetResult(yourTank, enemyTank, enemyBullet));
     }
     if (Type == TypeCondition.Or)
     {
         return Children.Any(t => t.GetResult(yourTank, enemyTank, enemyBullet));
     }
     return Comparision.GetResult(yourTank, enemyTank, enemyBullet);
 }
コード例 #4
0
ファイル: TestClassTank.cs プロジェクト: bvuong1993/blackrose
 public void Setup()
 {
     _tank = new Tank(Properties.Resources.Tank_A);
 }
コード例 #5
0
 private void pictureBoxTank_Click(object sender, EventArgs e)
 {
     var newTank = new ChooseTank();
     if (newTank.ShowDialog() == DialogResult.OK)
     {
         Tank temp = Tank;
         Tank = newTank.Tank;
         Tank.Name = temp.Name;
         Tank.ActionBeAttacked = temp.ActionBeAttacked;
         Tank.ActionCannotMoveBackward = temp.ActionCannotMoveBackward;
         Tank.ActionCannotMoveForward = temp.ActionCannotMoveForward;
         Tank.ActionDetected = temp.ActionDetected;
         Tank.ActionNormal = temp.ActionNormal;
         ShowTankInformation();
     }
 }
コード例 #6
0
 private void buttonOpen_Click(object sender, EventArgs e)
 {
     var opener = new OpenFileDialog
     {
         Title = "Open Tank",
         Filter = "Tank File (*.tank)|*.tank",
         RestoreDirectory = true
     };
     if (opener.ShowDialog() == DialogResult.OK)
     {
         try
         {
             IFormatter formatter = new BinaryFormatter();
             Stream stream = new FileStream(opener.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
             Tank = (Tank)formatter.Deserialize(stream);
             stream.Close();
             panelTank.Visible = true;
             panelAction.Visible = true;
             buttonSave.Enabled = true;
             ShowTankInformation();
             buttonActionNormal_Click(null, null);
             ShowInstructionInformationList();
             ShowInstructionInformationButton();
         }
         catch
         {
             MessageBox.Show("Cannot load this file!");
         }
     }
 }
コード例 #7
0
 private void buttonNew_Click(object sender, EventArgs e)
 {
     var newTank = new ChooseTank();
     if (newTank.ShowDialog() == DialogResult.OK)
     {
         Tank = newTank.Tank;
         panelTank.Visible = true;
         panelAction.Visible = true;
         buttonSave.Enabled = true;
         ShowTankInformation();
         buttonActionNormal_Click(null, null);
         ShowInstructionInformationList();
         ShowInstructionInformationButton();
     }
 }
コード例 #8
0
ファイル: Comparison.cs プロジェクト: bvuong1993/blackrose
        /// <summary>
        /// The turn the result of the Comparison
        /// </summary>
        /// <param name="yourTank"></param>
        /// <param name="enemyTank"></param>
        /// <param name="enemyBullet"></param>
        /// <returns></returns>
        public bool GetResult(Tank yourTank, Tank enemyTank, Bullet enemyBullet)
        {
            float par = 0;
            switch (Parameter)
            {
                case TypeParameter.GetPositionX:
                    par = yourTank.Position.X;
                    break;
                case TypeParameter.GetPositionY:
                    par = yourTank.Position.Y;
                    break;
                case TypeParameter.GetDirection:
                    par = MathProcessor.CalDifferentAngle(yourTank.Direction, 0);
                    break;
                case TypeParameter.GetCurrentHeal:
                    par = yourTank.HealCur;
                    break;
                case TypeParameter.GetEnemyDistance:
                    par = MathProcessor.CalDistance(yourTank.Position, enemyTank.Position);
                    break;
                case TypeParameter.GetEnemyDifferentAngle:
                    par = MathProcessor.CalDifferentAngle(yourTank.Direction, MathProcessor.CalPointAngle(yourTank.Position, enemyTank.Position));
                    break;
                case TypeParameter.GetEnemyCurrentHeal:
                    par = enemyTank.HealCur;
                    break;
                case TypeParameter.GetBulletDifferentAngle:
                    par = MathProcessor.CalDifferentAngle(yourTank.Direction, enemyBullet.Direction);
                    break;
            }

            const float epsilon = 1e-6f;
            switch (Operator)
            {
                case TypeOperator.GreaterEqual:
                    if (par >= Value)
                    {
                        return true;
                    }
                    break;
                case TypeOperator.Greater:
                    if (par > Value)
                    {
                        return true;
                    }
                    break;
                case TypeOperator.Equal:
                    if (Math.Abs(par - Value) < epsilon)
                    {
                        return true;
                    }
                    break;
                case TypeOperator.Lower:
                    if (par < Value)
                    {
                        return true;
                    }
                    break;
                case TypeOperator.LowerEqual:
                    if (par <= Value)
                    {
                        return true;
                    }
                    break;
                case TypeOperator.NotEqual:
                    if (Math.Abs(par - Value) > epsilon)
                    {
                        return true;
                    }
                    break;
            }

            return false;
        }
コード例 #9
0
ファイル: Tank.cs プロジェクト: bvuong1993/blackrose
 /// <summary>
 /// Execute some change of object in a frame in battlefield
 /// </summary>
 /// <param name="objects">Objects are battlefield</param>
 /// <returns>Result of that frame</returns>
 public override TypeResult NextFrame(List<ObjectGame> objects)
 {
     if (NewResult == TypeResult.BeDestroyed)
     {
         return TypeResult.BeDestroyed;
     }
     DetectedEnemy(objects);
     if (EnemyTank != null)
     {
         NewResult = TypeResult.Detected;
     }
     if (Instruction == null || Instruction.Interruptible)
     {
         SetListInstructions();
         while (Instruction == null)
         {
             if (ListInstructions.Count == 0)
             {
                 break;
             }
             else
             {
                 if (ListInstructions[0].Condition == null ||
                     ListInstructions[0].Condition.GetResult(this, EnemyTank, EnemyBullet))
                 {
                     Instruction = ListInstructions[0].Clone();
                 }
                 else
                 {
                     ListInstructions.RemoveAt(0);
                 }
             }
         }
     }
     NewResult = TypeResult.Normal;
     ExecuteInstruction(objects);
     EnemyTank = null;
     EnemyBullet = null;
     return TypeResult.Nothing;
 }
コード例 #10
0
ファイル: Tank.cs プロジェクト: bvuong1993/blackrose
 public void DetectedEnemy(List<ObjectGame> objects)
 {
     foreach (ObjectGame obj in objects)
     {
         if (obj != this && obj.Type == TypeObject.Tank)
         {
             var distance = MathProcessor.CalDistance(Position, obj.Position);
             var direction = MathProcessor.CalPointAngle(Position, obj.Position);
             var differentAngle = MathProcessor.CalDifferentAngle(Direction, direction);
             if (distance < RadaRange && Math.Abs(differentAngle) < RadaAngle / 2)
             {
                 EnemyTank = (Tank)obj;
                 break;
             }
         }
     }
 }