1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Battleships.General; using Battleships.Ships; using Battleships.PhysicalEnvironment;
namespace Battleships { public partial class MainScreen : Form { InternalStorage NewStorage = new InternalStorage(); GlobalEnvironment NewEnvironment = new GlobalEnvironment(); InOutCheck NewCheck = new InOutCheck(); InOutConvert NewConvert = new InOutConvert(); PlayerShip NewPlayerShip = new PlayerShip(); TurnCountCalculation NewTurnCountCalculation = new TurnCountCalculation(); PositionCalculation NewPositionCalculation = new PositionCalculation(); BallisticCalculation NewBallisticCalculation = new BallisticCalculation(); AmmoCountCalculation NewAmmoCountCalculation = new AmmoCountCalculation();
public MainScreen() { InitializeComponent(); }
private void MainScreen_Load(object sender, EventArgs e) { int FirstTurn = 1; NewStorage.StoreCurrentNumberOfTurns(FirstTurn); this.TurnCounterBox.Text = Convert.ToString(NewStorage.RestoreCurrentNumberOfTurns());
if (NewStorage.RestoreCurrentNumberOfTurns() == 1) { NewStorage.StorePlayerPosXM(NewPlayerShip.InitialPositionX); NewStorage.StorePlayerPosYM(NewPlayerShip.InitialPositionY); double CurrentPlayerPosXNauticalMiles = NewConvert.ConvertMetersToNauticalMiles(NewStorage.RestorePlayerPosXM(), NewEnvironment.ConversionFactorMetersToNauticalMiles); double CurrentPlayerPosYNauticalMiles = NewConvert.ConvertMetersToNauticalMiles(NewStorage.RestorePlayerPosYM(), NewEnvironment.ConversionFactorMetersToNauticalMiles);
int CurrentPlayerAmmoCount = NewAmmoCountCalculation.CalculateCurrentAmmoAmount(NewPlayerShip.InitialAmmo, 0); NewStorage.StorePlayerCurrentAmmoCount(CurrentPlayerAmmoCount); this.AmmoBox.Text = Convert.ToString(NewStorage.RestorePlayerCurrentAmmoCount());
pictureBoxPlayerShip1.BackColor = Color.Transparent; pictureBoxSplash.BackColor = Color.Transparent;
pictureBoxPlayerShip1.Parent = pictureBoxBackground; pictureBoxSplash.Parent = pictureBoxBackground;
pictureBoxPlayerShip1.Location = new Point(Convert.ToInt32(CurrentPlayerPosXNauticalMiles), Convert.ToInt32(CurrentPlayerPosYNauticalMiles));
pictureBoxSplash.Visible = true; pictureBoxSplash.Location = new Point(Convert.ToInt32(0), Convert.ToInt32(0));
} }
private void ApplySpeed_Click(object sender, EventArgs e) { bool IsInt = NewCheck.CheckIfInt(this.SpeedBox.Text);
if (IsInt == true) { bool IsInRange = NewCheck.CheckIfIntWithinRange(this.SpeedBox.Text, NewPlayerShip.MaxSpeedKts, NewPlayerShip.MinSpeedKts);
if (IsInRange == true) { NewStorage.StorePlayerSpeedKts(Convert.ToInt32(this.SpeedBox.Text)); this.SpeedBox.Text = Convert.ToString(NewStorage.RestorePlayerSpeedKts()); } else { MessageBox.Show("Speed either exceeds maximum speed or is negative. Maximum Speed for this vessel is: " + NewPlayerShip.MaxSpeedKts, "Wrong Speed"); }
} else { if (IsInt == false) { MessageBox.Show("Input must be Integer.", "Wrong Format"); } } }
private void ApplyCourse_Click(object sender, EventArgs e) { bool IsInt = NewCheck.CheckIfInt(this.CourseBox.Text);
if (IsInt == true) { bool IsInRange = NewCheck.CheckIfIntWithinRange(this.CourseBox.Text, NewPlayerShip.MaxCourseDegrees, NewPlayerShip.MinCourseDegrees);
if (IsInRange == true) { NewStorage.StorePlayerCourseDegrees(Convert.ToInt32(this.CourseBox.Text)); this.CourseBox.Text = Convert.ToString(NewStorage.RestorePlayerCourseDegrees()); } else { MessageBox.Show("Course either exceeds maximum angle or is negative. Course must be between 0 and 360 degrees." , "Wrong Course"); }
} else { if (IsInt == false) { MessageBox.Show("Input must be Integer.", "Wrong Format"); } } }
private void ApplyGunAzimuth_Click(object sender, EventArgs e) { bool IsDouble = NewCheck.CheckIfDouble(this.GunHorizontalBox.Text);
if (IsDouble == true) { bool IsInRange = NewCheck.CheckIfDoubleWithinRange(this.GunHorizontalBox.Text, NewPlayerShip.MaxGunAzimuthDegrees, NewPlayerShip.MinGunAzimuthDegrees);
if (IsInRange == true) { NewStorage.StorePlayerGunAzimuthDegrees(Convert.ToInt32(this.GunHorizontalBox.Text)); this.GunHorizontalBox.Text = Convert.ToString(NewStorage.RestorePlayerGunAzimuthDegrees()); } else { MessageBox.Show("Gun azimuth either exceeds maximum or minimum angle for this vessel. Gun azimuth must be between 0 and " + NewPlayerShip.MaxGunAzimuthDegrees, "Wrong Angle"); }
} else { if (IsDouble == false) { MessageBox.Show("Input must be Real Number", "Wrong Format"); } } }
private void ApplyGunElevation_Click(object sender, EventArgs e) { bool IsDouble = NewCheck.CheckIfDouble(this.GunVerticalBox.Text);
if (IsDouble == true) { bool IsInRange = NewCheck.CheckIfDoubleWithinRange(this.GunVerticalBox.Text, NewPlayerShip.MaxGunElevationDegrees, NewPlayerShip.MinGunElevationDegrees);
if (IsInRange == true) { NewStorage.StorePlayerGunElevationDegrees(Convert.ToInt32(this.GunVerticalBox.Text)); this.GunVerticalBox.Text = Convert.ToString(NewStorage.RestorePlayerGunElevationDegrees()); } else { string _LocalString1 = Convert.ToString(NewPlayerShip.MaxGunElevationDegrees) + Convert.ToString(NewPlayerShip.MinGunElevationDegrees); MessageBox.Show("Gun elevation either exceeds maximum or minimum angle for this vessel. Gun elevation must be between: " + _LocalString1, "Wrong Angle"); }
} else { if (IsDouble == false) { MessageBox.Show("Input must be Real Number", "Wrong Format"); } } }
private void ApplyGunCharges_Click(object sender, EventArgs e) { bool IsInt = NewCheck.CheckIfInt(this.GunPropellingBox.Text);
if (IsInt == true) { bool IsInRange = NewCheck.CheckIfIntWithinRange(this.GunPropellingBox.Text, NewPlayerShip.MaxGunPropellingChargesAmount, NewPlayerShip.MinGunPropellingChargesAmount);
if (IsInRange == true) { NewStorage.StorePlayerGunPropellingChargesAmount(Convert.ToInt32(this.GunPropellingBox.Text)); this.GunPropellingBox.Text = Convert.ToString(NewStorage.RestorePlayerGunPropellingChargesAmount()); } else { MessageBox.Show("Amount of propelling charges either exceeds maximum or minimum for this vessels guns. Number of Propelling Charges mus be between 1 and " + NewPlayerShip.MaxGunPropellingChargesAmount, "Wrong Amount"); }
} else { if (IsInt == false) { MessageBox.Show("Input must be Integer", "Wrong Format"); } } }
private void FireGunSalvo_Click(object sender, EventArgs e) { bool _LocalBool = true; NewStorage.StorePlayerGunFireThisTurn(_LocalBool); }
private void RadarTurnOn_Click(object sender, EventArgs e) { bool _LocalBool = true; NewStorage.StorePlayerRadarStatus(_LocalBool); }
private void RadarTurnOff_Click(object sender, EventArgs e) { bool _LocalBool = false; NewStorage.StorePlayerRadarStatus(_LocalBool); }
private void EndTurn_Click(object sender, EventArgs e) { double _LocalSpeedMs = NewConvert.ConvertKtsToMs(NewStorage.RestorePlayerSpeedKts()); NewStorage.StorePlayerSpeedMs(_LocalSpeedMs);
double _LocalSpeedVectorX = NewConvert.ConvertPolarTo2DX(NewStorage.RestorePlayerCourseDegrees(), NewStorage.RestorePlayerSpeedMs()); NewStorage.StorePlayerSpeedVectorXMs(_LocalSpeedVectorX);
double _LocalSpeedVectorY = NewConvert.ConvertPolarTo2DY(NewStorage.RestorePlayerCourseDegrees(), NewStorage.RestorePlayerSpeedMs()); NewStorage.StorePlayerSpeedVectorYMs(_LocalSpeedVectorY);
double _LocalTotalInitialVelocity = NewConvert.ConvertPropellingChargesToTotalv0(NewStorage.RestorePlayerGunPropellingChargesAmount(), NewPlayerShip.VelocityPerChargeMs); NewStorage.StorePlayerGunTotalInitialVelocity(_LocalTotalInitialVelocity);
double _LocalInitialVelocityVectorXMs = NewConvert.ConvertSphericalTo3DX(NewStorage.RestorePlayerGunTotalInitialVelocity(), NewStorage.RestorePlayerGunElevationDegrees(), NewStorage.RestorePlayerGunAzimuthDegrees()); NewStorage.StorePlayerInitialVelocityVectorXMs(_LocalInitialVelocityVectorXMs);
double _LocalInitialVelocityVectorYMs = NewConvert.ConvertSphericalTo3DY(NewStorage.RestorePlayerGunTotalInitialVelocity(), NewStorage.RestorePlayerGunElevationDegrees(), NewStorage.RestorePlayerGunAzimuthDegrees()); NewStorage.StorePlayerInitialVelocityVectorYMs(_LocalInitialVelocityVectorYMs);
double _LocalInitialVelocityVectorZMs = NewConvert.ConvertSphericalTo3DZ(NewStorage.RestorePlayerGunTotalInitialVelocity(), NewStorage.RestorePlayerGunElevationDegrees()); NewStorage.StorePlayerInitialVelocityVectorZMs(_LocalInitialVelocityVectorZMs);
int PreviousTurn = NewStorage.RestoreCurrentNumberOfTurns(); int CurrentTurn = NewTurnCountCalculation.CalculateCurrentTurnNumber(PreviousTurn); NewStorage.StoreCurrentNumberOfTurns(CurrentTurn); this.TurnCounterBox.Text = Convert.ToString(NewStorage.RestoreCurrentNumberOfTurns());
int CurrentTimeScaleMins = 6; double CurrentPlayerPosXMeters = NewPositionCalculation.CalculateNewPosX(NewStorage.RestorePlayerPosXM(), NewStorage.RestorePlayerSpeedVectorXMs(), CurrentTimeScaleMins); double CurrentPlayerPosYMeters = NewPositionCalculation.CalculateNewPosY(NewStorage.RestorePlayerPosYM(), NewStorage.RestorePlayerSpeedVectorYMs(), CurrentTimeScaleMins); double CurrentPlayerPosXNauticalMiles = NewConvert.ConvertMetersToNauticalMiles(CurrentPlayerPosXMeters, NewEnvironment.ConversionFactorMetersToNauticalMiles); double CurrentPlayerPosYNauticalMiles = NewConvert.ConvertMetersToNauticalMiles(CurrentPlayerPosYMeters, NewEnvironment.ConversionFactorMetersToNauticalMiles); NewStorage.StorePlayerPosXM(CurrentPlayerPosXMeters); NewStorage.StorePlayerPosYM(CurrentPlayerPosYMeters); NewStorage.StorePlayerPosXNm(CurrentPlayerPosXNauticalMiles); NewStorage.StorePlayerPosYNm(CurrentPlayerPosYNauticalMiles);
pictureBoxPlayerShip1.Location = new Point(Convert.ToInt32(NewStorage.RestorePlayerPosXNm()), Convert.ToInt32(NewStorage.RestorePlayerPosYNm()));
if (NewStorage.RestorePlayerGunFireThisTurn() == true) { bool AmmoAvailable; if (NewCheck.CheckIntIfAboveZero(NewStorage.RestorePlayerCurrentAmmoCount())) { AmmoAvailable = true; } else { AmmoAvailable = false; }
if (AmmoAvailable == true) { int CurrentPlayerAmmoCount = NewAmmoCountCalculation.CalculateCurrentAmmoAmount(NewStorage.RestorePlayerCurrentAmmoCount(), NewStorage.RestorePlayerGunPropellingChargesAmount()); NewStorage.StorePlayerCurrentAmmoCount(CurrentPlayerAmmoCount); this.AmmoBox.Text = Convert.ToString(NewStorage.RestorePlayerCurrentAmmoCount()); double _LocalTimeOfImpactSeconds = NewBallisticCalculation.CalculateImpactTimeZSeconds(NewStorage.RestorePlayerInitialVelocityVectorZMs(), NewEnvironment.ConstantGravitationalAccelerationMs2, NewPlayerShip.DeckHeightMeters, NewPlayerShip.ProjectileMassKg); double _LocalImpactPointYMeters = NewBallisticCalculation.CalculateImpactPointYMeters(NewStorage.RestorePlayerInitialVelocityVectorYMs(), 0, NewStorage.RestorePlayerPosYM(), _LocalTimeOfImpactSeconds, NewPlayerShip.ProjectileMassKg); double _LocalImpactPointXMeters = NewBallisticCalculation.CalculateImpactPointXMeters(NewStorage.RestorePlayerInitialVelocityVectorXMs(), 0, NewStorage.RestorePlayerPosXM(), _LocalTimeOfImpactSeconds, NewPlayerShip.ProjectileMassKg); double _LocalImpactPointXNm = NewConvert.ConvertMetersToNauticalMiles(_LocalImpactPointXMeters, NewEnvironment.ConversionFactorMetersToNauticalMiles); double _LocalImpactPointYNm = NewConvert.ConvertMetersToNauticalMiles(_LocalImpactPointYMeters, NewEnvironment.ConversionFactorMetersToNauticalMiles); NewStorage.StoreImpactPointXNm(_LocalImpactPointXNm); NewStorage.StoreImpactPointYNm(_LocalImpactPointYNm);
bool TargetIsHit = false; if (TargetIsHit == true) { bool _LocalSplashThisTurn = false; NewStorage.StoreIfPlayerSplash(_LocalSplashThisTurn); }
else { bool _LocalSplashThisTurn = true; NewStorage.StoreIfPlayerSplash(_LocalSplashThisTurn); } } else { bool _LocalBool = false; NewStorage.StorePlayerGunFireThisTurn(_LocalBool); FireGunSalvo.Enabled = false; this.AmmoBox.Text = Convert.ToString(0); }
} else { bool SplashThisTurn = false; NewStorage.StoreIfPlayerSplash(SplashThisTurn); } pictureBoxSplash.Visible = NewStorage.RestoreIfPlayerSplash(); pictureBoxSplash.Location = new Point(Convert.ToInt32(NewStorage.RestoreImpactPointXNm()), Convert.ToInt32(NewStorage.RestoreImpactPointYNm())); } } } |