Advertisement
Guest User

hallo

a guest
Jan 15th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace Boat
  10. {
  11.  
  12. public class Places
  13. {
  14. public int radarLocation;
  15. public int numberOfFighters;
  16. public static int difficulity;
  17.  
  18.  
  19. }
  20. public class HuntersLagoone : Places
  21. {
  22. public int radarLocation = 0;
  23. public int numberOfFighters = 0;
  24. public static int difficulity = 2;
  25.  
  26. }
  27. public class Swift : Places
  28. {
  29. public int radarLocation = 1;
  30. public int numberOfFighters = 1;
  31. public static int difficulity = 6;
  32. }
  33.  
  34. public class BoatInfo
  35. {
  36. public const string connectionString = @"Integrated Security=SSPI;Persist Security Info=False;User ID=Dennis;Initial Catalog=GameDB;Data Source=ASUS\SQLEXPRESS";
  37. public static int numberOfWorkers;
  38. public static int levelOfRadar;
  39. public static int levelOfLivingPlace;
  40. public int levelOfGunShop;
  41. public static int cash;
  42. public static bool cooldown;
  43. public static int signedIn;
  44.  
  45. public static void Register()
  46. {
  47. Console.Write("Type Your User Name: ");
  48. string NAM = Console.ReadLine();
  49. Console.WriteLine(" ");
  50. Console.Write("And now your password: ");
  51. string password = Console.ReadLine();
  52. BoatInfo.SaveUser(password, NAM);
  53. Console.WriteLine("Continuing...");
  54.  
  55. }
  56.  
  57. ////////////////////////////////// STORED PROCEDURE BLOCK ///////////////////////////////////////////
  58.  
  59. //public static void SaveBoatInfo() & GetBoatInfo()
  60. public static void SaveUser(string PASS,string name)
  61. {
  62.  
  63. DataSet ds = new DataSet();
  64. const string savedData = "usp_UserSaveData";
  65. const string users = "Users";
  66.  
  67. using (SqlConnection conn = new SqlConnection(connectionString))
  68. {
  69. try
  70. {
  71. using (SqlDataAdapter da = new SqlDataAdapter())
  72. {
  73. da.SelectCommand = new SqlCommand(savedData, conn);
  74. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  75.  
  76.  
  77.  
  78. SqlParameter pass = da.SelectCommand.Parameters.Add("@pass", System.Data.SqlDbType.NVarChar,100);
  79. pass.Direction = ParameterDirection.Input;
  80. pass.Value = PASS;
  81.  
  82.  
  83. SqlParameter Name = da.SelectCommand.Parameters.Add("@name", System.Data.SqlDbType.NVarChar,100);
  84. Name.Direction = ParameterDirection.Input;
  85. Name.Value = name;
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94. da.Fill(ds);
  95.  
  96.  
  97. }
  98. }
  99. catch (Exception e)
  100. {
  101. Console.WriteLine("Saving the data was unsuccesful. starting a new game..." + e.Message);
  102.  
  103.  
  104. }
  105. foreach (DataRow dr in ds.Tables[0].Rows)
  106. {
  107. signedIn = Convert.ToInt32(dr["id"]);
  108. }
  109.  
  110. }
  111. }
  112. public static void SaveBoatInfo(int NumberOfWorkers, int LevelOfRadar, int LevelOfLivingPlace, int Cash,int id)
  113. {
  114. DataSet ds = new DataSet();
  115. const string savedData = "usp_SaveBoatInfo";
  116. const string users = "Users";
  117.  
  118. using (SqlConnection conn = new SqlConnection(connectionString))
  119. {
  120. try
  121. {
  122. using (SqlDataAdapter da = new SqlDataAdapter())
  123. {
  124. da.SelectCommand = new SqlCommand(savedData, conn);
  125. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  126.  
  127.  
  128.  
  129.  
  130.  
  131. SqlParameter numberofworkers = da.SelectCommand.Parameters.Add("@numberOfWorkers", System.Data.SqlDbType.Int);
  132. numberofworkers.Direction = ParameterDirection.Input;
  133. numberofworkers.Value = NumberOfWorkers;
  134.  
  135. SqlParameter levelofradar = da.SelectCommand.Parameters.Add("@levelOfRadar", System.Data.SqlDbType.Int);
  136. levelofradar.Direction = ParameterDirection.Input;
  137. levelofradar.Value = levelOfRadar;
  138.  
  139. SqlParameter leveloflivingplace = da.SelectCommand.Parameters.Add("@levelOfLivingPlace", System.Data.SqlDbType.Int);
  140. leveloflivingplace.Direction = ParameterDirection.Input;
  141. leveloflivingplace.Value = LevelOfLivingPlace;
  142.  
  143. SqlParameter cash = da.SelectCommand.Parameters.Add("@cash", System.Data.SqlDbType.Int);
  144. cash.Direction = ParameterDirection.Input;
  145. cash.Value = Cash;
  146.  
  147. SqlParameter whom = da.SelectCommand.Parameters.Add("@b_id", System.Data.SqlDbType.Int);
  148. whom.Direction = ParameterDirection.Input;
  149. whom.Value = id;
  150.  
  151.  
  152.  
  153.  
  154.  
  155. da.Fill(ds);
  156. }
  157. }
  158. catch (Exception e)
  159. {
  160. Console.WriteLine("saving the data was unsuccesful. starting a new game..." + e.Message);
  161.  
  162. }
  163.  
  164. }
  165. Console.WriteLine("Data has been saved");
  166. }
  167. public static void GetBoatInfo(string username, string password)
  168. {
  169. DataSet ds = new DataSet();
  170. const string savedData = "usp_GetBoatInfo";
  171. const string users = "Users";
  172.  
  173. using (SqlConnection conn = new SqlConnection(connectionString))
  174. {
  175. try
  176. {
  177. using (SqlDataAdapter da = new SqlDataAdapter())
  178. {
  179. da.SelectCommand = new SqlCommand(savedData, conn);
  180. da.SelectCommand.CommandType = CommandType.StoredProcedure;
  181.  
  182.  
  183.  
  184.  
  185.  
  186. SqlParameter sql_username = da.SelectCommand.Parameters.Add("@g_username", System.Data.SqlDbType.NVarChar,100);
  187. sql_username.Direction = ParameterDirection.Input;
  188. sql_username.Value = username;
  189.  
  190. SqlParameter sql_password = da.SelectCommand.Parameters.Add("@g_password", System.Data.SqlDbType.NVarChar, 100);
  191. sql_password.Direction = ParameterDirection.Input;
  192. sql_password.Value = password;
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200. da.Fill(ds);
  201. }
  202. }
  203. catch (Exception e)
  204. {
  205. Console.WriteLine("Loading the data was unsuccesful. starting a new game..." + e.Message);
  206. Console.WriteLine("Or maybe you're registering an existing account");
  207.  
  208. }
  209.  
  210. foreach (DataRow dr in ds.Tables[0].Rows) /////פה זה רץ פשוט על כל הסלקט שעשיתי בסטורד פרוסידור
  211. {
  212.  
  213. Console.WriteLine("Data took succesfully");
  214. cash = Convert.ToInt32(dr["s_Cash"]);
  215. numberOfWorkers = Convert.ToInt32(dr["s_numberOfWorkers"]);
  216. levelOfRadar = Convert.ToInt32(dr["s_levelOfRadar"]);
  217. levelOfLivingPlace = Convert.ToInt32(dr["s_levelOfLivingPlace"]);
  218. int id = Convert.ToInt32(dr["playerId"]);
  219.  
  220. BoatInfo.signedIn = id;
  221.  
  222. }
  223.  
  224.  
  225.  
  226.  
  227.  
  228. }
  229. if(cash == 0 && numberOfWorkers == 0 && levelOfRadar == 0 && levelOfLivingPlace == 0)
  230. {
  231. Console.WriteLine("Sorry, it appears your \npass or username is incorrect");
  232. Console.WriteLine("If your cash is 0, and it's actually not 0, you might want to \ntry again.");
  233. }
  234. }
  235.  
  236.  
  237.  
  238.  
  239. /////////////////////////////////////////////// END OF STORED PROCEDURE BLOCK ////////////////////////////////////
  240.  
  241.  
  242.  
  243.  
  244. public BoatInfo()
  245. {
  246.  
  247. levelOfGunShop = 1;
  248.  
  249. }
  250.  
  251. }
  252. class Program
  253. {
  254. public const double VERSION = 1.2;
  255.  
  256. static void Main(string[] args)
  257. {
  258.  
  259. Console.WriteLine("Boats! Press 'Enter' To Continue");
  260. Console.ReadKey();
  261. Console.WriteLine("Signin or register?");
  262. string input = Console.ReadLine();
  263. if (input.ToUpper() == "SIGNIN")
  264. {
  265. Console.Write("Type in your username: ");
  266. string un = Console.ReadLine();
  267. Console.Write("Type in your password: ");
  268. string p = Console.ReadLine();
  269. BoatInfo.GetBoatInfo(un, p);
  270. if (BoatInfo.signedIn == 10000)
  271. {
  272.  
  273. Console.WriteLine("Sorry, password or username is not correct. Registering...");
  274. Console.WriteLine("if you don't wish to register, exit the program.");
  275. BoatInfo.Register();
  276. }
  277. }
  278. else if (input.ToUpper() == "REGISTER" || BoatInfo.signedIn <= -1)
  279. {
  280.  
  281. BoatInfo.Register();
  282.  
  283. }
  284. else
  285. Console.WriteLine("Try Again.");
  286.  
  287.  
  288.  
  289.  
  290. Console.ReadKey();
  291.  
  292. Console.WriteLine("");
  293. BoatInfo Dennis = new BoatInfo();
  294.  
  295. bool gameIsWorking = true;
  296. if(BoatInfo.signedIn <= -1 )
  297. {
  298. Console.WriteLine("Sorry, you didn't sign in. please exit. and try again.");
  299. Console.ReadLine();
  300. }
  301. while (BoatInfo.signedIn > 0)
  302. {
  303.  
  304. Console.WriteLine(" ");
  305. Console.WriteLine("What Do You Wish To Know? (Info,Attack,Shop,Help,Save,Load(to sign in to anotheraccount) \nTo Quit However, Type Exit.)");
  306.  
  307.  
  308. string choosed = Console.ReadLine();
  309. Console.WriteLine(" ");
  310. switch (choosed.ToUpper())
  311. {
  312. case "LOAD":
  313. Console.WriteLine("Awww sorry... i'm too lazy to make a function to do that, \nso just type 'exit' and re-enter the program...");
  314. break;
  315. case "SAVE":
  316. BoatInfo.SaveBoatInfo(BoatInfo.numberOfWorkers, BoatInfo.levelOfRadar, BoatInfo.levelOfLivingPlace, BoatInfo.cash,BoatInfo.signedIn);
  317. break;
  318. case "INFO":
  319. Console.WriteLine("Number Of Workers:" + BoatInfo.numberOfWorkers + " " + "\nRadar Lvl:" + BoatInfo.levelOfRadar + " " + "\nLiving Place Lvl:" + BoatInfo.levelOfLivingPlace + " " + "\nGun Shop Lvl:" + Dennis.levelOfGunShop +" " +"\nCash:" + BoatInfo.cash );
  320. break;
  321. case "ATTACK":
  322. if (BoatInfo.cooldown == false)
  323. {
  324. for (int i = 0; i < 1; i++)
  325. {
  326. Console.WriteLine(" ");
  327. Console.WriteLine("Choose the place you want to get to, for your workers to hunt the fish you wish.");
  328. Console.WriteLine(" ");
  329. 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.");
  330. Console.WriteLine(" ");
  331. Console.WriteLine("Available: HuntersLagoone, Swift.");
  332.  
  333. string choosenPlace = Console.ReadLine();
  334.  
  335. ////////////////Locations Requieremtns And Difficulity and Awards///////////////
  336. switch (choosenPlace.ToUpper())
  337. {
  338. case "HUNTERSLAGOONE":
  339. Console.WriteLine(" ");
  340. Console.WriteLine("Requieremtns: \nRadar Lvl: 0 \nNumber Of Workers: 0 \nDifficulity: 2 \nReward: 2000$");
  341. 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!");
  342. break;
  343. case "SWIFT":
  344. Console.WriteLine(" ");
  345. Console.WriteLine("Requieremtns: \nRadar Lvl: 1 \nNumber Of Workers: 1 \nDifficulity: 6 \nReward: 6000$ ");
  346. break;
  347. }
  348. /////////////////////////////////////////////////////////////////////
  349.  
  350. bool result = IsPermmited(BoatInfo.numberOfWorkers, BoatInfo.levelOfRadar, choosenPlace);
  351.  
  352. if (result == true)
  353. {
  354. Console.WriteLine(" ");
  355. Console.WriteLine("Press 'Enter' to enter, or 'return' to return to your boat.");
  356. string act = Console.ReadLine();
  357. if (act.ToUpper() == "")
  358. {
  359. if(choosenPlace.ToUpper() == "HUNTERSLAGOONE")
  360. {
  361. Places.difficulity = HuntersLagoone.difficulity;
  362. }
  363. else if(choosenPlace.ToUpper() == "SWIFT")
  364. {
  365. Places.difficulity = Swift.difficulity;
  366. }
  367.  
  368. int EarnedCash = Fight(Places.difficulity); //diff + 1 as parameter for diff//
  369. if (EarnedCash == 0)
  370. {
  371. Console.WriteLine("After You fought, it appears that you didn't catch any fish, \nand therefore you didn't earn anything.");
  372. BoatInfo.cash = (EarnedCash + BoatInfo.cash);
  373. BoatInfo.cooldown = true;
  374.  
  375.  
  376. }
  377. else
  378. {
  379. Console.WriteLine("You have earned: " + EarnedCash + "$ !");
  380. BoatInfo.cash = (EarnedCash + BoatInfo.cash);
  381. BoatInfo.cooldown = true;
  382.  
  383. }
  384. }
  385. else
  386. continue;
  387.  
  388. }
  389.  
  390.  
  391.  
  392. else
  393. {
  394. Console.WriteLine(" ");
  395. Console.WriteLine("Sorry, but you do not meet the requirments. \nUpgrade Workers Or The Radar! (or don't just press enter)");
  396. }
  397.  
  398.  
  399.  
  400. }
  401. }
  402. else if (BoatInfo.cooldown == true)
  403. {
  404. DateTime now = DateTime.Now;
  405. int thisnum = now.Second;
  406. Console.WriteLine("Your Workers are tired. they will be able to fight in about 1 minute.");
  407. Console.WriteLine("");
  408. Console.WriteLine("Sometimes they are really tired, and sometimes they just needed that one second break.");
  409.  
  410. 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
  411.  
  412. int second = moment.Second;
  413.  
  414. if(thisnum <= second)
  415. {
  416. BoatInfo.cooldown = false;
  417. }
  418.  
  419. }
  420. break;
  421. case "SHOP":
  422. Console.WriteLine("Welcome To The Upgrade Shop! you have: " + BoatInfo.cash+"$ !");
  423. Console.WriteLine(" ");
  424. Console.WriteLine("Number Of Workers:" + BoatInfo.numberOfWorkers.ToString() + " " + "\nRadar Lvl:" + BoatInfo.levelOfRadar.ToString() + " " + "\nLiving Place Lvl:" + BoatInfo.levelOfLivingPlace.ToString());
  425. Console.WriteLine(" ");
  426. Console.WriteLine("Which thing will you upgrade? notes:\n (before having 4 workers, you must have living place lvl 2)");
  427. Console.WriteLine(" ");
  428. 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.");
  429. string desiredUpgrade = Console.ReadLine();
  430. switch(desiredUpgrade.ToUpper())
  431. {
  432. case "NOW":
  433. Console.WriteLine(" ");
  434. Console.WriteLine("A new worker is costing 9,000$");
  435. Console.WriteLine(" ");
  436. Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
  437. int l = 1;
  438. string fsure = Console.ReadLine();
  439. if (fsure == "" && BoatInfo.cash >= 9000)
  440. {
  441.  
  442. l++;
  443. if (BoatInfo.numberOfWorkers == 4 * l && BoatInfo.levelOfLivingPlace > 1 * l) // put = if mistaken.
  444. {
  445. Console.WriteLine("You can't purchase more workers if your living place is level 1");
  446. }
  447. else
  448. {
  449. BoatInfo.cash = BoatInfo.cash - 9000;
  450. BoatInfo.numberOfWorkers = BoatInfo.numberOfWorkers + 1;
  451. Console.WriteLine("You now have: {0} Workers!", BoatInfo.numberOfWorkers);
  452. }
  453. }
  454. else if(BoatInfo.cash < 9000 && fsure == "")
  455. {
  456. Console.WriteLine("You don't have enough cash.");
  457. }
  458. else
  459. continue;
  460.  
  461. break;
  462.  
  463. case "RLV":
  464. Console.WriteLine(" ");
  465. Console.WriteLine("Radar Upgrade Lvl is Costing 10,000$");
  466. Console.WriteLine(" ");
  467. Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
  468.  
  469. string qsure = Console.ReadLine();
  470. if (qsure == "" && BoatInfo.cash >= 10000)
  471. {
  472. BoatInfo.cash = BoatInfo.cash - 10000;
  473. BoatInfo.levelOfRadar = BoatInfo.levelOfRadar + 1;
  474. Console.WriteLine("Purchase Was Completed!");
  475.  
  476.  
  477. }
  478. else if(BoatInfo.cash < 10000 && qsure == "")
  479. {
  480. Console.WriteLine("You don't have enough cash.");
  481. }
  482. else
  483. continue;
  484. break;
  485.  
  486. case "LPL":
  487. Console.WriteLine(" ");
  488. Console.WriteLine("Living Place Upgrade Lvl Is Costing 50,000$");
  489. Console.WriteLine(" ");
  490. Console.WriteLine("Press 'enter' to Buy, or 'return' to Return");
  491.  
  492. string lsure = Console.ReadLine();
  493. if (lsure == "" && BoatInfo.cash > 50000)
  494. {
  495. BoatInfo.cash = BoatInfo.cash - 50000;
  496.  
  497. BoatInfo.levelOfLivingPlace = BoatInfo.levelOfLivingPlace + 1;
  498. Console.WriteLine("Your Living Place Lvl Is Now {0} ", BoatInfo.levelOfLivingPlace = BoatInfo.levelOfLivingPlace + 1);
  499. }
  500. else if(BoatInfo.cash < 50000 && lsure == "")
  501. {
  502. Console.WriteLine("You don't have enough cash.");
  503. }
  504. else
  505. continue;
  506. break;
  507. case "EXIT":
  508. continue;
  509.  
  510.  
  511. }
  512. break;
  513. case "EXIT":
  514. BoatInfo.signedIn = -1;
  515. Environment.Exit(0);
  516. break;
  517.  
  518. case "HELP":
  519. Console.WriteLine("This is Version {0}, Creator: Dennis.",VERSION);
  520. 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!");
  521. Console.WriteLine(" ");
  522. Console.WriteLine("Future Updates Are Coming Soon!");
  523. Console.WriteLine("Update notes: \nVersion 1.2: *Some minor changes.");
  524. Console.WriteLine("Press 'Enter' To continue.");
  525. break;
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. }
  533. Console.ReadKey();
  534. }
  535.  
  536. }
  537.  
  538. public static bool IsPermmited(int NumberOfWorkers, int RadarLvl,string choosenPlace)
  539. {
  540.  
  541.  
  542. switch (choosenPlace.ToUpper())
  543. {
  544. case "HUNTERSLAGOONE":
  545. HuntersLagoone nl = new HuntersLagoone();
  546.  
  547.  
  548.  
  549. if (nl.numberOfFighters <= NumberOfWorkers && nl.radarLocation <= RadarLvl)
  550. {
  551.  
  552. return true;
  553. }
  554. else if(nl.numberOfFighters < NumberOfWorkers)
  555. {
  556. return false;
  557. }
  558. else
  559. {
  560. return false;
  561. }
  562. break;
  563. case "SWIFT":
  564. Swift ns = new Swift();
  565. if (ns.numberOfFighters <= NumberOfWorkers && ns.radarLocation <= RadarLvl)
  566. {
  567. return true;
  568. }
  569. else
  570. return false;
  571. break;
  572.  
  573. }
  574. return false;
  575.  
  576.  
  577. }
  578.  
  579. public static int Fight(int diff)
  580. {
  581. Console.WriteLine("You have found some fish, to attack, press enter. \nand as always type exit to leave. ");
  582. string input = Console.ReadLine();
  583. if (input.ToUpper() == "EXIT")
  584. return 0;
  585. else if(input == "")
  586. {
  587.  
  588. Random rnd = new Random();
  589. BoatInfo forfight = new BoatInfo();
  590. int health = (BoatInfo.numberOfWorkers * 2);
  591. for (int i = 0; i <= health; i++)
  592. {
  593. int chance = rnd.Next(0, diff);
  594. if(BoatInfo.numberOfWorkers > diff)
  595. {
  596. diff = diff + 2;
  597. i = 0;
  598. continue;
  599. }
  600. if (chance == BoatInfo.numberOfWorkers)
  601. {
  602. Console.WriteLine("You Have Succeded. you have been awarded.");
  603. Console.WriteLine("Returning to the boat...");
  604. Console.ReadKey();
  605.  
  606. return 1000 * diff;
  607. }
  608. else
  609. {
  610. Console.WriteLine("Sorry, you didn't catch any fish. \nand you lost some life");
  611. Console.WriteLine("Continuing..");
  612. Console.ReadKey();
  613. i++;
  614. if(i == health)
  615. return 0;
  616.  
  617. }
  618.  
  619. }
  620. return 0;
  621. }
  622. return 0;
  623. }
  624.  
  625. }
  626. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement