Advertisement
YavorGrancharov

Japanese_Roulette(copy)

Jul 6th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Japanese_Roulette
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] bullets = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  12.             string[] players = Console.ReadLine().Split(' ');
  13.             bool dead = false;
  14.             int index = 0;
  15.             for (int i = 0; i < bullets.Length; i++)
  16.             {
  17.                 if (bullets[i] == 1)
  18.                 {
  19.                     index = i;
  20.                     break;
  21.                 }
  22.             }
  23.            
  24.             for (int i = 0; i < players.Length; i++)
  25.             {
  26.                 string[] tokens = players[i].Split(',');
  27.                 string direction = tokens[1];
  28.                 int spin = int.Parse(tokens[0]);
  29.                
  30.                 switch (direction)
  31.                 {
  32.                     case "Right":
  33.                     index = (index + spin) % bullets.Length;
  34.                     break;
  35.                     case "Left":
  36.                     if (index - spin < 0)
  37.                     {
  38.                         index = bullets.Length - (Math.Abs(index - spin) % bullets.Length);
  39.                     }
  40.                     else
  41.                     {
  42.                         index -= spin;
  43.                     }
  44.                     break;
  45.                 }
  46.                
  47.                 if (index == 2)
  48.                 {
  49.                     Console.WriteLine($"Game over! Player {i} is dead.");
  50.                     dead = true;
  51.                     break;
  52.                 }
  53.                
  54.                 index = index + 1 == bullets.Length ? 0 : index + 1;
  55.             }
  56.             if (!dead)
  57.             {
  58.                 Console.WriteLine("Everybody got lucky!");
  59.             }
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement