Advertisement
dimipan80

IT Village

May 29th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.02 KB | None | 0 0
  1. namespace IT_Village
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     class ITVillage
  7.     {
  8.         private static char[][] board;
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             board = new char[4][];
  13.             CreateTheGameBoard();
  14.  
  15.             string[] startPosition = Console.ReadLine().Split();
  16.             byte startY = (byte)(byte.Parse(startPosition[0]) - 1);
  17.             byte startX = (byte)(byte.Parse(startPosition[1]) - 1);
  18.  
  19.             byte[] diceNumbers = Console.ReadLine().Split()
  20.                 .Select(byte.Parse).ToArray();
  21.  
  22.             int coins = 50;
  23.             byte totalInns = CountAllInnsOnBoard();
  24.             byte ownInns = 0;
  25.             byte row = startY;
  26.             byte col = startX;
  27.             for (byte i = 0; i < diceNumbers.Length; i++)
  28.             {
  29.                 coins += ownInns * 20;
  30.                 MoveToTheNextField(ref row, ref col, diceNumbers[i]);
  31.  
  32.                 switch (board[row][col])
  33.                 {
  34.                     case 'P':
  35.                         coins -= 5;
  36.                         break;
  37.                     case 'I':
  38.                         if (coins < 100)
  39.                         {
  40.                             coins -= 10;
  41.                         }
  42.                         else
  43.                         {
  44.                             coins -= 100;
  45.                             ownInns++;
  46.                             board[row][col] = '0';
  47.                         }
  48.                         break;
  49.                     case 'F':
  50.                         coins += 20;
  51.                         break;
  52.                     case 'S':
  53.                         i += 2;
  54.                         break;
  55.                     case 'V':
  56.                         coins *= 10;
  57.                         break;
  58.                     case 'N':
  59.                         Console.WriteLine("<p>You won! Nakov's force was with you!<p>");
  60.                         return;
  61.                 }
  62.  
  63.                 if (ownInns == totalInns)
  64.                 {
  65.                     Console.WriteLine("<p>You won! You own the village now! You have {0} coins!<p>", coins);
  66.                     return;
  67.                 }
  68.  
  69.                 if (i >= diceNumbers.Length - 1)
  70.                 {
  71.                     Console.WriteLine("<p>You lost! No more moves! You have {0} coins!<p>",
  72.                         coins);
  73.                     return;
  74.                 }
  75.  
  76.                 if (coins <= 0)
  77.                 {
  78.                     Console.WriteLine("<p>You lost! You ran out of money!<p>");
  79.                     return;
  80.                 }
  81.             }
  82.         }
  83.  
  84.         private static void CreateTheGameBoard()
  85.         {
  86.             string[] inputBoard = Console.ReadLine().Split('|');
  87.  
  88.             for (byte i = 0; i < inputBoard.Length; i++)
  89.             {
  90.                 string[] letters = inputBoard[i].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  91.  
  92.                 board[i] = new char[letters.Length];
  93.                 for (byte j = 0; j < letters.Length; j++)
  94.                 {
  95.                     board[i][j] = letters[j][0];
  96.                 }
  97.             }
  98.         }
  99.  
  100.         private static byte CountAllInnsOnBoard()
  101.         {
  102.             byte count = 0;
  103.             for (int i = 0; i < 4; i++)
  104.             {
  105.                 for (int j = 0; j < 4; j++)
  106.                 {
  107.                     if (board[i][j] == 'I')
  108.                     {
  109.                         count++;
  110.                     }
  111.                 }
  112.             }
  113.  
  114.             return count;
  115.         }
  116.  
  117.         private static void MoveToTheNextField(ref byte row, ref byte col, byte nextNumber)
  118.         {
  119.             byte diceValue = (byte)(nextNumber % 12);
  120.             for (byte j = 0; j < diceValue; j++)
  121.             {
  122.                 if (row == 0 && col < 3) col++;
  123.  
  124.                 else if (col == 3 && row < 3) row++;
  125.  
  126.                 else if (row == 3 && col > 0) col--;
  127.  
  128.                 else if (col == 0 && row > 0) row--;
  129.             }
  130.         }
  131.     }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement