Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- namespace ArraysnShit
- {
- class ChessGame
- {
- static byte[,] chessGrid = new byte[8, 8];
- static string moveFrom;
- static string moveTo;
- static int rowNum;
- static void Main(string[] args)
- {
- PieceInit();
- while (true)
- {
- Console.Clear();
- DrawGrid();
- Console.Write("Move from:");
- moveFrom = Console.ReadLine();
- if (CheckInput(moveFrom))
- {
- Console.Clear();
- DrawGrid();
- Console.Write("Move to:");
- moveTo = Console.ReadLine();
- if (CheckInput(moveTo))
- {
- //do THE move
- byte temp = chessGrid[moveFrom[0] - 97, moveFrom[1] - 49];
- chessGrid[moveTo[0] - 97, moveTo[1] - 49] = temp; //copy paste
- if(moveFrom != moveTo)
- {
- chessGrid[moveFrom[0] - 97, moveFrom[1] - 49] = 0; //delete first copy
- }
- }
- }
- Console.Clear();
- DrawGrid();
- }
- Console.ReadKey();
- }
- static bool CheckInput(string input)
- {
- input.ToLower();
- if (input.Length == 2)
- {
- if (input[0] >= 97 && input[0] <= 104 && input[1] >= 49 && input[1] <= 57)
- {
- return true;
- }
- }
- return false;
- }
- static void DrawGrid()
- {
- rowNum = 1;
- for (int y = 0; y < chessGrid.GetLength(0); y++)
- {
- Console.Write(rowNum++ + " | ");
- for (int x = 0; x < chessGrid.GetLength(0); x++)
- {
- if (chessGrid[x, y] == 0)
- {
- Console.Write((char)48);
- }
- else
- {
- Console.Write((char)chessGrid[x, y]);
- }
- Console.Write(" ");
- }
- Console.WriteLine("");
- }
- Console.WriteLine(" _______________\n a b c d e f g h\n");
- }
- static void PieceInit()
- {
- PawnsAss();
- RooksAss();
- KnightsAss();
- BishopsAss();
- RoyalsAss();
- }
- static void PawnsAss()
- {
- //black pawns
- for (int x = 0; x < chessGrid.GetLength(0); x++)
- {
- chessGrid[x, 1] = 80; //R
- }
- //white pawns
- for (int x = 0; x < chessGrid.GetLength(0); x++)
- {
- chessGrid[x, 6] = 112; //r
- }
- }
- static void RooksAss()
- {
- //black rooks
- chessGrid[0, 0] = 82; //R
- chessGrid[7, 0] = 82; //R
- //white rooks
- chessGrid[0, 7] = 114; //r
- chessGrid[7, 7] = 114; //r
- }
- static void KnightsAss()
- {
- //black knights
- chessGrid[1, 0] = 72; //H
- chessGrid[6, 0] = 72; //H
- //white knights
- chessGrid[1, 7] = 104; //h
- chessGrid[6, 7] = 104; //h
- }
- static void BishopsAss()
- {
- //black bishops
- chessGrid[2, 0] = 66; //B
- chessGrid[5, 0] = 66; //B
- //white bishops
- chessGrid[2, 7] = 98; //b
- chessGrid[5, 7] = 98; //b
- }
- static void RoyalsAss()
- {
- //black pieces
- chessGrid[3, 0] = 81; //Q
- chessGrid[4, 0] = 75; //K
- //white pieces
- chessGrid[3, 7] = 113; //q
- chessGrid[4, 7] = 107; //k
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement