command line argument for singleplayer, default ip

This commit is contained in:
Baipyrus 2022-10-07 13:12:42 +02:00
parent 6d525344b5
commit 21803868e0
2 changed files with 30 additions and 9 deletions

View File

@ -17,7 +17,15 @@ namespace SnakeGame {
private static bool gameOver, isReady, isMultiplayer;
private static Snake self = new(width/2, height/2);
private static void Main() {
private static void Main(string[] args) {
// Check CL_Args for parameters
bool doSingleplayer = true;
foreach (string arg in args)
if (arg == "-s" || arg == "--single") {
doSingleplayer = false;
break;
}
// Calculate the number of milliseconds in which to display 1 frame
int frameMills = 1000 / FPS;
@ -30,7 +38,7 @@ namespace SnakeGame {
// Decide on Single- or Multiplayer version
Console.Clear();
while (true) {
while (doSingleplayer) {
Console.Clear();
Console.WriteLine("################################");
Console.WriteLine("Art des Spielens:");

View File

@ -20,15 +20,28 @@ Connection.messageEvents.Add(new MessageEvent("PlayerReady", playerDetectReady))
Connection.messageEvents.Add(new MessageEvent("FoodUpdate", foodUpdateRedirect));
Connection.messageEvents.Add(new MessageEvent("ListLobbies", playerListLobbies));
// Check CL_Args for parameters
bool defaultIP = true;
string[] CL_Args = Environment.GetCommandLineArgs();
foreach (string arg in CL_Args)
if (arg == "-y" || arg == "--yes") {
defaultIP = false;
break;
}
// Start the Server itself
Console.Write($"Use '{Connection.ipAddress}:{Connection.port}'? (Y/n) ");
string uIn = Console.ReadLine();
if (uIn.ToLower() == "n") {
Console.WriteLine("Input IP and Port in the following Format:");
Console.Write("( Format 'IPv4:Port' ): ");
uIn = Console.ReadLine();
Connection.ParseIPandPort(uIn);
if (defaultIP) {
Console.Write($"Use '{Connection.ipAddress}:{Connection.port}'? (Y/n) ");
string uIn = Console.ReadLine();
if (uIn.ToLower() == "n") {
Console.WriteLine("Input IP and Port in the following Format:");
Console.Write("( Format 'IPv4:Port' ): ");
uIn = Console.ReadLine();
Connection.ParseIPandPort(uIn);
}
}
// Output selected IP and Port
Console.Clear();
Console.WriteLine("Server Started . . . ");
Console.WriteLine($"Using '{Connection.ipAddress}:{Connection.port}'.");