Advertisement
vencinachev

Kaufland matrix game

Oct 26th, 2020
2,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.88 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 Matrixx
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] sizes = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
  14.             int rows = sizes[0];
  15.             int cols = sizes[1];
  16.             int[,] matrix = new int[rows, cols];
  17.  
  18.             for (int row = 0; row < rows; row++)
  19.             {
  20.                 for (int col = 0; col < cols; col++)
  21.                 {
  22.                     matrix[row, col] = 100;
  23.                 }
  24.             }
  25.  
  26.             while (true)
  27.             {
  28.                 String input = Console.ReadLine();
  29.                 if (input == "GAME OVER")
  30.                 {
  31.                     break;
  32.                 }
  33.                 int[] data = input.Split(',').Select(int.Parse).ToArray();
  34.  
  35.                 if (data[0] < 0 || data[0] >= rows || data[1] < 0 || data[1] >= cols)
  36.                 {
  37.                     continue;
  38.                 }
  39.  
  40.                 for (int x = -1; x <= 1; x++)
  41.                 {
  42.                     for (int y = -1; y <= 1; y++)
  43.                     {
  44.                         if (data[0] + x >= 0 &&
  45.                             data[0] + x < rows &&
  46.                             data[1] + y >= 0 &&
  47.                             data[1] + y < cols)
  48.                         {
  49.                             if (x == 0 && y == 0)
  50.                             {
  51.                                 matrix[data[0], data[1]] -= data[2];
  52.                             }
  53.                             else
  54.                             {
  55.                                 /*
  56.                                 int damage = 0;
  57.                                 if (data[2] >= 1 && data[2] <= 30)
  58.                                 {
  59.                                     damage = 5;
  60.                                 }
  61.                                 else if (damage < 70)
  62.                                 {
  63.                                     damage = 10;
  64.                                 }
  65.                                 else
  66.                                 {
  67.                                     damage = (100 * data[2]) / 20;
  68.                                 }
  69.                                 matrix[data[0] + x, data[1] + y] -= damage;
  70.                                 */
  71.                                 matrix[data[0] + x, data[1] + y] -= 10;
  72.                             }
  73.                         }
  74.                     }
  75.                 }
  76.             }
  77.  
  78.             // print matrix
  79.             for (int row = 0; row < rows; row++)
  80.             {
  81.                 for (int col = 0; col < cols; col++)
  82.                 {
  83.                     Console.Write("{0} ", matrix[row, col]);
  84.                 }
  85.                 Console.WriteLine();
  86.             }
  87.         }
  88.     }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement