Guest User

Untitled

a guest
Aug 12th, 2015
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.49 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 ChessTest
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Figure f = new Figure(1, 7);
  14.             ChessTable.CheckPosition(f);
  15.             for (int i = 0; i < f.wentsList.Count; i++)
  16.             {
  17.                 Console.WriteLine((string)f.wentsList[i].ToString());
  18.             }
  19.             Console.ReadLine();
  20.         }
  21.     }
  22.     public struct Wents
  23.     {
  24.         public string Name { get; set; }
  25.         public bool isValid { get; set; }
  26.         public int deltaX { get; set; }
  27.         public int deltaY { get; set; }
  28.         public Wents(string name, int y, int x) : this()
  29.         {
  30.             Name = name;
  31.             deltaX = x;
  32.             deltaY = y;
  33.         }
  34.         public override string ToString()
  35.         {
  36.             return String.Format("The went {0} is {1}",Name,isValid);
  37.         }
  38.     }
  39.     public class Figure
  40.     {
  41.        
  42.         public List<Wents> wentsList= new List<Wents>();
  43.         public Tuple<int, int> tulpe;
  44.         public Figure(int x, int y)
  45.         {
  46.             WentsInit();
  47.             tulpe = new Tuple<int, int>(x, y);
  48.            
  49.         }
  50.         private void WentsInit()
  51.         {
  52.             wentsList.Add(new Wents("Y+2;X+1", +2, +1));
  53.             wentsList.Add(new Wents("Y+2;X-1", +2, -1));
  54.             wentsList.Add(new Wents("Y-2;X+1", -2, +1));
  55.             wentsList.Add(new Wents("Y-2;X-1", -2, -1));
  56.             wentsList.Add(new Wents("Y+1;X+2", +1, +2));
  57.             wentsList.Add(new Wents("Y-1;X+2", -1, +2));
  58.             wentsList.Add(new Wents("Y+2;X+1", +1, -2));
  59.             wentsList.Add(new Wents("Y-2;X-1", -1, -2));
  60.         }
  61.     }
  62.     public static class ChessTable
  63.     {
  64.         private static int[,] _table = new int[7, 7];
  65.         public static void CheckPosition(Figure f)
  66.         {
  67.             for (int i = 0; i < f.wentsList.Count; i++)
  68.             {
  69.                 try
  70.                 {
  71.                     int _i = _table[f.tulpe.Item1 + f.wentsList[i].deltaX, f.tulpe.Item2 + f.wentsList[i].deltaY];
  72.                     Wents w = f.wentsList[i];
  73.                     w.isValid = true;
  74.                     f.wentsList[i] = w;
  75.                 }
  76.                 catch
  77.                 {
  78.                     System.Console.WriteLine("IOF");
  79.                    
  80.                 }
  81.             }
  82.         }
  83.        
  84.  
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment