Professional Documents
Culture Documents
Models;
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
namespace BattleShipConsole
{
class Program //Created for Everflow with Github Copilot for speed
{
static void Main(string[] args)
{
Run();
}
#region Game
EVFNavyAsset EVFNavyAsset = new EVFNavyAsset();
EVFNavyAsset EVFEnemyNavyAsset = new EVFNavyAsset();
PrintMap(EVFNavyAsset.FirePositions, EVFNavyAsset, EVFEnemyNavyAsset,
ShowShips);
int Game;
for (Game = 1; Game < 101; Game++)
{
EVFNavyAsset.StepsTaken++;
ForegroundColor = ConsoleColor.White;
WriteLine("Enter firing Coord's (e.g. A3).");
string input = ReadLine();
position = AnalyzeInput(input, Coordinates);
EVFEnemyNavyAsset.Fire();
if (index == -1)
EVFNavyAsset.FirePositions.Add(position);
Clear();
PrintHeader();
for (int h = 0; h < 19; h++)
{
Write(" ");
}
PrintMap(EVFNavyAsset.FirePositions, EVFNavyAsset,
EVFEnemyNavyAsset, ShowShips);
Commentator(EVFNavyAsset, true);
Commentator(EVFEnemyNavyAsset, false);
if (EVFEnemyNavyAsset.IsObliteratedAll ||
EVFNavyAsset.IsObliteratedAll) { break; }
ForegroundColor = ConsoleColor.White;
if (EVFEnemyNavyAsset.IsObliteratedAll && !
EVFNavyAsset.IsObliteratedAll)
{
WriteLine($"Game Ended, you win. {name}");
}
else if (!EVFEnemyNavyAsset.IsObliteratedAll &&
EVFNavyAsset.IsObliteratedAll)
{
WriteLine($"Game Ended, you lose. {name}, The only winning move is
not to play."); //Cheeky War games reference
}
else
{
WriteLine("Game Ended, draw.");
}
if (x == 2 && y == 10)
{
if (navyAsset.IsBattleshipSunk)
{
ForegroundColor = ConsoleColor.Red;
Write("Battleship [5]");
}
else
{
ForegroundColor = ConsoleColor.DarkGreen;
Write("Battleship [5]");
}
}
if (x == 3 && y == 10)
{
if (navyAsset.IsDestroyerSunk)
{
ForegroundColor = ConsoleColor.Red;
Write("Destroyer [4] ");
}
else
{
ForegroundColor = ConsoleColor.DarkGreen;
Write("Destroyer [4] ");
}
}
if (x == 4 && y == 10)
{
if (navyAsset.IsDestroyer2Sunk)
{
ForegroundColor = ConsoleColor.Red;
Write("Destroyer [4] ");
}
else
{
ForegroundColor = ConsoleColor.DarkGreen;
Write("Destroyer [4] ");
}
}
int hitCounter = 0;
int EnemyshipCounter = 0;
int myShipCounter = 0;
int enemyHitCounter = 0;
if (SortedLFirePositions.Count != 0 &&
SortedLFirePositions[hitCounter].x == x && SortedLFirePositions[hitCounter].y == y)
{
if (EnemyMyNavyAsset.AllShipsPosition.Exists(ShipPos =>
ShipPos.x == x && ShipPos.y == y))
{
ForegroundColor = ConsoleColor.Red;
Write("[*]");
keepGoing = false;
}
else
{
ForegroundColor = ConsoleColor.Black;
Write("[X]");
keepGoing = false;
if (keepGoing)
{
ForegroundColor = ConsoleColor.Blue;
Write("[~]");
}
PrintStatistic(x, y, MyNavyAsset);
if (y == 10)
{
Write(" ");
WriteLine();
}
}
catch (Exception e)
{
string error = e.Message.ToString();
}
}
try
{
if (SortedLFirePositions.Count != 0 &&
SortedLFirePositions[EnemyHitCounter].x == x &&
SortedLFirePositions[EnemyHitCounter].y == y)
{
if (MyNavyAsset.AllShipsPosition.Exists(ShipPos =>
ShipPos.x == x && ShipPos.y == y))
{
ForegroundColor = ConsoleColor.Red;
Write("[*]");
keepGoing = false;
}
else
{
ForegroundColor = ConsoleColor.Black;
Write("[X]");
keepGoing = false;
ForegroundColor = ConsoleColor.DarkGreen;
Write("[O]");
keepGoing = false;
if (keepGoing)
{
ForegroundColor = ConsoleColor.Blue;
Write("[~]");
}
PrintStatistic(x, y, EnemyNavyAsset);
}
catch (Exception e)
{
string error = e.Message.ToString();
}
}
if (inputSplit.Length == 3)
{
return pos;
}
return Coordinate;
}
}
}
}