Advertisement
Guest User

Untitled

a guest
Mar 6th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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 JapaneseRoulette
  8. {
  9. class JapaneseRoulette
  10. {
  11. static void Main()
  12. {
  13. var cylinder = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14. var players = Console.ReadLine().Split(' ');
  15. var currentPosition = 0;
  16. for (int i = 0; i < cylinder.Length; i++)
  17. {
  18. if (cylinder[i] == 1)
  19. {
  20. currentPosition = i; break;
  21. }
  22. }
  23.  
  24. for (int i = 0; i < players.Length; i++)
  25. {
  26. var currentPlayer = players[i].Split(',');
  27. var power = int.Parse(currentPlayer[0]);
  28. var direction = currentPlayer[1];
  29.  
  30. if (direction == "Right")
  31. {
  32. while (power > 0)
  33. {
  34. currentPosition++;
  35. power--;
  36. if (currentPosition > cylinder.Length - 1)
  37. currentPosition = 0;
  38. }
  39.  
  40. }
  41. else if (direction == "Left")
  42. {
  43. while (power > 0)
  44. {
  45. currentPosition--;
  46. power--;
  47. if (currentPosition < 0)
  48. currentPosition = cylinder.Length - 1;
  49. }
  50. }
  51.  
  52. if (currentPosition == 2)
  53. {
  54. Console.WriteLine("Game over! Player {0} is dead.", i);
  55. return;
  56. }
  57. currentPosition++;
  58. //Add two checks if current position is outside bounds of array.
  59. if (currentPosition < 0)
  60. currentPosition = cylinder.Length - 1;
  61. if (currentPosition > cylinder.Length - 1)
  62. currentPosition = 0;
  63. }
  64.  
  65. Console.WriteLine("Everybody got lucky!");
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement