Closed Daniel-Martinez closed 10 years ago
Created a method that checks the bool isFriend flag and displays a message that they are friendly and does not fire at them.
case "kill":
if (enteredValue.Length > 0) //if caller has entered a name to search
{
for (int i = 0; i < statusList.Count; i++) //iterate through our TargetList to search for target name if enteredValue is entered.
{
if (enteredValue == statusList[i].Name) //if the given name is on our targetList
{
if (statusList[i].isFriend == true) //if he is a friend dont shoot and display message
{
Console.Write("Sorry Captain, we don't permit friendly fire, yar!\n");
}
else if (statusList[i].Status == "Dead")
{
Console.Write("Captain, this bloak is already looking dead to me! Nasty luck mate.\n");
}
else //ortherwise he is an enemy fire on coordinates
{
Console.Write("\nenemy sighted, preparing to fire\n");
Poseidon.command_reset(); //set missle launcher to firing position
double tempX = targetList[i].X;
double tempY = targetList[i].Y;
double tempZ = targetList[i].Z;
double radius = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//http://www.learningaboutelectronics.com/Articles/Cartesian-rectangular-to-spherical-coordinate-converter-calculator.php#answer
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
radius = Math.Sqrt(Math.Pow(tempX, 2) + Math.Pow(tempY, 2) + Math.Pow(tempZ, 2)); //cartetion product
theta = (180 / Math.PI) * (Math.Acos(tempZ / radius)); //calculating theta which is our up/down
phi = (180 / Math.PI) * (Math.Atan(tempY / tempX)); //calculateing phi which is left/right
if (tempZ == 0)
{
theta = 0;
}
int t = Convert.ToInt32(phi); //converts to int because our missleLauncher only understands integers, ### WE NEED TO ASK ABOUT THIS+
int t2 = Convert.ToInt32(theta);
if (phi < 0) //if entered value is less that zero it is a negative number and will move left.
{
int positive = Math.Abs(t); //must take absolute value of number to enter into moveLeft function
Poseidon.command_Left(positive); //missle launcher moves left by amount entered
}
else
{
Poseidon.command_Right(t); //if entered value is positive then we move right by amount entered
}
if (theta < 0)
{
int positive = Math.Abs(t2);
Poseidon.command_Down(positive);
}
else
{
Poseidon.command_Up(t2);
}
Poseidon.command_Fire();
for (i = 0; i < targetList.Count; i++) //iterate through our TargetList to search for target name if enteredValue is entered.
{
if (statusList[i].Name == enteredValue)
{
statusList[i].Status = "Dead";
}
}
Console.Write("\n");
}
}
}
}
break;
Create a method that will iterate through the target list and only fire on targets that are enemies.