Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 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 Ali_ohjelmat
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13.  
  14.  
  15.  
  16. // 1 = kivi, 2 = paperi, 3 = sakset
  17.  
  18. Random rnd = new Random();
  19. int arvot = rnd.Next(1, 4);
  20.  
  21. //string tietokone = arvot.ToString();
  22. string tietokone = "";
  23.  
  24. if (arvot == 1)
  25. {
  26. tietokone = "Kivi";
  27. }
  28.  
  29. else if (arvot == 2)
  30. {
  31. tietokone = "Paperi";
  32. }
  33.  
  34. else if (arvot == 3)
  35. {
  36. tietokone = "Sakset";
  37. }
  38. else
  39. {
  40.  
  41. }
  42.  
  43.  
  44.  
  45. //testi
  46.  
  47. switch (AskRockPaperScissor())
  48. {
  49. case 1:
  50. if (arvot == 1)
  51. {
  52. Console.WriteLine("Tasapeli.\n" + tietokone + " vastaan " + AskRockPaperScissor());
  53. }
  54.  
  55. else if (arvot == 2)
  56. {
  57. Console.WriteLine("Hävisit .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  58. }
  59.  
  60. else if (arvot == 3)
  61. {
  62. Console.WriteLine("Voitit .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  63. }
  64. break;
  65.  
  66.  
  67. case 2:
  68. if (arvot == 1)
  69. {
  70. Console.WriteLine("Voitit.\n" + tietokone + " vastaan " + AskRockPaperScissor());
  71. }
  72.  
  73. else if (arvot == 2)
  74. {
  75. Console.WriteLine("Tasapeli .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  76. }
  77.  
  78. else if (arvot == 3)
  79. {
  80. Console.WriteLine("Hävisit .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  81. }
  82. break;
  83.  
  84. case 3:
  85. if (arvot == 1)
  86. {
  87. Console.WriteLine("Hävisit.\n" + tietokone + " vastaan " + AskRockPaperScissor());
  88. }
  89.  
  90. else if (arvot == 2)
  91. {
  92. Console.WriteLine("Voitit .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  93. }
  94.  
  95. else if (arvot == 3)
  96. {
  97. Console.WriteLine("Tasapeli .\n" + tietokone + " vastaan " + AskRockPaperScissor());
  98. }
  99. break;
  100.  
  101. default:
  102. break;
  103. }
  104.  
  105.  
  106.  
  107. //testi
  108.  
  109.  
  110.  
  111. /* switch (tietokone)
  112. {
  113. case "Kivi":
  114. if (AskRockPaperScissor() == 1)
  115. {
  116. Console.WriteLine(tietokone + " vastaan Kivi. \nTasapeli.");
  117. }
  118. else if (AskRockPaperScissor() == 2)
  119. {
  120. Console.WriteLine(tietokone + " vastaan Paperi. \nPelaaja voitti.");
  121. }
  122. else if (AskRockPaperScissor() == 3)
  123. {
  124. Console.WriteLine(tietokone + " vastaan Sakset. \nTietokone voitti.");
  125. }
  126. break;
  127.  
  128.  
  129.  
  130. case "Paperi":
  131. if (AskRockPaperScissor() == 1)
  132. {
  133. Console.WriteLine(tietokone + " vastaan Kivi. \nTietokone voitti.");
  134. }
  135. else if (AskRockPaperScissor() == 2)
  136. {
  137. Console.WriteLine(tietokone + " vastaan Paperi. \nTasapeli.");
  138. }
  139. else if (AskRockPaperScissor() == 3)
  140. {
  141. Console.WriteLine(tietokone + " vastaan Sakset. \nPelaaja voitti.");
  142. }
  143. break;
  144.  
  145. case "Sakset":
  146. if (AskRockPaperScissor() == 1)
  147. {
  148. Console.WriteLine(tietokone + " vastaan Kivi. \nPelaaja voitti.");
  149. }
  150. else if (AskRockPaperScissor() == 2)
  151. {
  152. Console.WriteLine(tietokone + " vastaan Paperi. \nTietokone voitti.");
  153. }
  154. else if (AskRockPaperScissor() == 3)
  155. {
  156. Console.WriteLine(tietokone + " vastaan Sakset. \nTasapeli.");
  157. }
  158. break;
  159.  
  160.  
  161. default:
  162. break;
  163. }
  164.  
  165. Console.WriteLine("Tietokone valitsi: " + tietokone);
  166.  
  167. */
  168.  
  169. }
  170.  
  171.  
  172. static int AskRockPaperScissor()
  173. {
  174. int arvo = -1;
  175. bool success = false;
  176. while (!success)
  177. {
  178.  
  179. Console.WriteLine("Kivi(1), Paperi(2) vai Sakset(3)?");
  180. int.TryParse(Console.ReadLine().Trim(), out arvo);
  181.  
  182.  
  183. switch (arvo)
  184. {
  185. case 1:
  186. Console.WriteLine("Valitsit Kiven");
  187. success = true;
  188. break;
  189.  
  190. case 2:
  191. Console.WriteLine("Valitsit Paperin");
  192. success = true;
  193. break;
  194.  
  195. case 3:
  196. Console.WriteLine("Valitsit Sakset");
  197. success = true;
  198. break;
  199.  
  200. default:
  201. Console.WriteLine("Ilmoita valintasi numeroilla (1 - 3)");
  202. break;
  203. }
  204. }
  205.  
  206. return arvo;
  207. }
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement