Advertisement
grubcho

Japanese roullette

Jul 5th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 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 Japanese_roulette
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] cylinder = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             string[] rotation = Console.ReadLine().Split(' ').ToArray();
  15.  
  16.  
  17.             var initialPosition = 0;
  18.             var endPosition = 0;
  19.             bool dead = false;
  20.  
  21.             for (int i = 0; i < cylinder.Length; i++)
  22.             {
  23.                 if (cylinder[i] == 1)
  24.                 {
  25.                     initialPosition = i;
  26.                     break;
  27.                 }
  28.             }
  29.             for (int i = 0; i < rotation.Length; i++)
  30.             {
  31.                 dead = false;
  32.                 string[] currentCommand = rotation[i].Split(',');
  33.                 var force = int.Parse(currentCommand[0]);
  34.                 var direction = currentCommand[1];
  35.  
  36.                 switch (direction)
  37.                 {
  38.                     case "Right":
  39.                         endPosition = (initialPosition + force) % cylinder.Length;
  40.                         initialPosition = endPosition;
  41.                         break;
  42.                     case "Left":
  43.                         endPosition = (initialPosition - force) % cylinder.Length;
  44.                         if (endPosition < 0)
  45.                         {
  46.                             endPosition += cylinder.Length;
  47.                         }
  48.                         initialPosition = endPosition;
  49.                         break;
  50.                 }
  51.  
  52.                 if (endPosition == 2)
  53.                 {
  54.                     Console.WriteLine($"Game over! Player {i} is dead.");
  55.                     dead = true;
  56.                     break;
  57.                 }
  58.                 initialPosition++;
  59.  
  60.             }
  61.             if (!dead)
  62.             {
  63.                 Console.WriteLine($"Everybody got lucky!");
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement