Advertisement
Guest User

Boats! without save feature.

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