Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 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.  
  8. namespace BatailleNavale
  9. {
  10.     class Renderer
  11.     {
  12.         private int _xSize, _ySize;
  13.         private string _title;
  14.         ConsoleColor _color;
  15.         int[,] _plateau;
  16.         string _padding = "";
  17.         public Renderer(int x, int y, int[,] p ,string t, ConsoleColor c)
  18.         {
  19.             this._xSize = x;
  20.             this._ySize = y;
  21.             this._title = t;
  22.             this._color = c;
  23.             this._plateau = p;
  24.  
  25.         }
  26.         public void ShowPlateau()
  27.         {
  28.             _padding = "";
  29.             for (int x = 0; x < 20; x++)
  30.             {
  31.                 _padding += ' ';
  32.             }
  33.  
  34.             Console.Write(_padding);
  35.             Console.ForegroundColor = _color;
  36.             Console.WriteLine(_title);
  37.  
  38.             for (int y = -1; y < _ySize +2; y++)
  39.             {
  40.  
  41.                 if (y >= 1 && y <= _ySize )
  42.                 {
  43.                     Console.Write(_padding);
  44.                     Console.ForegroundColor = ConsoleColor.White;
  45.                     Console.Write(y);
  46.                 }
  47.                 if (y == 0)
  48.                 {
  49.                     Console.Write(_padding);
  50.                     Console.Write("  ");
  51.                 }
  52.                 for (int x = 0; x < _xSize; x++)
  53.                 {
  54.                     if (x == 0 && y != _ySize)
  55.                     {
  56.                         Console.Write("  ");
  57.                     }
  58.                     if (x == 0 && y == _ySize)
  59.                     {
  60.                         Console.Write(" ");
  61.                     }
  62.                     if (y == -1 && x == 0)
  63.                         Console.Write(_padding);
  64.                     if (y == _ySize + 1 && x == 0)
  65.                         Console.Write(_padding);
  66.                     if (y == -1 || y == _ySize + 1)
  67.                     {
  68.                         Console.ForegroundColor = ConsoleColor.White;
  69.                         Console.Write("════");
  70.                     }
  71.                     else if (x == _xSize - 1 && y == -1)
  72.                     {
  73.                         Console.WriteLine();
  74.                     }
  75.                     else if (y >= 0 && y <= _ySize)
  76.                     {
  77.                         if (y == 0)
  78.                         {
  79.                             Console.ForegroundColor = ConsoleColor.White;
  80.                             Console.Write(((char)('a' + x)));
  81.                             Console.Write("   ");
  82.                         }
  83.                         else
  84.                         {
  85.                             switch (_plateau[x, y-1])
  86.                             {
  87.                                 case 0:
  88.                                     Console.ForegroundColor = ConsoleColor.Cyan;
  89.                                     Console.Write("▓▓▓ ");
  90.                                     break;
  91.  
  92.                                 case 1:
  93.                                     Console.ForegroundColor = ConsoleColor.Gray;
  94.                                     Console.Write("▓▓▓ ");
  95.                                     break;
  96.  
  97.                                 case 2:
  98.                                     Console.ForegroundColor = ConsoleColor.DarkRed;
  99.                                     Console.Write("▓▓▓ ");
  100.                                     break;
  101.  
  102.                                 case 3:
  103.                                     Console.ForegroundColor = ConsoleColor.Yellow;
  104.                                     Console.Write("▓▓▓ ");
  105.                                     break;
  106.  
  107.                             }
  108.                         }
  109.                     }
  110.                 }
  111.                 Console.WriteLine();
  112.                 Console.WriteLine();
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement