Update IcePath.c
This commit is contained in:
parent
8ef7c9d589
commit
fce2c1f597
81
IcePath.c
81
IcePath.c
|
@ -1,12 +1,12 @@
|
|||
#define VERSION "0.11"
|
||||
#define VERSION "0.20"
|
||||
|
||||
#define N 512
|
||||
#define DELAY 25 // milliseconds
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
void printm();
|
||||
|
@ -44,7 +44,7 @@ struct infolevel { // level[0] empty
|
|||
int num;
|
||||
int height;
|
||||
int width;
|
||||
int matrix[N][N];
|
||||
char matrix[N][N];
|
||||
point start;
|
||||
point exit;
|
||||
} level[100];
|
||||
|
@ -81,8 +81,8 @@ int main() {
|
|||
}
|
||||
|
||||
void readfiles() {
|
||||
int u = 1, i = 0, j, lines = 0;
|
||||
char ch;
|
||||
int u = 1, i = 0, lines = 0, j, k, newline;
|
||||
char ch, tile;
|
||||
// read f_data
|
||||
rewind(f_data);
|
||||
do { // count lines
|
||||
|
@ -104,26 +104,40 @@ void readfiles() {
|
|||
do { // read from line 5
|
||||
ch = fgetc(f_info);
|
||||
if (ch == '\n')
|
||||
lines++;;
|
||||
lines++;
|
||||
} while (lines < 5);
|
||||
do {
|
||||
|
||||
fscanf(f_info, "%d.%d %s %dx%d", &level[u].world, &level[u].num, level[u].name, &level[u].height, &level[u].width);
|
||||
fscanf(f_info, "%d.%d %s", &level[u].world, &level[u].num, level[u].name);
|
||||
newline = j = k = 0;
|
||||
if (level[u].world != 999) {
|
||||
for (i = 0; i < level[u].height; i++){
|
||||
for (j = 0; j < level[u].width; j++) {
|
||||
fscanf(f_info, "%d ", &level[u].matrix[i][j]);
|
||||
if(level[u].matrix[i][j] == 1){
|
||||
level[u].matrix[i][j] = 0;
|
||||
level[u].start.x = j;
|
||||
level[u].start.y = i;
|
||||
level[u].width = level[u].height = 0;
|
||||
while (newline < 2) {
|
||||
if (level[u].width == 0)
|
||||
level[u].width = k;
|
||||
k = 0;
|
||||
while (1) {
|
||||
tile = fgetc(f_info);
|
||||
if (tile == '\n') {
|
||||
newline++;
|
||||
break;
|
||||
}
|
||||
if (level[u].matrix[i][j] == 3) {
|
||||
level[u].exit.x = j;
|
||||
level[u].exit.y = i;
|
||||
newline = 0;
|
||||
level[u].matrix[j][k] = tile;
|
||||
if(level[u].matrix[j][k] == 'A') {
|
||||
level[u].matrix[j][k] = ' ';
|
||||
level[u].start.x = k;
|
||||
level[u].start.y = j;
|
||||
}
|
||||
if (level[u].matrix[i][j] == 'B') {
|
||||
level[u].exit.x = k;
|
||||
level[u].exit.y = j;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
j++;
|
||||
level[u].height++;
|
||||
}
|
||||
level[u].height -= 2;
|
||||
}
|
||||
u++;
|
||||
} while (level[u-1].world != 999);
|
||||
|
@ -215,7 +229,7 @@ void move_ptr(int direction) {
|
|||
switch (direction) {
|
||||
case KEY_LEFT:
|
||||
moves++;
|
||||
while (ptr.x != 0 && level[selected.pos].matrix[ptr.y][ptr.x-1] != 3) {
|
||||
while (ptr.x != 0 && level[selected.pos].matrix[ptr.y][ptr.x-1] != '+') {
|
||||
ptr.x--;
|
||||
printm();
|
||||
refresh();
|
||||
|
@ -227,7 +241,7 @@ void move_ptr(int direction) {
|
|||
} break;
|
||||
case KEY_RIGHT:
|
||||
moves++;
|
||||
while (ptr.x < level[selected.pos].width - 1 && level[selected.pos].matrix[ptr.y][ptr.x+1] != 3){
|
||||
while (ptr.x < level[selected.pos].width - 1 && level[selected.pos].matrix[ptr.y][ptr.x+1] != '+'){
|
||||
ptr.x++;
|
||||
printm();
|
||||
refresh();
|
||||
|
@ -239,7 +253,7 @@ void move_ptr(int direction) {
|
|||
} break;
|
||||
case KEY_UP:
|
||||
moves++;
|
||||
while (ptr.y > 0 && level[selected.pos].matrix[ptr.y-1][ptr.x] != 3) {
|
||||
while (ptr.y > 0 && level[selected.pos].matrix[ptr.y-1][ptr.x] != '+') {
|
||||
ptr.y--;
|
||||
printm();
|
||||
refresh();
|
||||
|
@ -251,7 +265,7 @@ void move_ptr(int direction) {
|
|||
} break;
|
||||
case KEY_DOWN:
|
||||
moves++;
|
||||
while (ptr.y < level[selected.pos].height - 1 && level[selected.pos].matrix[ptr.y+1][ptr.x] != 3) {
|
||||
while (ptr.y < level[selected.pos].height - 1 && level[selected.pos].matrix[ptr.y+1][ptr.x] != '+') {
|
||||
ptr.y++;
|
||||
printm();
|
||||
refresh();
|
||||
|
@ -276,7 +290,7 @@ void printm() {
|
|||
printw("Warning! Keep this window in fullscreen mode please\n\n\n");
|
||||
while (left + right < 18 && (a == 1 || a == 2)) {
|
||||
a = 0;
|
||||
if (ptr.x - left - 1 > 0) {
|
||||
if (ptr.x - left > 0) {
|
||||
left++;
|
||||
a++;
|
||||
}
|
||||
|
@ -291,21 +305,19 @@ void printm() {
|
|||
up++;
|
||||
b++;
|
||||
}
|
||||
if (ptr.y + down + 1 < level[selected.pos].height) {
|
||||
if (ptr.y + down < level[selected.pos].height) {
|
||||
down++;
|
||||
b++;
|
||||
}
|
||||
}
|
||||
for (i = ptr.y - up - 1; i <= ptr.y + down; i++) {
|
||||
for (j = ptr.x - left - 1; j <= ptr.x + right; j++) {
|
||||
for (i = ptr.y - up; i <= ptr.y + down; i++) {
|
||||
for (j = ptr.x - left; j <= ptr.x + right; j++) {
|
||||
if (i == ptr.y && j == ptr.x) {
|
||||
printw("YOU");
|
||||
} else {
|
||||
switch (level[selected.pos].matrix[i][j]) {
|
||||
case 0: printw(" "); break;
|
||||
case 3: printw("|/|"); break;
|
||||
case 2: printw("( )"); break;
|
||||
default: printw("?"); break;
|
||||
case 'B': printw("()"); break;
|
||||
default: printw("%c", level[selected.pos].matrix[i][j]); break;
|
||||
}
|
||||
}
|
||||
printw("\t");
|
||||
|
@ -328,8 +340,9 @@ int searchlevel() {
|
|||
if (level[i].num == selected.level && level[i].world == selected.world)
|
||||
return i;
|
||||
}
|
||||
// else go to level 1.1
|
||||
selected.level = selected.world = 1;
|
||||
// else go to level 0.1
|
||||
selected.world = 0;
|
||||
selected.level = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -377,7 +390,7 @@ void ranking() {
|
|||
struct dataresult temp;
|
||||
char *time_string[N];
|
||||
readfiles();
|
||||
// sort data
|
||||
// reord data
|
||||
for (i = 0; data[i].moves != 0; i++) {
|
||||
for (j = i + 1; data[j].moves != 0; j++) {
|
||||
if (data[i].moves > data[j].moves) {
|
||||
|
@ -427,7 +440,7 @@ void rules() {
|
|||
}
|
||||
|
||||
int checkwin() {
|
||||
if (level[selected.pos].matrix[ptr.y][ptr.x] == 2){
|
||||
if (level[selected.pos].matrix[ptr.y][ptr.x] == 'B'){
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
|
|
Loading…
Reference in New Issue