Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
5.1 kB
5
Indexable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    internal class Board
    {
        public int selectedPieceX;
        public int selectedPieceY; 

        char[,] mainBoard = {
                {   ' ',' ',' ',' ',' ','0','-','-','0','-','-','0',' ',' ',' ',' ',' '},
                {   ' ',' ',' ',' ',' ',' ','\\',' ','|',' ','/',' ',' ',' ',' ',' ',' '},
                {   ' ',' ',' ',' ',' ',' ','0','-','0','-','0',' ',' ',' ',' ',' ',' '},
                {   ' ',' ',' ',' ',' ',' ',' ','\\','|','/',' ',' ',' ',' ',' ',' ',' '},
                {   'E',' ',' ',' ','0','-','0','-','0','-','0','-','0',' ',' ',' ','E',},
                {   '|','\\',' ',' ','|','\\','|','/','|','\\','|','/','|',' ',' ','/','|'},
                {   '|',' ','E',' ','0','-','0','-','0','-','0','-','0',' ','E',' ','|',},
                {   '|',' ','|','\\','|','/','|','\\','|','/','|','\\','|','/','|',' ','|'},
                {   'E','-','E','-','E','-','E','-','E','-','E','-','E','-','E','-','E',},
                {   '|',' ','|','/','|','\\','|','/','|','\\','|','/','|','\\','|',' ','|',},
                {   '|',' ','E',' ','*','-','*','-','*','-','*','-','*',' ','E',' ','|',},
                {   '|','/',' ',' ','|','/','|','\\','|','/','|','\\','|',' ',' ','\\','|'},
                {   'E',' ',' ',' ','*','-','*','-','*','-','*','-','*',' ',' ',' ','E',},
                {   ' ',' ',' ',' ',' ',' ',' ','/','|','\\',' ',' ',' ',' ',' ',' ',' ',},
                {   ' ',' ',' ',' ',' ',' ','*','-','*','-','*',' ',' ',' ',' ',' ',' ',},
                {   ' ',' ',' ',' ',' ',' ','/',' ','|',' ','\\',' ',' ',' ',' ',' ',' ',},
                {   ' ',' ',' ',' ',' ','*','-','-','*','-','-','*',' ',' ',' ',' ',' ',},
         };

        public bool PlacePiece(int row, int col, char piece)
        {
            if (row >= 0 && row < mainBoard.GetLength(0) && col >= 0 && col < mainBoard.GetLength(1))
            {
                if (mainBoard[row, col] == 'E')
                {
                    mainBoard[row, col] = piece;
                    return true; //วางได้
                }
                else
                {
                    Console.WriteLine("This position already has pieces.");
                    return false; //มีหมากแล้ว
                }
            }
            else
            {
                Console.WriteLine("ERROR");
                return false; // นอกพื้นที่
            }
        }

        public void CheckPath(int row , int col , int targetRow , int targetCol) 
        {
            if ( Math.Abs( targetRow - row) == 2 || Math.Abs (targetCol - col) == 2) 
            {
                if(targetRow - row == 2) 
                {
                    switch (targetCol-col) 
                    { 

                    }
                }
            }
            else 
            {
                Console.WriteLine("You can't pass, Please try again");
            }
        }

        public void ClearPiece(int row, int col)
        {
            if (row >= 0 && row < mainBoard.GetLength(0) && col >= 0 && col < mainBoard.GetLength(1))
            {
                mainBoard[row, col] = 'E';
            }
            else
            {
                Console.WriteLine("ERROR");           
            }
        }

        public void SelectPiece(int row, int col, char piece) 
        {

            if (row >= 0 && row < mainBoard.GetLength(0) && col >= 0 && col < mainBoard.GetLength(1))
            {
                if (mainBoard[row, col] == piece)
                {
                    selectedPieceY= col;
                    selectedPieceX= row;

                }
                else
                {
                    Console.WriteLine("This is not your piece.");
                }
            }

            else
            {
                Console.WriteLine("ERROR");
            }
        }

        public void PrintBoard()
        {
            for (int row = 0; row < mainBoard.GetLength(0); row++)
            {
                for (int col = 0; col < mainBoard.GetLength(1); col++)
                {
                    char currentChar = mainBoard[row, col];

                    if (currentChar == '*')
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }
                    else if (currentChar == '0')
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                    }
                    else
                    {
                        Console.ResetColor();
                    }
                    Console.Write(mainBoard[row, col]);
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
        }
    }
}