I'm trying to make an idle game, but I don't know how to run 2 scripts at the same time.
Scripts:
1. (Main Program):
2. (Money generator script):
I'm trying to get the scripts to communicate and run at the same time? I don't know how though, please help. Thanks!
Scripts:
1. (Main Program):
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using ClassLibrary;
using System.Threading.Tasks;
using System.Security.Cryptography;
namespace GameMain
{
class Game
{
public static convertToMiliseconds convert = new convertToMiliseconds();
static void Main(string[] args)
{
Start:
string input = Start();
Console.Clear();
if (input == "Start" || input == "start")
{
countdown(10);
Console.Clear();
Console.ForegroundColor = ConsoleColor.White;
//Call other script to generate money
}
else if (input == "Exit" || input == "exit")
{
return;
}
else
{
goto Start;
}
Console.ReadLine();
}
static string Start()
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Idle ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Loading");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("...");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("\nBy ");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("HubStudios\n\n");
Console.Write("Input: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Exit ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("Start");
Console.ForegroundColor = ConsoleColor.White;
Console.Write(": ");
string input = Console.ReadLine();
return input;
}
public static void countdown(int timerLength)
{
double percent1 = 0;
int counter1 = 0;
double percent2 = 0;
int counter2 = 0;
double percent3 = 0;
for (int i = timerLength; i < 20; i--)
{
Console.Write("Loading: ");
Console.Write(i);
if (i <= 3 && i > 1)
{
Console.WriteLine("\n\nFinishing Up");
percent3 += 33.33;
Console.WriteLine("Finishing: {0}%", percent3);
}
else if (i <= 6 && i > 3)
{
Console.WriteLine("\n\nLoading Scripts");
percent2 += 33.33;
Console.WriteLine("Scripts: {0}%", percent2);
string script = GetUniqueKey(2500);
if (counter2 == 0)
{
Console.WriteLine("\n\nLoading: {0}", script);
}
else if (counter2 == 1)
{
Console.WriteLine("\n\nLoading: {0}", script);
}
else if (counter2 == 2)
{
Console.WriteLine("\n\nLoading: {0}", script);
}
counter2 += 1;
}
else if (i <= 9 && i > 6)
{
Console.WriteLine("\n\nStarting Console");
percent1 += 33.33;
Console.WriteLine("Console: {0}%", percent1);
if (counter1 == 0)
{
Console.WriteLine("\n\nLoading settings.dll");
}
else if (counter1 == 1)
{
Console.WriteLine("\n\nCompiling script data");
}
else if (counter1 == 2)
{
Console.WriteLine("\n\nRendering fonts");
}
counter1 += 1;
}
if (i == 1)
{
Console.WriteLine("\n\nFinishing Up");
percent3 += 33.33;
Console.WriteLine("Finishing: {0}%", percent3);
Thread.Sleep(1000);
Console.Clear();
starting(); starting();
return;
}
Thread.Sleep(1000);
Console.Clear();
}
}
public static string GetUniqueKey(int size)
{
char[] chars =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
byte[] data = new byte[size];
using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider())
{
crypto.GetBytes(data);
}
StringBuilder result = new StringBuilder(size);
foreach (byte b in data)
{
result.Append(chars[b % (chars.Length)]);
}
return result.ToString();
}
static void starting()
{
Console.WriteLine("-=-");
Console.WriteLine("starting");
Thread.Sleep(500);
Console.Clear();
Console.WriteLine("-=-");
Console.WriteLine("starting.");
Thread.Sleep(500);
Console.Clear();
Console.WriteLine("-=-");
Console.WriteLine("starting..");
Thread.Sleep(500);
Console.Clear();
Console.WriteLine("-=-");
Console.WriteLine("starting...");
Thread.Sleep(500);
Console.Clear();
}
}
}
2. (Money generator script):
C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MoneyScript
{
class Program
{
public static int money;
static void Main(string[] args)
{
bool starting = true;
while (starting)
{
money++;
Thread.Sleep(2500);
}
}
}
}
I'm trying to get the scripts to communicate and run at the same time? I don't know how though, please help. Thanks!