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; }
public void Dispose() { if (_tank != null) { _tank.Dispose(); _tank = null; } }
/// <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); }
public void Setup() { _tank = new Tank(Properties.Resources.Tank_A); }
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(); } }
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!"); } } }
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(); } }
/// <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; }
/// <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; }
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; } } } }