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