Modularized power distribution functions

master
Aaron Johnson 5 years ago
parent 68a8155ed7
commit 74c238b472

@ -31,10 +31,7 @@ namespace Elite_Power_Management_Simulator
private void btn_reset_Click(object sender, EventArgs e) private void btn_reset_Click(object sender, EventArgs e)
{ {
global.eng = 4; pwr_reset();
global.sys = 4;
global.wep = 4;
update();
} }
public void update() public void update()
{ {
@ -43,215 +40,229 @@ namespace Elite_Power_Management_Simulator
prog_wep.Value = global.wep; prog_wep.Value = global.wep;
} }
//Power Distribution Functions
public void pwr_reset()
{
global.eng = 4;
global.sys = 4;
global.wep = 4;
update();
}
public void pwr_eng()
{
bool fin = false;
if (global.eng < 8)
{
if (global.eng == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.sys >= 1 && global.wep >= 1 && !fin)
{
global.eng += 2;
global.sys -= 1;
global.wep -= 1;
fin = true;
}
if (global.sys < 1 && global.wep > 1 && !fin)
{
global.eng += 2;
global.wep -= 2;
fin = true;
}
if (global.sys > 1 && global.wep < 1 && !fin)
{
global.eng += 2;
global.sys -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.sys % 2 == 0)
{
if (global.wep >= 1 && !fin)
{
global.eng += 1;
global.wep -= 1;
fin = true;
}
/*else
{
if (!fin)
{
MessageBox.Show("Internal math error!");
}
}*/
}
else
{
if (global.sys >= 1 && !fin)
{
global.eng += 1;
global.sys -= 1;
fin = true;
}
/*else
{
if (!fin)
{
MessageBox.Show("Internal math error!");
}
}*/
}
}
}
update();
}
public void pwr_sys()
{
bool fin = false;
if (global.sys < 8)
{
if (global.sys == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.eng >= 1 && global.wep >= 1 && !fin)
{
global.sys += 2;
global.eng -= 1;
global.wep -= 1;
fin = true;
}
if (global.eng < 1 && global.wep > 1 && !fin)
{
global.sys += 2;
global.wep -= 2;
fin = true;
}
if (global.eng > 1 && global.wep < 1 && !fin)
{
global.sys += 2;
global.eng -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.eng % 2 == 0)
{
if (global.wep >= 1 && !fin)
{
global.sys += 1;
global.wep -= 1;
fin = true;
}
}
else
{
if (global.eng >= 1 && !fin)
{
global.sys += 1;
global.eng -= 1;
fin = true;
}
}
}
}
update();
}
public void pwr_wep()
{
bool fin = false;
if (global.wep < 8)
{
if (global.wep == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.sys >= 1 && global.eng >= 1 && !fin)
{
global.wep += 2;
global.sys -= 1;
global.eng -= 1;
fin = true;
}
if (global.sys < 1 && global.eng > 1 && !fin)
{
global.wep += 2;
global.eng -= 2;
fin = true;
}
if (global.sys > 1 && global.eng < 1 && !fin)
{
global.wep += 2;
global.sys -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.sys % 2 == 0)
{
if (global.eng >= 1 && !fin)
{
global.wep += 1;
global.eng -= 1;
fin = true;
}
}
else
{
if (global.sys >= 1 && !fin)
{
global.wep += 1;
global.sys -= 1;
fin = true;
}
}
}
}
update();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ {
//capture up arrow key
if (keyData == Keys.Up) if (keyData == Keys.Up)
{ {
bool fin = false; pwr_eng();
if (global.eng < 8)
{
if (global.eng == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.sys >= 1 && global.wep >= 1 && !fin)
{
global.eng += 2;
global.sys -= 1;
global.wep -= 1;
fin = true;
}
if (global.sys < 1 && global.wep > 1 && !fin)
{
global.eng += 2;
global.wep -= 2;
fin = true;
}
if (global.sys > 1 && global.wep < 1 && !fin)
{
global.eng += 2;
global.sys -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.sys % 2 == 0)
{
if (global.wep >= 1 && !fin)
{
global.eng += 1;
global.wep -= 1;
fin = true;
}
/*else
{
if (!fin)
{
MessageBox.Show("Internal math error!");
}
}*/
}
else
{
if (global.sys >= 1 && !fin)
{
global.eng += 1;
global.sys -= 1;
fin = true;
}
/*else
{
if (!fin)
{
MessageBox.Show("Internal math error!");
}
}*/
}
}
}
update();
return true; return true;
} }
//capture down arrow key
if (keyData == Keys.Down) if (keyData == Keys.Down)
{ {
global.eng = 4; pwr_reset();
global.sys = 4;
global.wep = 4;
update();
return true; return true;
} }
//capture left arrow key
if (keyData == Keys.Left) if (keyData == Keys.Left)
{ {
bool fin = false; pwr_sys();
if (global.sys < 8)
{
if (global.sys == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.eng >= 1 && global.wep >= 1 && !fin)
{
global.sys += 2;
global.eng -= 1;
global.wep -= 1;
fin = true;
}
if (global.eng < 1 && global.wep > 1 && !fin)
{
global.sys += 2;
global.wep -= 2;
fin = true;
}
if (global.eng > 1 && global.wep < 1 && !fin)
{
global.sys += 2;
global.eng -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.eng % 2 == 0)
{
if (global.wep >= 1 && !fin)
{
global.sys += 1;
global.wep -= 1;
fin = true;
}
}
else
{
if (global.eng >= 1 && !fin)
{
global.sys += 1;
global.eng -= 1;
fin = true;
}
}
}
}
update();
return true; return true;
} }
//capture right arrow key
if (keyData == Keys.Right) if (keyData == Keys.Right)
{ {
bool fin = false; pwr_wep();
if (global.wep < 8)
{
if (global.wep == 7)
{
calc.e = 1;
}
else
{
calc.e = 2;
}
if (calc.e == 2)
{
if (global.sys >= 1 && global.eng >= 1 && !fin)
{
global.wep += 2;
global.sys -= 1;
global.eng -= 1;
fin = true;
}
if (global.sys < 1 && global.eng > 1 && !fin)
{
global.wep += 2;
global.eng -= 2;
fin = true;
}
if (global.sys > 1 && global.eng < 1 && !fin)
{
global.wep += 2;
global.sys -= 2;
fin = true;
}
}
if (calc.e == 1)
{
if (global.sys % 2 == 0)
{
if (global.eng >= 1 && !fin)
{
global.wep += 1;
global.eng -= 1;
fin = true;
}
}
else
{
if (global.sys >= 1 && !fin)
{
global.wep += 1;
global.sys -= 1;
fin = true;
}
}
}
}
update();
return true; return true;
} }
return base.ProcessCmdKey(ref msg, keyData); return base.ProcessCmdKey(ref msg, keyData);

Loading…
Cancel
Save