示例#1
0
        public static Figure GetFigureType(char code)
        {
            Figure temp = new Figure();
            switch(code) {
                case 'P': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.Pawn;
                        break;
                    }
                case 'R': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.Rook;
                        break;
                    }
                case 'N': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.Knight;
                        break;
                    }
                case 'B': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.Bishop;
                        break;
                    }
                case 'K': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.King;
                        break;
                    }
                case 'Q': {
                        temp.Color = FigureColor.White;
                        temp.Type = FigureType.Queen;
                        break;
                    }

                case 'p': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.Pawn;
                        break;
                    }
                case 'r': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.Rook;
                        break;
                    }
                case 'n': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.Knight;
                        break;
                    }
                case 'b': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.Bishop;
                        break;
                    }
                case 'k': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.King;
                        break;
                    }
                case 'q': {
                        temp.Color = FigureColor.Black;
                        temp.Type = FigureType.Queen;
                        break;
                    }
                default: {
                        temp.Color = FigureColor.Empty;
                        temp.Type = FigureType.Empty;
                        break;
                    }

            }
            return temp;
        }
示例#2
0
 public static Figure[,] Parse(string Notation)
 {
     const char EOLN = ' ';
     Figure[,] cells = new Figure[8, 8];
     int counter = 0, rowNumber = 0, value = 0, index = 0;
     char cursor = Notation[0];
     bool result = false;
     while(cursor != EOLN) {
         if(cursor == '/') {
             counter++;
             cursor = Notation[counter];
             index = 0;
             rowNumber++;
             continue;
         }
         result = System.Int32.TryParse(cursor.ToString(), out value);
         if(result) {
             for(int i = 1; i <= value; i++) {
                 cells[rowNumber, index] = GetFigureType(cursor);
                 index++;
             }
         } else {
             cells[rowNumber, index] = GetFigureType(cursor);
             index++;
         }
         counter++;
         cursor = Notation[counter];
     }
     return cells;
 }