Advertisement
Filkolev

IT Village

May 27th, 2015
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. public class ItVillage
  5. {
  6.     public static void Main()
  7.     {
  8.         string[] boardLayout = Console.ReadLine()
  9.             .Split(new[] { '|', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  10.  
  11.         int[] startPosition = Console.ReadLine()
  12.             .Split()
  13.             .Select(int.Parse)
  14.             .ToArray();
  15.  
  16.         int[] moves = Console.ReadLine()
  17.             .Split()
  18.             .Select(int.Parse)
  19.             .ToArray();
  20.  
  21.         string[] board = new string[12];
  22.  
  23.         board[0] = boardLayout[0];
  24.         board[1] = boardLayout[1];
  25.         board[2] = boardLayout[2];
  26.         board[3] = boardLayout[3];
  27.         board[4] = boardLayout[7];
  28.         board[5] = boardLayout[11];
  29.         board[6] = boardLayout[15];
  30.         board[7] = boardLayout[14];
  31.         board[8] = boardLayout[13];
  32.         board[9] = boardLayout[12];
  33.         board[10] = boardLayout[8];
  34.         board[11] = boardLayout[4];
  35.  
  36.         int startIndex;
  37.  
  38.         switch (startPosition[0] - 1)
  39.         {
  40.             case 0:
  41.                 startIndex = startPosition[1] - 1;
  42.                 break;
  43.             case 1:
  44.                 startIndex = startPosition[1] - 1 == 0 ? 11 : 4;
  45.                 break;
  46.             case 2:
  47.                 startIndex = startPosition[1] - 1 == 0 ? 9 : 5;
  48.                 break;
  49.             default:
  50.                 startIndex = (10 - startPosition[1]);
  51.                 break;
  52.         }
  53.  
  54.         int money = 50;
  55.         int innsOwned = 0;
  56.         int totalInns = boardLayout.Count(x => x == "I");
  57.         int nextIndex = startIndex;
  58.  
  59.         for (int i = 0; i < moves.Length; i++)
  60.         {
  61.             money += 20 * innsOwned;
  62.  
  63.             nextIndex = (nextIndex + moves[i]) % 12;
  64.  
  65.             string currentLocation = board[nextIndex];
  66.  
  67.             switch (currentLocation)
  68.             {
  69.                 case "P":
  70.                     money -= 5;
  71.                     break;
  72.                 case "I":
  73.                     if (money >= 100)
  74.                     {
  75.                         money -= 100;
  76.                         innsOwned++;
  77.                     }
  78.                     else
  79.                     {
  80.                         money -= 10;
  81.                     }
  82.                     break;
  83.                 case "F":
  84.                     money += 20;
  85.                     break;
  86.                 case "S":
  87.                     i += 2;
  88.                     break;
  89.                 case "V":
  90.                     money *= 10;
  91.                     break;
  92.                 case "N":
  93.                     Console.WriteLine("<p>You won! Nakov's force was with you!<p>");
  94.                     return;
  95.             }
  96.  
  97.             if (innsOwned == totalInns)
  98.             {
  99.                 Console.WriteLine("<p>You won! You own the village now! You have {0} coins!<p>", money);
  100.                 return;
  101.             }
  102.  
  103.             if (money < 0)
  104.             {
  105.                 Console.WriteLine("<p>You lost! You ran out of money!<p>");
  106.                 return;
  107.             }
  108.         }
  109.  
  110.         Console.WriteLine("<p>You lost! No more moves! You have {0} coins!<p>", money);
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement