Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace anna_kuutti_su215_uppgifter_3
  8. {
  9. class Box
  10. {
  11. public int x;
  12. public int y;
  13. public int width;
  14. public int height;
  15. int randomColor;
  16. public ConsoleColor[] colors = { ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.Magenta, ConsoleColor.Green, ConsoleColor.Gray, ConsoleColor.DarkYellow, ConsoleColor.DarkRed, ConsoleColor.DarkMagenta, ConsoleColor.DarkGreen, ConsoleColor.DarkGray, ConsoleColor.DarkCyan, ConsoleColor.DarkBlue, ConsoleColor.Blue };
  17. Random rndColor = new Random();
  18.  
  19. public void Draw()
  20. {
  21. randomColor = rndColor.Next(0, colors.Length);
  22. Console.BackgroundColor = colors[randomColor];
  23. Console.ForegroundColor = colors[randomColor];
  24. for (int i = 0; i < height; i++)
  25. {
  26. System.Console.SetCursorPosition(x, y);
  27. for (int o = 0; o < width; o++)
  28. {
  29. Console.Write("x");
  30. //System.Threading.Thread.Sleep(1);
  31. }
  32. y += 1;
  33. }
  34. }
  35. }
  36.  
  37. class Program
  38. {
  39. static void Main(string[] args)
  40. {
  41. ChooseWhatToDo();
  42. Console.ReadLine();
  43. }
  44.  
  45. static void ChooseWhatToDo()
  46. {
  47. Console.WriteLine("Please choose witch program you want to play");
  48. Console.WriteLine("1. rock paper scissor");
  49. Console.WriteLine("2. stop time at 10");
  50. Console.WriteLine("3. 1 to 100 000");
  51. Console.WriteLine("4. Fibonaccis");
  52. Console.WriteLine("5. Login in with many users");
  53. Console.WriteLine("6. Create boxes");
  54.  
  55. switch (EnterAnumber())
  56. {
  57. case 1:
  58. RockScissorPaper();
  59. break;
  60. case 2:
  61. ComeSoCloseAsYoucanTo30();
  62. break;
  63. case 3:
  64. CountTo100000();
  65. break;
  66. case 4:
  67. Fibonaccis();
  68. break;
  69. case 5:
  70. LogInManyUsers();
  71. break;
  72. case 6:
  73. CreateBoxes();
  74. break;
  75. }
  76. }
  77.  
  78. static void LogInManyUsers()
  79. {
  80. string[] user = { "egon", "kalle", "per", "nils" }; //array its many strings in this case stored in one place
  81. string[] password = { "banan", "1234", "password", "nisse" };
  82. Console.WriteLine("Please write your username first, then press enter and write your password.");//writes out on the console
  83.  
  84. string userName = Console.ReadLine(); //reads what the user writes on the console and put it in the string
  85. string userPassword = Console.ReadLine();
  86.  
  87. try
  88. {
  89. int pos = Array.IndexOf(user, userName); //array.IndexOf looks at the array you choose and look at the position this string i this case has
  90. if (userPassword == password[pos])
  91. Console.WriteLine("Welcome to my program");
  92. }
  93. catch
  94. {
  95. Console.WriteLine("either your username or password is wrong");
  96. }
  97. }
  98.  
  99. static void Fibonaccis()
  100. {
  101. long number1 = 0; // a bigger int
  102. long number2 = 1;
  103. long number3;
  104.  
  105. long evenNumber = 0;
  106.  
  107. for (int i = 0; i < 51; i++) // as long as i is smaller than 51
  108. {
  109. if (number1 == 0) //if 1 is 0 then it enter this if-statement
  110. Console.WriteLine(number2);
  111.  
  112. number3 = number1 + number2;
  113. number1 = number2;
  114. number2 = number3;
  115. if (IsEven(number3) && number3 < 4000001)
  116. {
  117. evenNumber = number3 + evenNumber;
  118. }
  119. Console.WriteLine(number3);
  120. }
  121. Console.WriteLine("All even numbers under 4000 000 is " + evenNumber);
  122. }
  123.  
  124. static bool IsEven(long value) // bool is true or false
  125. {
  126. return value % 2 == 0; // % gives backthe things that is left after it has been divided by 2 in this case
  127. }
  128.  
  129. static void CountTo100000()
  130. {
  131. DateTime startTime = DateTime.Now; //dateTime is a funktion that creates a variabel that can store time. DateTime.now takes the time that is right now
  132. for (int i = 0; i < 100001; i++)
  133. {
  134. Console.WriteLine(i);
  135. }
  136. TimeSpan span = DateTime.Now - startTime;
  137.  
  138. DateTime secondStartTime = DateTime.Now;
  139. for (int i = 0; i < 100001; i++)
  140. {
  141. Console.Write(i);
  142. }
  143. TimeSpan secondSpan = DateTime.Now - secondStartTime; //timespan creates a variabel that can count the difference between two times
  144. Console.WriteLine("Det tog writeLine {0} seconds och write {1} seconds ", span.TotalSeconds, secondSpan.TotalSeconds);
  145. }
  146.  
  147. static void ComeSoCloseAsYoucanTo30()
  148. {
  149. Console.WriteLine("The goal is to come as close to 30 seconds as you can");
  150. Console.WriteLine("Press enter to start the timer");
  151. DateTime startTime = DateTime.Now;
  152. Console.ReadLine();
  153.  
  154. Console.WriteLine("Press enter when you want to stop the timer");
  155. Console.ReadLine();
  156. TimeSpan span = DateTime.Now - startTime;
  157. int yourTime = 10 - (int)span.TotalSeconds;//(int) makes the timespan time to an int
  158. Console.WriteLine("You were {0} seconds away", yourTime);
  159. }
  160.  
  161. static void RockScissorPaper()
  162. {
  163. int soManyWinsNeedsTowin;
  164. int computerWins = 0;
  165. int playerWins = 0;
  166. string[] options = { "spock", "scissor", "paper", "rock", "lizard", "spock", "scissor", "paper", "rock", "lizard" };
  167. Random rnd = new Random();
  168.  
  169. Console.WriteLine("We are going to play rock paper scissor.");
  170. while (true)
  171. {
  172. Console.WriteLine("Please choose how many points you want to play to.");
  173. Console.WriteLine("Press either 1, 3, 5 or 7 for how many times you want to play");
  174. soManyWinsNeedsTowin = EnterAnumber();
  175.  
  176. if (soManyWinsNeedsTowin != 1 || soManyWinsNeedsTowin != 3 || soManyWinsNeedsTowin != 5 || soManyWinsNeedsTowin != 7)
  177. Console.WriteLine("Please write a correct number");
  178. else
  179. break;
  180.  
  181. }
  182. while (true)//countinues as long as its true
  183. {
  184.  
  185. Console.WriteLine("Please write your choose");
  186. Console.WriteLine("Press 1 for paper");
  187. Console.WriteLine("Press 2 for rock");
  188. Console.WriteLine("Press 3 for lizard");
  189. Console.WriteLine("Press 4 for spock");
  190. Console.WriteLine("Press 5 for scissor");
  191. Console.WriteLine("Press 6 for quit");
  192.  
  193. int yourNumber = EnterAnumber();
  194. string yourChoose = options[yourNumber + 1]; //makes yourchoose to the string which has this place
  195. int computerNumber = rnd.Next(2, 7);
  196. string computerChoice = options[computerNumber];
  197.  
  198. Console.WriteLine(yourChoose);
  199. Console.WriteLine(computerChoice);
  200.  
  201. if (yourChoose == computerChoice)
  202. Console.WriteLine("You choose {0} and computer choose {1} so nobody won", yourChoose, computerChoice);
  203. else if (yourChoose == options[computerNumber + 1] || yourChoose == options[computerNumber - 2])
  204. {
  205. Console.WriteLine("You choose {0} and computer choose {1} so computer won", yourChoose, computerChoice);
  206. computerWins++;//adds 1 to computerWins
  207. }
  208. else if (yourChoose == options[computerNumber - 1] || yourChoose == options[computerNumber + 2])
  209. {
  210. Console.WriteLine("You choose {0} and computer choose {1} so you won", yourChoose, computerChoice);
  211. playerWins++;
  212. }
  213. else if (yourNumber == 6)
  214. break;
  215.  
  216. if (computerWins == soManyWinsNeedsTowin)
  217. {
  218. Console.WriteLine("Computer won with {0} to {1}", computerWins, playerWins);
  219. break;
  220. }
  221. else if (playerWins == soManyWinsNeedsTowin)
  222. {
  223. Console.WriteLine("You won over the computer with {0} over {1}", playerWins, computerWins);
  224. break;
  225. }
  226.  
  227.  
  228. Console.ReadLine();
  229. Console.Clear(); //clears the console blank
  230. }
  231. }
  232.  
  233. static int EnterAnumber()
  234. {
  235. while (true)
  236. {
  237.  
  238. try//tries to do this
  239. {
  240. return int.Parse(Console.ReadLine());//gives back this value
  241. }
  242. catch//if try fail then it does this
  243. {
  244. Console.WriteLine("You must only use numnbers");
  245. }
  246. }
  247. }
  248. static void CreateBoxes()
  249. {
  250. Console.Clear();
  251. Random rnd = new Random();
  252. while (true)
  253. {
  254.  
  255. Box box1 = new Box(); //creates one box
  256.  
  257. box1.x = rnd.Next(0, 107); ; // x value is 2
  258. box1.y = rnd.Next(0, 26);
  259. box1.width = rnd.Next(10, 80);
  260. box1.height = rnd.Next(10, 50);
  261. if (box1.height + box1.y < 30 && box1.x + box1.width < 120)
  262. {
  263. box1.Draw();
  264. }
  265. }
  266. }
  267. }
  268. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement