static void Main(string[] args) //主函数,懂得都懂 { bool result = true; bool turn; int player = 0; ProCon con = new ProCon(); ProMod mod = new ProMod(); ProgramView view = new ProgramView(); Chess[,] Matrix = mod.SetPosition(); Chess[,] road = mod.SetRoad(); while (result == true) { string[,] Board = mod.Piece(Matrix); view.Displaying(Matrix, road); view.Start(player); try { Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write("============================================\n"); Console.Write(" X = "); int chozenX = Convert.ToInt32(Console.ReadLine()); Console.Write(" Y = "); int chozenY1 = Convert.ToInt32(Console.ReadLine()); int chozenY = chozenY1 * 2; int checkpiece = con.CheckPiece(chozenX * 2, chozenY, Matrix); if (checkpiece == 2) //检测是否有棋子 { road = con.Road(chozenX * 2, chozenY, Matrix); view.Displaying(Matrix, road); road = mod.SetRoad(); view.Check(checkpiece, Board, chozenX, chozenY); Console.Write(" X = "); int X = Convert.ToInt32(Console.ReadLine()); Console.Write(" Y = "); int Y = Convert.ToInt32(Console.ReadLine()); turn = con.SwitchPlayer(X * 2, Y * 2, chozenX * 2, chozenY, Matrix); player = view.Move(turn, player); result = con.Result(Matrix); } else if (checkpiece == 0) { view.Check(checkpiece, Board, chozenX, chozenY); } else { view.Check(checkpiece, Board, chozenX, chozenY); } } catch (Exception) //检测异常 { view.Wrong(); } } view.Displaying(Matrix, road); view.Win(player); //Console.ReadKey(); }
public void Displaying(Chess[,] Matrix, Chess[,] road) //打印棋盘坐标 { ProMod Mod = new ProMod(); string[,] Board = Mod.Piece(Matrix); Console.BackgroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write(" X\\Y "); for (int j = 0; j <= 17; j++) { if (j == 0) { Console.Write(j + " "); } else if (j == 16) { Console.Write(j / 2 + " "); } else if (j % 2 == 0 && j > 0) { Console.Write(j / 2 + " "); } } Console.Write("\n"); for (int i = 0; i <= 18; i++) { Console.ForegroundColor = ConsoleColor.DarkGray; if (i % 2 == 0) { Console.Write(" " + i / 2 + " "); } else { Console.Write(" "); } for (int j = 0; j < 17; j++) { if (Matrix[i, j].side == Chess.Player.black) { if (road[i, j].path == Chess.Piecepath.yes) { ColorBule(Board, i, j); road[i, j].path = Chess.Piecepath.not; } else { ColorYellow(Matrix, Board, i, j); } } else if (Matrix[i, j].side == Chess.Player.red) { if (road[i, j].path == Chess.Piecepath.yes) { ColorBule(Board, i, j); road[i, j].path = Chess.Piecepath.not; } else { ColorYellow(Matrix, Board, i, j); } } else { if (road[i, j].path == Chess.Piecepath.yes) { Console.BackgroundColor = ConsoleColor.Blue; Console.Write(Board[i, j]); Console.BackgroundColor = ConsoleColor.Yellow; road[i, j].path = Chess.Piecepath.not; } else { Console.Write(Board[i, j]); } } } if (i % 2 == 0) { Console.Write(" " + i / 2 + " "); } else { Console.Write(" "); } Console.Write("\n"); } Console.Write(" "); for (int j = 0; j <= 17; j++) { if (j == 0) { Console.Write(j + " "); } else if (j == 16) { Console.Write(j / 2 + " "); } else if (j % 2 == 0 && j > 0) { Console.Write(j / 2 + " "); } } }