Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {*****************************
- * created by Kirill Halo *
- * https://vk.com/itmentor *
- *****************************}
- program Chess;
- uses crt, graphABC;
- const FLAG_ATTACK = -1;
- const LocationFigures : array[0..7,0..7] of integer =((0,0,0,0,0,0,0,0),
- (0,0,0,0,0,0,0,0),
- (0,0,1,0,0,0,0,0),
- (0,0,0,0,0,0,0,0),
- (0,0,0,0,0,0,0,0),
- (0,0,0,0,0,1,1,0),
- (0,0,0,0,0,0,0,0),
- (0,0,0,0,0,0,0,0));
- type TMatr = array[0..7, 0..7] of integer;
- var
- PlacesAttackFigures : TMatr;
- xCenter : integer;
- yCenter : integer;
- WidthBoard : integer;
- HeightBoard : integer;
- XCellCount : integer;
- YCellCount : integer;
- WidthCell : integer;
- HeightCell : integer;
- CountCell : integer;
- {Инициализация начальных параметров}
- procedure InitializationInitialParameters;
- begin
- xCenter := WindowWidth div 2;
- yCenter := WindowHeight div 2;
- setPixel(xCenter, yCenter, clGray);
- WidthBoard := 300;
- HeightBoard := 300;
- XCellCount := 8;
- YCellCount := 8;
- WidthCell := WidthBoard div XCellCount;
- HeightCell := HeightBoard div YCellCount;
- CountCell := XCellCount * YCellCount;
- end;
- { Заполнение матрицы занятых(ударных) мест}
- procedure FillPlacesAttackFigures(var PlacesAttackFigures : TMatr;
- RowCount, ColCount : integer);
- var ix, iy : integer;
- attack_x, attack_y : integer;
- begin
- for iy := 0 to RowCount - 1 do
- for ix := 0 to ColCount - 1 do
- PlacesAttackFigures[iy, ix] := 0;
- for iy := 0 to RowCount - 1 do
- for ix := 0 to ColCount - 1 do
- begin
- if(LocationFigures[iy, ix] = 1) then
- begin
- for attack_y := 0 to RowCount - 1 do
- PlacesAttackFigures[attack_y, ix] := FLAG_ATTACK;
- for attack_x := 0 to ColCount - 1 do
- PlacesAttackFigures[iy, attack_x] := FLAG_ATTACK;
- end;
- end;
- end;
- {Метод, возвращается число свободных мест}
- function GetCountFreePlaces(PlacesAttackFigures : TMatr;
- RowCount, ColCount : integer):integer;
- var ix, iy : integer;
- count : integer;
- begin
- count := 0;
- for iy := 0 to RowCount - 1 do
- for ix := 0 to ColCount - 1 do
- if(PlacesAttackFigures[iy, ix] <> FLAG_ATTACK) then inc(count);
- result := count;
- end;
- {Рисование одной ячейки
- 1 - цвет серый
- 0 - цвет белый
- FLAG_ATTACK - цвет красный}
- procedure DrawingSingleCell(x, y : integer; c : integer);
- begin
- if (c = 1) then
- SetBrushColor(clGray)
- else if (c = 0) then
- SetBrushColor(clWhite)
- else if (c = FLAG_ATTACK) then
- SetBrushColor(RGB(122,0,0))
- else
- write('Error!');
- Rectangle(x, y, x + WidthCell, y + HeightCell);
- end;
- {Рисование ладьи в клетке с координатой (x;y) }
- procedure DrawingRookInCell(x, y : integer);
- var d:integer;
- begin
- SetBrushColor(clBlack);
- d := 10;
- Rectangle(x + d, y + d, x + 4 + d, y + 4 + d );
- Rectangle(x + 8 + d, y + d, x + 12 + d, y + 4 + d);
- Rectangle(x + 16 + d, y + d, x + 20 + d, y + 4 + d);
- Rectangle(x + d, y + 4 + d, x + 20 + d, y + 10 + d);
- Rectangle(x + 4 + d, y + 10 + d, x + 16 + d, y + 20 + d);
- Rectangle(x + d, y + 20 + d, x + 20 + d, y + 26 + d);
- end;
- {Рисование доски}
- procedure DrawBoard;
- var x, y : integer;
- x0, y0 : integer;
- k, iy, ix : integer;
- begin
- //Setbrushstyle(bsClear);
- SetPenColor(clBlack);
- Rectangle(xCenter - WidthBoard div 2, yCenter - HeightBoard div 2,
- xCenter + WidthBoard div 2, yCenter + HeightBoard div 2);
- x0 := xCenter - WidthBoard div 2;
- y0 := yCenter - HeightBoard div 2;
- for k := 0 to CountCell - 1 do
- begin
- iy := k div XCellCount; ix := k mod XCellCount;
- x := x0 + ix * WidthCell + 2;
- y := y0 + iy * HeightCell + 2;
- if(PlacesAttackFigures[iy, ix] = FLAG_ATTACK ) then
- DrawingSingleCell(x, y, FLAG_ATTACK) //Запрещенные ячейки
- else
- DrawingSingleCell(x, y, (ix + iy + 1) mod 2); //цвет меняется через остаток по модулю 2
- end;
- end;
- {Расстановка фигур, согласно матрице}
- procedure PlacementOfFigures(arr : TMatr; RowCount, ColCount : integer);
- var ix, iy : integer;
- x0, y0 : integer;
- x, y : integer;
- begin
- x0 := xCenter - WidthBoard div 2;
- y0 := yCenter - HeightBoard div 2;
- for ix := 0 to RowCount - 1 do
- for iy := 0 to ColCount - 1 do
- begin
- if(arr[iy, ix] = 1) then
- begin
- x := x0 + ix * WidthCell;
- y := y0 + iy * HeightCell;
- DrawingRookInCell(x, y);
- end;
- end;
- end;
- {Main}
- begin
- InitializationInitialParameters;
- FillPlacesAttackFigures(PlacesAttackFigures, XCellCount, YCellCount);
- DrawBoard;
- PlacementOfFigures(LocationFigures, YCellCount, XCellCount);
- writeln('Число свободных мест: ', GetCountFreePlaces(PlacesAttackFigures,
- XCellCount, YCellCount));
- end.
Advertisement
Add Comment
Please, Sign In to add comment