Advertisement
Filkolev

Game Of Code

Jul 7th, 2014
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2.  
  3. class GameOfPage
  4. {
  5.     static void Main()
  6.     {
  7.         string[] inputLines = new string[16];
  8.  
  9.         for (int i = 0; i < 16; i++)
  10.         {
  11.             inputLines[i] = Console.ReadLine();
  12.         }
  13.  
  14.         char[,] tray = new char[16, 16];
  15.  
  16.         for (int row = 0; row < 16; row++)
  17.         {
  18.             for (int col = 0; col < 16; col++)
  19.             {
  20.                 tray[row, col] = inputLines[row][col];
  21.             }
  22.         }
  23.  
  24.         decimal price = 0;
  25.  
  26.         string question = null;
  27.  
  28.         while (question != "paypal")
  29.         {
  30.             question = Console.ReadLine();
  31.  
  32.             if (question == "what is")
  33.             {
  34.                 int checkRow = int.Parse(Console.ReadLine());
  35.                 int checkColumn = int.Parse(Console.ReadLine());
  36.                 Console.WriteLine(checkLocation(checkRow, checkColumn, tray));
  37.             }
  38.  
  39.             if (question == "buy")
  40.             {
  41.                 int checkRow = int.Parse(Console.ReadLine());
  42.                 int checkColumn = int.Parse(Console.ReadLine());
  43.  
  44.                 if (checkLocation(checkRow, checkColumn, tray) == "cookie")
  45.                 {
  46.                     price += 1.79m;
  47.                     for (int r = checkRow - 1; r <= checkRow + 1; r++)
  48.                     {
  49.                         for (int c = checkColumn - 1; c <= checkColumn + 1; c++)
  50.                         {
  51.                             tray[r, c] = '0';
  52.                         }
  53.                     }
  54.  
  55.  
  56.                 }
  57.  
  58.                 else if (checkLocation(checkRow, checkColumn, tray) == "broken cookie" || checkLocation(checkRow, checkColumn, tray) == "cookie crumb")
  59.                 {
  60.                     Console.WriteLine("page");
  61.                 }
  62.  
  63.             }
  64.         }
  65.  
  66.         Console.WriteLine("{0:F2}", price);
  67.  
  68.     }
  69.  
  70.     public static string checkLocation(int row, int column, char[,] tray)
  71.     {
  72.         int upperRow = row - 1;
  73.         if (row == 0)
  74.         {
  75.             upperRow++;
  76.         }
  77.  
  78.         int lowerRow = row + 1;
  79.         if (row == 15)
  80.         {
  81.             lowerRow--;
  82.         }
  83.  
  84.         int leftcolumn = column - 1;
  85.         if (column == 0)
  86.         {
  87.             leftcolumn++;
  88.         }
  89.  
  90.         int rightColumn = column + 1;
  91.         if (column == 15)
  92.         {
  93.             rightColumn--;
  94.         }
  95.  
  96.         int sum = 0;
  97.  
  98.         for (int r = upperRow; r <= lowerRow; r++)
  99.         {
  100.             for (int c = leftcolumn; c <= rightColumn; c++)
  101.             {
  102.                 if (tray[r,c] == '1')
  103.                 {
  104.                     sum++;
  105.                 }
  106.             }
  107.         }
  108.  
  109.         if (sum == 9)
  110.         {
  111.             return "cookie";
  112.         }
  113.  
  114.         else if (sum == 1 && tray[row, column] == '1')
  115.         {
  116.             return "cookie crumb";
  117.         }
  118.  
  119.         else if (sum != 0)
  120.         {
  121.             return "broken cookie";
  122.         }
  123.  
  124.         else
  125.         {
  126.             return "smile";
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement