I try to transition a Monopoly Banking python programming I made into C#.
I used the main module is where I declare all my global variables, however, I don't quite understand how to call a module in another module without all the required variables passed into it.
For example on line 50 i try running SetCustom module however i don't have all the parameters that are required passed into MainMenu, I really don't wanna pass every Parameter into every module cause that just ends in mess and confusion. Is there away i can work around this or do i have to do everything messy?
Thanks in advance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MonopolyCSharpNonForm
{
class Program
{
static void Main(string[] args)
{
//Primary Settings
int StartingBallance = 2000;
int PassGo = 200;
int Bail = 50;
int IncomeTax = 100;
int SuperTax = 200;
string TaxLocation = 1; // 1 goes to the bank
//Players/Economy
string Player1 = "Player1";
string Player2 = "";
string Player3 = "";
string Player4 = "";
int Ballance1 = 2000;
int Ballance2 = 2000;
int Ballance3 = 2000;
int Ballance4 = 2000;
int FreeParking = 0;
string[] BankRupties = { };
MainMenu(); // Calling Main Menu
}
static void MainMenu()
{
Console.WriteLine("Welcome to Monpoly Banker V4");
Console.WriteLine("Would you to use the Default or Custom settings?"); //Ask for Default or Custom option
string LocalOption = Console.ReadLine(); //Record the option as a local variable 'LocalOption'
while (LocalOption != "Default" && LocalOption != "Custom")//Check if LocalOption is 'Default' or 'Custom'
{
Console.WriteLine("Niether option has been specified, type 'Default' or 'Custom'"); // If not state there is an Error.
LocalOption = Console.ReadLine(); //Record the input again.
}
if (LocalOption == "Custom") // Check if local variable is equal to custom.
{
SetCustom(ref StartingBallance, ref PassGo, ref Bail, ref IncomeTax, ref SuperTax, ref TaxLocation); //If it is run the SetCustom module below with the required parameters
}
else //Anything else it runs GettingNames module with required parameters
{
GettingNames(ref Player1, ref Player2, ref Player3, ref Player4);
}
}
static void SetCustom(ref int StartingBallance, ref int PassGo, ref int Bail, ref int IncomeTax, ref int SuperTax, ref string TaxLocation)
{
Console.WriteLine("\nHow much money is everyone starting with? "); // Ask for Starting Ballance
StartingBallance = Convert.ToInt32(Console.ReadLine()); // Change the StartingBallance to entered integer
Console.WriteLine("\nHow much money if you pass go? "); // Ask how much you get for passing go
PassGo = Convert.ToInt32(Console.ReadLine()); // change PassGo to entered integer
Console.WriteLine("\nHow much will bail cost? "); // Ash how much Bail is going to cost
Bail = Convert.ToInt32(Console.ReadLine()); // change Bail to entered integer
Console.WriteLine("\nHow much will income tax cost? "); // Ask how much Income Tax will cost
IncomeTax = Convert.ToInt32(Console.ReadLine()); // Change IncomeTax to entered Integer
Console.WriteLine("\nHow much will super tax cost? "); // Ask how much Super Tax will cost
SuperTax = Convert.ToInt32(Console.ReadLine()); // Record the entered integer
Console.WriteLine("\nDoes tax go to the bank for free parking? (1 = Bank | 2 = Free Parking)"); // Ask for where free parking will go (1/2 to make options easier)
TaxLocation = Console.ReadLine(); // Change TaxLocation to entered String
while (TaxLocation != "1" && TaxLocation != "2") // Check TaxLocation is either '1' or '2'
{
Console.WriteLine("Invalid Input. Try again."); // If not state its invalid input
TaxLocation = Console.ReadLine(); // Record entered Integer
}
GettingNames(ref Player1, ref Player2, ref Player3, ref Player4); // When done continue on to module Getting Names passing required parameters
}
static void GettingNames(ref string Player1, ref string Player2, ref string Player3, ref string Player4)
{
Console.WriteLine("\nWhat is Player1 name? "); // Ask Player1 name
Player1 = Console.ReadLine(); // Set Player1 to entered string
Console.WriteLine("\nWhat is Player2 name? "); // Ask Player2 name
Player2 = Console.ReadLine(); // Set Player1 to entered string
Console.WriteLine("\nWhat is Player3 name? "); // Ask Player3 name
Player3 = Console.ReadLine(); // Set Player1 to entered string
Console.WriteLine("\nWhat is Player4 name? "); // Ask Player4 name
Player4 = Console.ReadLine(); // Set Player1 to entered string
Console.WriteLine("All 4 player names have been entered."); // State all names entered and received
}
}
}