IPetrov007

JapanRoulete

Feb 26th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 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 _02_JapanRoulette
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] cilinder = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. List<string> powerAndDirections = Console.ReadLine().Split(' ').ToList();
  15.  
  16. int bulletIndex = 0;
  17. bulletIndex = NewMethod(cilinder, bulletIndex);
  18. for (int i = 0; i < powerAndDirections.Count; i++)
  19. {
  20. string[] player = new string[2];
  21. player = powerAndDirections[i].Split(',');
  22. string playerDirection = player[1];
  23. int playerPower = int.Parse(player[0]);
  24.  
  25.  
  26. if (playerDirection == "Right")
  27. {
  28. bulletIndex = (bulletIndex + playerPower) % cilinder.Length;
  29. }
  30. else if (playerDirection == "Left")
  31. {
  32. bulletIndex = Math.Abs((playerPower - bulletIndex)) % cilinder.Length;
  33. }
  34. if (bulletIndex == 2)
  35. {
  36. Console.WriteLine($"Game over! Player {i} is dead.");
  37. bulletIndex = 7;
  38. break;
  39. }
  40. else
  41. {
  42. bulletIndex++;
  43. }
  44.  
  45. }
  46. if (bulletIndex != 7)
  47. {
  48. Console.WriteLine("Everybody got lucky!");
  49. }
  50. }
  51.  
  52. private static int NewMethod(int[] cilinder, int bulletIndex)
  53. {
  54. for (int k = 0; k < cilinder.Length; k++)
  55. {
  56. if (cilinder[k] == 1)
  57. {
  58. bulletIndex = k;
  59. break;
  60. }
  61. }
  62.  
  63. return bulletIndex;
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment