Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Boat
- {
- public class Places
- {
- public int radarLocation;
- public int numberOfFighters;
- public static int difficulity;
- }
- public class HuntersLagoone : Places
- {
- public int radarLocation = 0;
- public int numberOfFighters = 0;
- public static int difficulity = 2;
- }
- public class Swift : Places
- {
- public int radarLocation = 1;
- public int numberOfFighters = 1;
- public static int difficulity = 6;
- }
- public class BoatInfo
- {
- public const string connectionString = @"Integrated Security=SSPI;Persist Security Info=False;User ID=Dennis;Initial Catalog=GameDB;Data Source=ASUS\SQLEXPRESS";
- public static int numberOfWorkers;
- public static int levelOfRadar;
- public static int levelOfLivingPlace;
- public int levelOfGunShop;
- public static int cash;
- public static bool cooldown;
- public static int signedIn;
- public static void Register()
- {
- Console.Write("Type Your User Name: ");
- string NAM = Console.ReadLine();
- Console.WriteLine(" ");
- Console.Write("And now your password: ");
- string password = Console.ReadLine();
- BoatInfo.SaveUser(password, NAM);
- Console.WriteLine("Continuing...");
- }
- ////////////////////////////////// STORED PROCEDURE BLOCK ///////////////////////////////////////////
- //public static void SaveBoatInfo() & GetBoatInfo()
- public static void SaveUser(string PASS,string name)
- {
- DataSet ds = new DataSet();
- const string savedData = "usp_UserSaveData";
- const string users = "Users";
- using (SqlConnection conn = new SqlConnection(connectionString))
- {
- try
- {
- using (SqlDataAdapter da = new SqlDataAdapter())
- {
- da.SelectCommand = new SqlCommand(savedData, conn);
- da.SelectCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter pass = da.SelectCommand.Parameters.Add("@pass", System.Data.SqlDbType.NVarChar,100);
- pass.Direction = ParameterDirection.Input;
- pass.Value = PASS;
- SqlParameter Name = da.SelectCommand.Parameters.Add("@name", System.Data.SqlDbType.NVarChar,100);
- Name.Direction = ParameterDirection.Input;
- Name.Value = name;
- da.Fill(ds);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Saving the data was unsuccesful. starting a new game..." + e.Message);
- }
- foreach (DataRow dr in ds.Tables[0].Rows)
- {
- signedIn = Convert.ToInt32(dr["id"]);
- }
- }
- }
- public static void SaveBoatInfo(int NumberOfWorkers, int LevelOfRadar, int LevelOfLivingPlace, int Cash,int id)
- {
- DataSet ds = new DataSet();
- const string savedData = "usp_SaveBoatInfo";
- const string users = "Users";
- using (SqlConnection conn = new SqlConnection(connectionString))
- {
- try
- {
- using (SqlDataAdapter da = new SqlDataAdapter())
- {
- da.SelectCommand = new SqlCommand(savedData, conn);
- da.SelectCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter numberofworkers = da.SelectCommand.Parameters.Add("@numberOfWorkers", System.Data.SqlDbType.Int);
- numberofworkers.Direction = ParameterDirection.Input;
- numberofworkers.Value = NumberOfWorkers;
- SqlParameter levelofradar = da.SelectCommand.Parameters.Add("@levelOfRadar", System.Data.SqlDbType.Int);
- levelofradar.Direction = ParameterDirection.Input;
- levelofradar.Value = levelOfRadar;
- SqlParameter leveloflivingplace = da.SelectCommand.Parameters.Add("@levelOfLivingPlace", System.Data.SqlDbType.Int);
- leveloflivingplace.Direction = ParameterDirection.Input;
- leveloflivingplace.Value = LevelOfLivingPlace;
- SqlParameter cash = da.SelectCommand.Parameters.Add("@cash", System.Data.SqlDbType.Int);
- cash.Direction = ParameterDirection.Input;
- cash.Value = Cash;
- SqlParameter whom = da.SelectCommand.Parameters.Add("@b_id", System.Data.SqlDbType.Int);
- whom.Direction = ParameterDirection.Input;
- whom.Value = id;
- da.Fill(ds);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("saving the data was unsuccesful. starting a new game..." + e.Message);
- }
- }
- Console.WriteLine("Data has been saved");
- }
- public static void GetBoatInfo(string username, string password)
- {
- DataSet ds = new DataSet();
- const string savedData = "usp_GetBoatInfo";
- const string users = "Users";
- using (SqlConnection conn = new SqlConnection(connectionString))
- {
- try
- {
- using (SqlDataAdapter da = new SqlDataAdapter())
- {
- da.SelectCommand = new SqlCommand(savedData, conn);
- da.SelectCommand.CommandType = CommandType.StoredProcedure;
- SqlParameter sql_username = da.SelectCommand.Parameters.Add("@g_username", System.Data.SqlDbType.NVarChar,100);
- sql_username.Direction = ParameterDirection.Input;
- sql_username.Value = username;
- SqlParameter sql_password = da.SelectCommand.Parameters.Add("@g_password", System.Data.SqlDbType.NVarChar, 100);
- sql_password.Direction = ParameterDirection.Input;
- sql_password.Value = password;
- da.Fill(ds);
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Loading the data was unsuccesful. starting a new game..." + e.Message);
- Console.WriteLine("Or maybe you're registering an existing account");
- }
- foreach (DataRow dr in ds.Tables[0].Rows) /////פה זה רץ פשוט על כל הסלקט שעשיתי בסטורד פרוסידור
- {
- Console.WriteLine("Data took succesfully");
- cash = Convert.ToInt32(dr["s_Cash"]);
- numberOfWorkers = Convert.ToInt32(dr["s_numberOfWorkers"]);
- levelOfRadar = Convert.ToInt32(dr["s_levelOfRadar"]);
- levelOfLivingPlace = Convert.ToInt32(dr["s_levelOfLivingPlace"]);
- int id = Convert.ToInt32(dr["playerId"]);
- BoatInfo.signedIn = id;
- }
- }
- if(cash == 0 && numberOfWorkers == 0 && levelOfRadar == 0 && levelOfLivingPlace == 0)
- {
- Console.WriteLine("Sorry, it appears your \npass or username is incorrect");
- Console.WriteLine("If your cash is 0, and it's actually not 0, you might want to \ntry again.");
- }
- }
- /////////////////////////////////////////////// END OF STORED PROCEDURE BLOCK ////////////////////////////////////
- public BoatInfo()
- {
- levelOfGunShop = 1;
- }
- }
- class Program
- {
- public const double VERSION = 1.2;
- static void Main(string[] args)
- {
- Console.WriteLine("Boats! Press 'Enter' To Continue");
- Console.ReadKey();
- Console.WriteLine("Signin or register?");
- string input = Console.ReadLine();
- if (input.ToUpper() == "SIGNIN")
- {
- Console.Write("Type in your username: ");
- string un = Console.ReadLine();
- Console.Write("Type in your password: ");
- string p = Console.ReadLine();
- BoatInfo.GetBoatInfo(un, p);
- if (BoatInfo.signedIn == 10000)
- {
- Console.WriteLine("Sorry, password or username is not correct. Registering...");
- Console.WriteLine("if you don't wish to register, exit the program.");
- BoatInfo.Register();
- }
- }
- else if (input.ToUpper() == "REGISTER" || BoatInfo.signedIn <= -1)
- {
- BoatInfo.Register();
- }
- else
- Console.WriteLine("Try Again.");
- Console.ReadKey();
- Console.WriteLine("");
- BoatInfo Dennis = new BoatInfo();
- bool gameIsWorking = true;
- if(BoatInfo.signedIn <= -1 )
- {
- Console.WriteLine("Sorry, you didn't sign in. please exit. and try again.");
- Console.ReadLine();
- }
- while (BoatInfo.signedIn > 0)
- {
- Console.WriteLine(" ");
- Console.WriteLine("What Do You Wish To Know? (Info,Attack,Shop,Help,Save,Load(to sign in to anotheraccount) \nTo Quit However, Type Exit.)");
- string choosed = Console.ReadLine();
- Console.WriteLine(" ");
- switch (choosed.ToUpper())
- {
- case "LOAD":
- Console.WriteLine("Awww sorry... i'm too lazy to make a function to do that, \nso just type 'exit' and re-enter the program...");
- break;
- case "SAVE":
- BoatInfo.SaveBoatInfo(BoatInfo.numberOfWorkers, BoatInfo.levelOfRadar, BoatInfo.levelOfLivingPlace, BoatInfo.cash,BoatInfo.signedIn);
- break;
- case "INFO":
- Console.WriteLine("Number Of Workers:" + BoatInfo.numberOfWorkers + " " + "\nRadar Lvl:" + BoatInfo.levelOfRadar + " " + "\nLiving Place Lvl:" + BoatInfo.levelOfLivingPlace + " " + "\nGun Shop Lvl:" + Dennis.levelOfGunShop +" " +"\nCash:" + BoatInfo.cash );
- break;
- case "ATTACK":
- if (BoatInfo.cooldown == false)
- {
- for (int i = 0; i < 1; i++)
- {
- Console.WriteLine(" ");
- Console.WriteLine("Choose the place you want to get to, for your workers to hunt the fish you wish.");
- Console.WriteLine(" ");
- Console.WriteLine("Sometimes you are too strong to catch a small fish. that's why you won't be able to catch\n an easy fish.");
- Console.WriteLine(" ");
- Console.WriteLine("Available: HuntersLagoone, Swift.");
- string choosenPlace = Console.ReadLine();
- ////////////////Locations Requieremtns And Difficulity and Awards///////////////
- switch (choosenPlace.ToUpper())
- {
- case "HUNTERSLAGOONE":
- Console.WriteLine(" ");
- Console.WriteLine("Requieremtns: \nRadar Lvl: 0 \nNumber Of Workers: 0 \nDifficulity: 2 \nReward: 2000$");
- Console.WriteLine("Since it's the first place to go, you don't need a radar or workers. \njust you, the captain, and you trusty sword!");
- break;
- case "SWIFT":
- Console.WriteLine(" ");
- Console.WriteLine("Requieremtns: \nRadar Lvl: 1 \nNumber Of Workers: 1 \nDifficulity: 6 \nReward: 6000$ ");
- break;
- }
- /////////////////////////////////////////////////////////////////////
- bool result = IsPermmited(BoatInfo.numberOfWorkers, BoatInfo.levelOfRadar, choosenPlace);
- if (result == true)
- {
- Console.WriteLine(" ");
- Console.WriteLine("Press 'Enter' to enter, or 'return' to return to your boat.");
- string act = Console.ReadLine();
- if (act.ToUpper() == "")
- {
- if(choosenPlace.ToUpper() == "HUNTERSLAGOONE")
- {
- Places.difficulity = HuntersLagoone.difficulity;
- }
- else if(choosenPlace.ToUpper() == "SWIFT")
- {
- Places.difficulity = Swift.difficulity;
- }
- int EarnedCash = Fight(Places.difficulity); //diff + 1 as parameter for diff//
- if (EarnedCash == 0)
- {
- Console.WriteLine("After You fought, it appears that you didn't catch any fish, \nand therefore you didn't earn anything.");
- BoatInfo.cash = (EarnedCash + BoatInfo.cash);
- BoatInfo.cooldown = true;
- }
- else
- {
- Console.WriteLine("You have earned: " + EarnedCash + "$ !");
- BoatInfo.cash = (EarnedCash + BoatInfo.cash);
- BoatInfo.cooldown = true;
- }
- }
- else
- continue;
- }
- else
- {
- Console.WriteLine(" ");
- Console.WriteLine("Sorry, but you do not meet the requirments. \nUpgrade Workers Or The Radar! (or don't just press enter)");
- }
- }
- }
- else if (BoatInfo.cooldown == true)
- {
- DateTime now = DateTime.Now;
- int thisnum = now.Second;
- Console.WriteLine("Your Workers are tired. they will be able to fight in about 1 minute.");
- Console.WriteLine("");
- Console.WriteLine("Sometimes they are really tired, and sometimes they just needed that one second break.");
- System.DateTime moment = new System.DateTime(2015, 12, 15, 17, 17, 10 + 30, 0); //change the (30) to make longer wait-times. 30>x longer, 30<x shorter
- int second = moment.Second;
- if(thisnum <= second)
- {
- BoatInfo.cooldown = false;
- }
- }
- break;
- case "SHOP":
- Console.WriteLine("Welcome To The Upgrade Shop! you have: " + BoatInfo.cash+"$ !");
- Console.WriteLine(" ");
- Console.WriteLine("Number Of Workers:" + BoatInfo.numberOfWorkers.ToString() + " " + "\nRadar Lvl:" + BoatInfo.levelOfRadar.ToString() + " " + "\nLiving Place Lvl:" + BoatInfo.levelOfLivingPlace.ToString());
- Console.WriteLine(" ");
- Console.WriteLine("Which thing will you upgrade? notes:\n (before having 4 workers, you must have living place lvl 2)");
- Console.WriteLine(" ");
- Console.WriteLine("To Buy A Worker: type NOW. \nTo Upgrade Radar Level: type RLV. \nTo Upgrade Living Place Level: type LPL. \nTo Leave Type Exit.");
- string desiredUpgrade = Console.ReadLine();
- switch(desiredUpgrade.ToUpper())
- {
- case "NOW":
- Console.WriteLine(" ");
- Console.WriteLine("A new worker is costing 9,000$");
- Console.WriteLine(" ");
- Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
- int l = 1;
- string fsure = Console.ReadLine();
- if (fsure == "" && BoatInfo.cash >= 9000)
- {
- l++;
- if (BoatInfo.numberOfWorkers == 4 * l && BoatInfo.levelOfLivingPlace > 1 * l) // put = if mistaken.
- {
- Console.WriteLine("You can't purchase more workers if your living place is level 1");
- }
- else
- {
- BoatInfo.cash = BoatInfo.cash - 9000;
- BoatInfo.numberOfWorkers = BoatInfo.numberOfWorkers + 1;
- Console.WriteLine("You now have: {0} Workers!", BoatInfo.numberOfWorkers);
- }
- }
- else if(BoatInfo.cash < 9000 && fsure == "")
- {
- Console.WriteLine("You don't have enough cash.");
- }
- else
- continue;
- break;
- case "RLV":
- Console.WriteLine(" ");
- Console.WriteLine("Radar Upgrade Lvl is Costing 10,000$");
- Console.WriteLine(" ");
- Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
- string qsure = Console.ReadLine();
- if (qsure == "" && BoatInfo.cash >= 10000)
- {
- BoatInfo.cash = BoatInfo.cash - 10000;
- BoatInfo.levelOfRadar = BoatInfo.levelOfRadar + 1;
- Console.WriteLine("Purchase Was Completed!");
- }
- else if(BoatInfo.cash < 10000 && qsure == "")
- {
- Console.WriteLine("You don't have enough cash.");
- }
- else
- continue;
- break;
- case "LPL":
- Console.WriteLine(" ");
- Console.WriteLine("Living Place Upgrade Lvl Is Costing 50,000$");
- Console.WriteLine(" ");
- Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
- string lsure = Console.ReadLine();
- if (lsure == "" && BoatInfo.cash > 50000)
- {
- BoatInfo.cash = BoatInfo.cash - 50000;
- BoatInfo.levelOfLivingPlace = BoatInfo.levelOfLivingPlace + 1;
- Console.WriteLine("Your Living Place Lvl Is Now {0} ", BoatInfo.levelOfLivingPlace = BoatInfo.levelOfLivingPlace + 1);
- }
- else if(BoatInfo.cash < 50000 && lsure == "")
- {
- Console.WriteLine("You don't have enough cash.");
- }
- else
- continue;
- break;
- case "EXIT":
- continue;
- }
- break;
- case "EXIT":
- BoatInfo.signedIn = -1;
- Environment.Exit(0);
- break;
- case "HELP":
- Console.WriteLine("This is Version {0}, Creator: Dennis.",VERSION);
- Console.WriteLine("If you have any questions please ask me and i will try to answer.\nthese questions will be put here for your better understanding this simple game\nand don't forget to tell me any bugs you encounter!");
- Console.WriteLine(" ");
- Console.WriteLine("Future Updates Are Coming Soon!");
- Console.WriteLine("Update notes: \nVersion 1.2: *Some minor changes.");
- Console.WriteLine("Press 'Enter' To continue.");
- break;
- }
- Console.ReadKey();
- }
- }
- public static bool IsPermmited(int NumberOfWorkers, int RadarLvl,string choosenPlace)
- {
- switch (choosenPlace.ToUpper())
- {
- case "HUNTERSLAGOONE":
- HuntersLagoone nl = new HuntersLagoone();
- if (nl.numberOfFighters <= NumberOfWorkers && nl.radarLocation <= RadarLvl)
- {
- return true;
- }
- else if(nl.numberOfFighters < NumberOfWorkers)
- {
- return false;
- }
- else
- {
- return false;
- }
- break;
- case "SWIFT":
- Swift ns = new Swift();
- if (ns.numberOfFighters <= NumberOfWorkers && ns.radarLocation <= RadarLvl)
- {
- return true;
- }
- else
- return false;
- break;
- }
- return false;
- }
- public static int Fight(int diff)
- {
- Console.WriteLine("You have found some fish, to attack, press enter. \nand as always type exit to leave. ");
- string input = Console.ReadLine();
- if (input.ToUpper() == "EXIT")
- return 0;
- else if(input == "")
- {
- Random rnd = new Random();
- BoatInfo forfight = new BoatInfo();
- int health = (BoatInfo.numberOfWorkers * 2);
- for (int i = 0; i <= health; i++)
- {
- int chance = rnd.Next(0, diff);
- if(BoatInfo.numberOfWorkers > diff)
- {
- diff = diff + 2;
- i = 0;
- continue;
- }
- if (chance == BoatInfo.numberOfWorkers)
- {
- Console.WriteLine("You Have Succeded. you have been awarded.");
- Console.WriteLine("Returning to the boat...");
- Console.ReadKey();
- return 1000 * diff;
- }
- else
- {
- Console.WriteLine("Sorry, you didn't catch any fish. \nand you lost some life");
- Console.WriteLine("Continuing..");
- Console.ReadKey();
- i++;
- if(i == health)
- return 0;
- }
- }
- return 0;
- }
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement