Guest User

Untitled

a guest
May 3rd, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02.JapaneseRoulette
  6. {
  7. public class JapaneseRoulette
  8. {
  9. public static void Main()
  10. {
  11. List<int> cylinder = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12. List<string> players = Console.ReadLine().Split(' ').ToList();
  13.  
  14. int beginPosition = cylinder.FindIndex(num => num == 1);
  15. int endPosition = 0;
  16.  
  17. for (int i = 0; i < players.Count; i++)
  18. {
  19. string[] currentPlayer = players[i].Split(',');
  20. int strength = int.Parse(currentPlayer[0]);
  21. string direction = currentPlayer[1];
  22.  
  23. switch (direction.ToLower())
  24. {
  25. case "right":
  26. endPosition = beginPosition + (strength % cylinder.Count);
  27.  
  28. if (endPosition >= cylinder.Count)
  29. {
  30. endPosition -= cylinder.Count;
  31. }
  32.  
  33. beginPosition = endPosition;
  34. break;
  35.  
  36. case "left":
  37. endPosition = beginPosition - (strength % cylinder.Count);
  38. //endPosition = Math.Abs(endPosition);
  39.  
  40. if (endPosition < 0)
  41. {
  42. endPosition += cylinder.Count;
  43. }
  44.  
  45. beginPosition = endPosition;
  46. break;
  47. }
  48.  
  49. if (endPosition == 2)
  50. {
  51. Console.WriteLine($"Game over! Player {i} is dead.");
  52. return;
  53. }
  54.  
  55. beginPosition++;
  56. }
  57.  
  58. Console.WriteLine("Everybody got lucky!");
  59. }
  60. }
  61. }
Add Comment
Please, Sign In to add comment