Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.19 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. using System.Threading;
  7.  
  8. namespace ArraysnShit
  9. {
  10.     class ChessGame
  11.     {
  12.         static byte[,] chessGrid = new byte[8, 8];
  13.         static string moveFrom;
  14.         static string moveTo;
  15.         static int rowNum;
  16.         static void Main(string[] args)
  17.         {
  18.             PieceInit();
  19.             while (true)
  20.             {
  21.                 Console.Clear();
  22.                 DrawGrid();
  23.                 Console.Write("Move from:");
  24.                 moveFrom = Console.ReadLine();
  25.  
  26.                 if (CheckInput(moveFrom))
  27.                 {
  28.                     Console.Clear();
  29.                     DrawGrid();
  30.                     Console.Write("Move to:");
  31.                     moveTo = Console.ReadLine();
  32.                     if (CheckInput(moveTo))
  33.                     {
  34.                         //do THE move
  35.                         byte temp = chessGrid[moveFrom[0] - 97, moveFrom[1] - 49];
  36.                         chessGrid[moveTo[0] - 97, moveTo[1] - 49] = temp; //copy paste
  37.                         if(moveFrom != moveTo)
  38.                         {
  39.                             chessGrid[moveFrom[0] - 97, moveFrom[1] - 49] = 0; //delete first copy
  40.                         }
  41.                     }
  42.                 }
  43.                 Console.Clear();
  44.                 DrawGrid();
  45.             }
  46.             Console.ReadKey();
  47.         }
  48.  
  49.         static bool CheckInput(string input)
  50.         {
  51.             input.ToLower();
  52.             if (input.Length == 2)
  53.             {
  54.                 if (input[0] >= 97 && input[0] <= 104 && input[1] >= 49 && input[1] <= 57)
  55.                 {
  56.                     return true;
  57.                 }
  58.             }
  59.             return false;
  60.         }
  61.  
  62.         static void DrawGrid()
  63.         {
  64.             rowNum = 1;
  65.             for (int y = 0; y < chessGrid.GetLength(0); y++)
  66.             {
  67.                 Console.Write(rowNum++ + " | ");
  68.                 for (int x = 0; x < chessGrid.GetLength(0); x++)
  69.                 {
  70.                     if (chessGrid[x, y] == 0)
  71.                     {
  72.                         Console.Write((char)48);
  73.                     }
  74.                     else
  75.                     {
  76.                         Console.Write((char)chessGrid[x, y]);
  77.                     }
  78.                     Console.Write(" ");
  79.                 }
  80.                 Console.WriteLine("");
  81.             }
  82.             Console.WriteLine("    _______________\n    a b c d e f g h\n");
  83.         }
  84.  
  85.         static void PieceInit()
  86.         {
  87.             PawnsAss();
  88.             RooksAss();
  89.             KnightsAss();
  90.             BishopsAss();
  91.             RoyalsAss();
  92.         }
  93.  
  94.         static void PawnsAss()
  95.         {
  96.             //black pawns
  97.             for (int x = 0; x < chessGrid.GetLength(0); x++)
  98.             {
  99.                 chessGrid[x, 1] = 80; //R
  100.             }
  101.  
  102.             //white pawns
  103.             for (int x = 0; x < chessGrid.GetLength(0); x++)
  104.             {
  105.                 chessGrid[x, 6] = 112; //r
  106.             }
  107.         }
  108.  
  109.         static void RooksAss()
  110.         {
  111.             //black rooks
  112.             chessGrid[0, 0] = 82; //R
  113.             chessGrid[7, 0] = 82; //R
  114.  
  115.             //white rooks
  116.             chessGrid[0, 7] = 114; //r
  117.             chessGrid[7, 7] = 114; //r
  118.         }
  119.  
  120.         static void KnightsAss()
  121.         {
  122.             //black knights
  123.             chessGrid[1, 0] = 72; //H
  124.             chessGrid[6, 0] = 72; //H
  125.  
  126.             //white knights
  127.             chessGrid[1, 7] = 104; //h
  128.             chessGrid[6, 7] = 104; //h
  129.         }
  130.  
  131.         static void BishopsAss()
  132.         {
  133.             //black bishops
  134.             chessGrid[2, 0] = 66; //B
  135.             chessGrid[5, 0] = 66; //B
  136.  
  137.             //white bishops
  138.             chessGrid[2, 7] = 98; //b
  139.             chessGrid[5, 7] = 98; //b
  140.         }
  141.  
  142.         static void RoyalsAss()
  143.         {
  144.             //black pieces
  145.             chessGrid[3, 0] = 81; //Q
  146.             chessGrid[4, 0] = 75; //K
  147.  
  148.             //white pieces
  149.             chessGrid[3, 7] = 113; //q
  150.             chessGrid[4, 7] = 107; //k
  151.         }
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement