[ create a new paste ] login | about

Link: http://codepad.org/dKQk4ykF    [ raw code | output | fork ]

C, pasted on Jun 12:
#include <stdio.h>

typedef struct _Map {
    int monster;
    int hp;
    int attack;
} Map;

Map m[6][6];

int fight (int HP, int AT, int x, int y, int been[6][6]) {

    if (x>5 || y>5 || x<1 || y<1 || been[y][x]) return 0;

    been[y][x] = 1;
    if (m[y][x].monster) {
        int m_hp = m[y][x].hp;
        m_hp -= AT;
        while (m_hp > 0) {
            HP -= m[y][x].attack;
            if (HP <= 0) return 0;
            m_hp -= AT;
        }
    }

    if (x==5 && y==5) return 1;
    else if (fight(HP, AT, x+1, y, been) || fight(HP, AT, x, y+1, been) ||
             fight(HP, AT, x-1, y, been) || fight(HP, AT, x, y-1, been)) return 1;
    else return 0;

}

int main(int argc, const char * argv[]) {

    int k, HP, AT, h, a, x, y;
    scanf("%d%d%d", &HP, &AT, &k);

    for (int j=1; j<=5; j++) {
        for (int i=1; i<=5; i++) {
            m[j][i].monster = 0;
        }
    }

    while (k--) {
        scanf("%d%d%d%d", &h, &a, &x, &y);
        m[y][x].monster = 1;
        m[y][x].hp = h;
        m[y][x].attack = a;
    }
    /*
    for (int j=1; j<=5; j++) {
        for (int i=1; i<=5; i++) {
            printf("%d ", m[j][i].monster);
        }
        printf("\n");
    }*/

    int been[6][6] = {0};

    if (m[5][5].monster) {
        int m_hp = m[5][5].hp;
        m_hp -= AT;
        while (m_hp > 0) {
            HP -= m[5][5].attack;
            if (HP <= 0) {
                printf("YOU DIED\n");
                return 0;
            }
            m_hp -= AT;
        }
        m[5][5].monster = 0;

    }

    if (fight(HP, AT, 1, 1, been)) printf("HEIR OF FIRE DESTROYED\n");
    else printf("YOU DIED\n");

    return 0;
}


Output:
1
2
3
In function 'main':
Line 38: error: 'for' loop initial declaration used outside C99 mode
Line 39: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: