Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdio.h>
- #include <stdbool.h>
- struct coord_pair{
- int x,y;
- bool exist;
- };
- struct Figure{
- struct coord_pair coords[1000];
- int lastIndex;
- bool exist;
- };
- struct Figure add_coordinate(struct Figure input, int x, int y){
- input.coords[input.lastIndex].x= x;
- input.coords[input.lastIndex].y= y;
- input.coords[input.lastIndex].exist=1;// deoarece array are fixed sized si trebuie sa adaugam
- input.lastIndex++;
- return input;
- }
- struct FigureGroup{
- struct Figure theGroup[100];
- int lastObj;
- };
- struct FigureGroup InitializeAll(struct FigureGroup FG){
- FG.lastObj = 0;
- for (int fig = 0; fig < 100; fig++){
- FG.theGroup[fig].exist = false;
- FG.theGroup[fig].lastIndex = 0;
- for (int coord = 0; coord < 100; coord++){
- FG.theGroup[fig].coords[coord].x = -1;
- FG.theGroup[fig].coords[coord].y = -1;
- FG.theGroup[fig].coords[coord].exist = false;
- }
- }
- return FG;
- }
- struct Figure createFigure(struct Figure allFigures, int figureCounter) {
- allFigures.exist = 1;
- for (int i = 0; i < 100; i++) {
- allFigures.coords[i].exist = 1;
- allFigures.lastIndex = 0;
- }
- return allFigures;
- }
- int* Move (struct Figure second_figure[], int direction, char game_map[100][100]){
- int result_array[3];
- int m_x;
- int m_y;
- switch (direction){
- case 1: m_x=0;m_y=1;break;
- case 2: m_x=1;m_y=1;break;
- case 3: m_x=1;m_y=0;break;
- case 4: m_x=1;m_y=-1;break;
- case 5: m_x=0;m_y=-1;break;
- case 6: m_x=-1;m_y=-1;break;
- case 7: m_x=-1;m_y=0;break;
- case 8: m_x=-1;m_y=1;break;
- }
- result_array[1] = m_x;
- result_array[2] = m_y;
- if (game_map[m_x][m_y] == '*'){
- result_array[0] = 0;
- return result_array;
- }
- for (int k=0;k<100;k++)
- {
- for (int l=0;l<100;l++)
- {
- if (second_figure[k].coords[l].x==m_x && second_figure[k].coords[l].y==m_y )
- {
- result_array[0] = 0;
- return result_array;
- }
- else if(second_figure[k].coords[l].x < 0 || second_figure[k].coords[l].y < 0
- || second_figure[k].coords[l].y > 99 || second_figure[k].coords[l].y > 99){
- result_array[0] = 0;
- return result_array;
- }
- }
- }
- result_array[0] = 1;
- return result_array;
- }
- struct FigureGroup ScanArray(struct FigureGroup GroupOfFigures, char chrMap[100][100], bool _recStarted){
- for (int x = 0; x < 100; x++){
- for (int y = 0; y < 100; y++){
- if (chrMap[x][y] == '@'){
- for (int i = 1; i <= 8; i++) {
- int *moveData;
- moveData = Move(GroupOfFigures.theGroup, i, chrMap);
- if (moveData[0] == 1 && _recStarted == 1) {
- GroupOfFigures.theGroup[GroupOfFigures.lastObj]
- = add_coordinate(GroupOfFigures.theGroup[GroupOfFigures.lastObj],
- moveData[2], moveData[3]);
- GroupOfFigures = ScanArray(GroupOfFigures, chrMap, 1);
- } else if (moveData[0] == 1 && _recStarted == 0) {
- GroupOfFigures.theGroup[GroupOfFigures.lastObj] =
- createFigure(GroupOfFigures.theGroup[GroupOfFigures.lastObj],
- GroupOfFigures.lastObj);
- GroupOfFigures.theGroup[GroupOfFigures.lastObj] =
- add_coordinate(GroupOfFigures.theGroup[GroupOfFigures.lastObj], moveData[1],
- moveData[2]);
- GroupOfFigures = ScanArray(GroupOfFigures, chrMap, 1);
- }
- }
- GroupOfFigures.lastObj++;
- }
- }
- }
- return GroupOfFigures;
- }
- int main() {
- char mapping [100][100];
- for (int x = 0; x < 100; x++){
- for (int y = 0; y < 100; y++){
- mapping[x][y] = '*';
- }
- }
- mapping[0][0] = '@';
- mapping[0][1] = '@';
- mapping[1][1] = '@';
- mapping[1][0] = '@';
- struct FigureGroup GrpOfFgrs;
- InitializeAll(GrpOfFgrs);
- ScanArray(GrpOfFgrs, mapping, 0);
- int numObj = GrpOfFgrs.lastObj;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement