-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
147 lines (114 loc) · 1.96 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <ncurses.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define WHITE_BLACK 8
#define WHITE_RED 9
#define WHITE_GREEN 10
#define WHITE_YELLOW 11
#define WHITE_BLUE 12
#define WHITE_MAGENTA 13
#define WHITE_CYAN 14
#define WHITE_WHITE 15
int getlen(), mrand(), find();
typedef struct vector {
int x;
int y;
} vector;
#define vect_new(x, y) (vector){x, y}
#define vect_equals(pos1, pos2) (pos1.y == pos2.y && pos1.x == pos2.x)
vector vect_norm();
int WIN_H, WIN_W;
int PLAYER_COLOR = COLOR_RED;
#include "weapons.h"
typedef struct player {
int life;
int maxlife;
WEAPON weapon;
int potions;
int level;
vector pos;
} PLAYER;
#include "enemies.h"
#include "shop.h"
#include "arena.h"
#include "main_menu.h"
int main()
{
time_t t;
srand((unsigned) time(&t));
initscr();
noecho();
start_color();
curs_set(0);
keypad(stdscr, TRUE);
cbreak();
for (int i = 0; i < 8; ++i)
init_pair(i, i, COLOR_BLACK);
for (int i = 8; i < 16; ++i)
init_pair(i, i, COLOR_WHITE);
getmaxyx(stdscr, WIN_H, WIN_W);
int window_too_small = false;
if (WIN_W >= 80 && WIN_H >= 35)
show_main_menu();
else
window_too_small = true;
clear();
endwin();
if (window_too_small)
printf("\nYour terminal window is too small! (Needs to be at least 80x35)\n\n");
return(0);
}
vector vect_norm(pos)
vector pos;
{
if (pos.x >= 1)
pos.x = 1;
else if (pos.x <= -1)
pos.x = -1;
else
pos.x = 0;
if (pos.y >= 1)
pos.y = 1;
else if (pos.y <= -1)
pos.y = -1;
else
pos.y = 0;
return(pos);
}
int mrand(n1, n2)
int n1, n2;
{
int out = -1;
++n1;
++n2;
while (out < n1)
out = rand() % n2+1;
return(out-1);
}
int find(s1, s2)
char *s1, *s2;
{
int i;
for (i=0; i <= getlen(s1); ++i)
{
if (s1[i] == s2[0])
{
for (int a = 1; a < getlen(s2); ++a)
{
if (s1[i+a] != s2[i+a])
break;
}
return(i);
}
}
return(-1);
}
int getlen(string)
char string[];
{
int i;
for (i = 0; string[i] != '\0'; ++i);
return(i);
}