Advertisement
dobroslav_atanasov

Japanese Roulette

Feb 27th, 2017
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.84 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.             var cylinder =  Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.             var strength =  Console.ReadLine().Split(' ').ToList();
  13.  
  14.             int startIndex = 2;
  15.             int position = 0;
  16.             bool isDead = false;
  17.             int player = 0;
  18.  
  19.             for (int i = 0; i < strength.Count; i++)
  20.             {
  21.                 player = i;
  22.                 var strengthAndDirection = strength[i].Split(',').ToList();
  23.                 int playerStrength = int.Parse(strengthAndDirection[0]);
  24.                 string playerDirection = strengthAndDirection[1];
  25.  
  26.                 if (i == 0)
  27.                 {
  28.                     if (playerDirection == "Right")
  29.                     {
  30.                         position = (startIndex + playerStrength) % cylinder.Count;
  31.                         if (cylinder[position] == 1)
  32.                         {
  33.                             isDead = true;
  34.                             break;
  35.                         }
  36.                     }
  37.                     else if (playerDirection == "Left")
  38.                     {
  39.                         position = Math.Abs(startIndex - playerStrength) % cylinder.Count;
  40.                         if (cylinder[position] == 1)
  41.                         {
  42.                             isDead = true;
  43.                             break;
  44.                         }
  45.                     }
  46.                 }
  47.                 else
  48.                 {
  49.                     if (playerDirection == "Right")
  50.                     {
  51.                         position = (position + playerStrength) % cylinder.Count;
  52.                         if (cylinder[position] == 1)
  53.                         {
  54.                             isDead = true;
  55.                             break;
  56.                         }
  57.                     }
  58.                     else if (playerDirection == "Left")
  59.                     {
  60.                         position = Math.Abs(position - playerStrength) % cylinder.Count;
  61.                         if (cylinder[position] == 1)
  62.                         {
  63.                             isDead = true;
  64.                             break;
  65.                         }
  66.                     }
  67.                 }
  68.                
  69.                 position++;
  70.                 if (position > cylinder.Count)
  71.                 {
  72.                     position = (position - 1) % cylinder.Count;
  73.                 }
  74.             }
  75.  
  76.             if (false)
  77.             {
  78.                 Console.WriteLine("Everybody got lucky!");
  79.             }
  80.             else
  81.             {
  82.                 Console.WriteLine($"Game over! Player {player} is dead.");
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement