Re: [C#] Bomb the World! [First app]
The source:
PHP Code:
using System;
using System.IO;
using Ini;
class SignIn
{
static void Main()
{
Login Main = new Login();
Main.checkDebug();
Main.checkBinDir();
Main.showWelcome();
}
}
class Uses
{
bool Dbg = false;
public int CalcNR(int age, int birthYear) //Not really used
{
return age * birthYear;
}
public bool setBool(bool setTo)
{
return Dbg = setTo;
}
public bool Debug()
{
return Dbg;
}
public void Wait(int msec)
{
System.Threading.Thread.Sleep(msec);
}
}
class Login
{
Uses Use = new Uses();
bool LoggedIn = false;
string User = null;
public Login()
{
//Constructor
}
public string path()
{
if (Use.Debug())
{
return Directory.GetCurrentDirectory() + "../../../bin/Release/bin/";
}
else
{
return "bin/";
}
}
public void checkDebug()
{
string str = null;
if (Use.Debug())
{
Console.Write("Debug mode is on! This will !NOT! function! Type 'y' to turn it off!" + Environment.NewLine);
Console.Write("After this, see if EliteGM has uploaded a fixed version!" + Environment.NewLine + Environment.NewLine);
Console.Write("Answer: ");
str = Console.ReadLine();
if (str == "y")
{
Use.setBool(false);
Console.Clear();
}
else if (str == "n")
{
Console.Clear();
}
else
{
Console.Clear();
Environment.Exit(1);
}
}
}
public void checkBinDir()
{
IniFile SW = new IniFile(path() + "Users.ini");
if (!Directory.Exists(path()))
{
DirectoryInfo di = Directory.CreateDirectory(path());
SW.IniWriteValue("John", "Username", "John");
SW.IniWriteValue("John", "Password", "abcd");
}
}
public void showWelcome()
{
string Opt = null;
Console.Write("Welcome!");
Console.Write(Environment.NewLine + Environment.NewLine);
if (!this.LoggedIn)
{
Console.Write("1. Login" + Environment.NewLine);
Console.Write("2. Create new user" + Environment.NewLine);
Console.Write("3. Exit" + Environment.NewLine + Environment.NewLine);
Console.Write("Choose an option: ");
Opt = Console.ReadLine();
this.checkEmpty(Opt);
if (Opt == "1")
{
Console.Clear();
this.logIn();
}
else if (Opt == "2")
{
Console.Clear();
this.newUser();
}
else if (Opt == "3")
{
Console.Write("Closing... ");
Use.Wait(1000);
Console.Write("Success!");
Use.Wait(50);
Environment.Exit(1);
}
else
{
Console.Write("Incorrect number!");
Use.Wait(500);
Console.Clear();
this.showWelcome();
}
}
else
{
Console.Write("1. Delete user(s)" + Environment.NewLine);
Console.Write("2. Back to user menu" + Environment.NewLine);
Console.Write("3. Logout" + Environment.NewLine + Environment.NewLine);
Console.Write("Choose an option: ");
Opt = Console.ReadLine();
this.checkEmpty(Opt);
if (Opt == "1")
{
Console.Clear();
this.deleteUsers();
}
else if (Opt == "2")
{
Console.Clear();
this.showOpts(User);
}
else if (Opt == "3")
{
Console.Write("Logging out... ");
Use.Wait(1000);
Console.Write("Success!");
Use.Wait(50);
Console.Clear();
this.LoggedIn = false;
this.User = null;
this.showWelcome();
}
else
{
Console.Write("Incorrect number!");
Console.Clear();
this.showWelcome();
}
}
}
public void checkEmpty(string str)
{
if (str == "")
{
Console.Clear();
this.showWelcome();
}
}
public void deleteUsers()
{
Console.Write("Comming SOON!");
Use.Wait(2000);
Console.Clear();
this.showWelcome();
}
protected void newUser()
{
IniFile SW = new IniFile(path() + "Users.ini");
string Read = null;
string User = null;
string Read2 = null;
Console.Write("Please Fill in all information!" + Environment.NewLine + Environment.NewLine);
Console.Write("Username: ");
Read = Console.ReadLine();
User = Read;
this.checkEmpty(User);
Console.Write("Password: ");
Read2 = Console.ReadLine();
this.checkEmpty(Read2);
if (SW.IniReadValue(User, "Username") != User)
{
SW.IniWriteValue(User, "Username", User);
SW.IniWriteValue(User, "Password", Read2);
}
else
{
Console.Write("Username already in use!");
Use.Wait(500);
Console.Clear();
this.newUser();
}
Console.Write(Environment.NewLine + Environment.NewLine);
Console.Write("Press ENTER to go to the Login..");
Console.ReadLine();
Console.Clear();
this.logIn();
}
public void logIn()
{
string User = "";
Console.Write("Please Login!");
Console.Write(Environment.NewLine + Environment.NewLine);
Console.Write("Username: ");
User = Console.ReadLine();
this.checkEmpty(User);
this.checkInfo(User);
}
public void checkInfo(string input)
{
IniFile SW = new IniFile(path() + "Users.ini");
string Read = SW.IniReadValue(input, "Username");
string Read2 = SW.IniReadValue(input, "Password");
string Pass = null;
if (input == Read)
{
Console.Write("Password: ");
Pass = Console.ReadLine();
if (Pass == Read2)
{
Console.Write("Successfully logged in!");
Use.Wait(1000);
Console.Clear();
this.LoggedIn = true;
this.User = Read;
this.showOpts(User);
}
else
{
Console.Write("Error! Incorrect password.");
Console.Write(Environment.NewLine);
this.checkInfo(input);
}
}
else
{
Console.Write("Error! Incorrect username.");
Console.Write(Environment.NewLine);
}
}
public void showOpts(string name)
{
string Number = "";
Console.Write("Greetings, " + name + ". What would you like to do?");
Console.Write(Environment.NewLine + Environment.NewLine);
Console.Write("1. Bomb America" + Environment.NewLine);
Console.Write("2. Bomb the UK" + Environment.NewLine);
Console.Write("3. Bomb Russia" + Environment.NewLine);
Console.Write("4. Bomb Europe" + Environment.NewLine);
Console.Write("5. Bomb ... (please specify)" + Environment.NewLine + Environment.NewLine);
Console.Write("6. Exit to main menu" + Environment.NewLine);
Console.Write("7. Exit" + Environment.NewLine + Environment.NewLine);
Console.Write("Choose an option: ");
Number = Console.ReadLine();
this.checkEmpty(Number);
if (Number == "1" || Number == "2" || Number == "3" || Number == "4")
{
Console.Write(Environment.NewLine);
Console.Write("Bombing... ");
Use.Wait(750);
Console.Write("Success!");
Use.Wait(500);
Console.Clear();
this.showOpts(User);
}
else if (Number == "6")
{
Console.Clear();
this.showWelcome();
}
else if (Number == "7")
{
Console.Write("Closing... ");
Use.Wait(1000);
Console.Write("Success!");
Use.Wait(50);
Environment.Exit(1);
}
else if (Number == "5")
{
Console.Write("5. Bomb ");
string Bomb = Console.ReadLine();
Console.Write("Bombing " + Bomb + "... ");
Use.Wait(750);
Console.Write("Success!");
Use.Wait(500);
Console.Clear();
this.showOpts(User);
}
else
{
Console.Write("Incorrect number!");
Use.Wait(500);
Console.Clear();
this.showOpts(User);
}
}
}
Bit complicated but w/e :P
If you press F5 to debug it, make sure that in the "Uses" class "bool dbg = true" !!!
When building it for releasing set it to false !!
Re: [C#] Bomb the World! [First app]
UPDATE:
Now saves the users to "Users.ini"
Added INFO in main post!
Re: [C#] Bomb the World! [First app]
Nice job. Works pretty good.
Its really simppple though.
Maybe make the bombing fail sometimes?
8/10
Re: [C#] Bomb the World! [First app]
It's cool, keep learning..
Makes me want to play BombStoppers tho :P
Re: [C#] Bomb the World! [First app]
Nice, you should add "Already bombed " + country.
But nice anyway.
Re: [C#] Bomb the World! [First app]