Skip to content

Commit ff67f92

Browse files
Add files via upload
1 parent f70ef91 commit ff67f92

1 file changed

Lines changed: 152 additions & 0 deletions

File tree

src/collandbuild_b02_code.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Collandbuild ver beta 0.2
2+
3+
// Source code
4+
5+
// Released into the public domain under CC0
6+
7+
#include <stdio.h>
8+
#include <stdlib.h>
9+
#include <conio.h>
10+
11+
int hp,stone,dirt,spines;
12+
int px,py,max,may;
13+
int apy,apx,sa,mal;
14+
int seed,rnd;
15+
int i,j;
16+
char world[20][31],a,rw[20][30];
17+
18+
void cb()
19+
{
20+
if (a == 'x') {
21+
if (rw[py][px] == '#') stone++;
22+
if (rw[py][px] == '+') dirt++;
23+
if (rw[py][px] == '^') spines++;
24+
rw[py][px] = ' ';
25+
}
26+
if (a == 'k') {
27+
if ((px == max) && (py == may)) mal = 0;
28+
}
29+
if (a == 'z') {
30+
printf("\n?");
31+
a = getch();
32+
if (a == '1') {
33+
if (stone > 0) stone--,rw[py][px] = '#';
34+
}
35+
if (a == '2') {
36+
if (dirt > 0) dirt--,rw[py][px] = '+';
37+
}
38+
if (a == '3') {
39+
if (spines > 0) spines--,rw[py][px] = '^';
40+
}
41+
}
42+
}
43+
44+
void go_ma()
45+
{
46+
rnd = rand() % 4 + 1;
47+
if (rnd == 1) may++;
48+
if (rnd == 2) may--;
49+
if (rnd == 3) max++;
50+
if (rnd == 4) max--;
51+
}
52+
53+
void tpp()
54+
{
55+
if (sa == 1) {
56+
if (rw[py][px] == '#') py = apy,px = apx;
57+
}
58+
if (rw[py][px] == '^') hp--;
59+
if (rw[py][px] == '+') hp++;
60+
}
61+
62+
void grw()
63+
{
64+
for (i = 0; i < 20; i++) {
65+
for (j = 0; j < 30; j++) {
66+
rnd = rand() % 8 + 1;
67+
if (rnd == 2) rw[i][j] = '#';
68+
else if (rnd == 3) rw[i][j] = '+';
69+
else if (rnd == 4) rw[i][j] = '^';
70+
else rw[i][j] = ' ';
71+
}
72+
}
73+
}
74+
75+
void egrw()
76+
{
77+
for (i = 0; i < 20; i++) {
78+
for (j = 0; j < 30; j++) {
79+
rw[i][j] = ' ';
80+
}
81+
}
82+
}
83+
84+
void map()
85+
{
86+
for (i = 0; i < 20; i++) {
87+
for (j = 0; j < 30; j++) {
88+
world[i][j] = rw[i][j];
89+
}
90+
world[i][30] = '\0';
91+
}
92+
if ((py > 19) || (px > 29) || (py < 0) || (px < 0)) py = 2,px = 2;
93+
if ((may > 19) || (max > 29) || (may < 0) || (max < 0)) may = 10,max = 10;
94+
world[py][px] = '*';
95+
if (mal == 1) {
96+
world[may][max] = '@';
97+
}
98+
}
99+
100+
int main()
101+
{
102+
printf("\nPUBLIC DOMAIN SOFTWARE");
103+
printf("\nCollandbuild");
104+
printf("\nVERSION: BETA 0.2\n");
105+
printf("\nS/E?");
106+
scanf(" %c",&a);
107+
if (a == 's') {
108+
printf("\nseed:");
109+
scanf("%d",&seed);
110+
srand(seed);
111+
hp = 5,stone = 0,dirt = 0,spines = 0;
112+
mal = 1;
113+
grw();
114+
}
115+
if (a == 'e') {
116+
hp = 999,stone = 999,dirt = 999,spines = 999;
117+
mal = 0;
118+
egrw();
119+
}
120+
printf("\nIs the stone active?(y/n)");
121+
scanf(" %c",&a);
122+
if (a == 'y') sa = 1;
123+
if (a == 'n') sa = 0;
124+
py = 2,px = 2,max = 10,may = 10;
125+
do
126+
{
127+
apy = py,apx = px;
128+
map();
129+
for (i = 0; i < 20; i++) {
130+
printf("\n%s",world[i]);
131+
}
132+
printf("\nHP: %d",hp);
133+
printf("\n1 Stone: %d",stone);
134+
printf("\n2 Dirt: %d",dirt);
135+
printf("\n3 Spines: %d",spines);
136+
a = getch();
137+
system("cls");
138+
if (a == 'w') py--;
139+
if (a == 's') py++;
140+
if (a == 'd') px++;
141+
if (a == 'a') px--;
142+
cb();
143+
if (a == 'q') hp = 0;
144+
tpp();
145+
if (mal == 1) {
146+
go_ma();
147+
}
148+
}
149+
while (hp > 0);
150+
printf("\nEND GAME");
151+
return 0;
152+
}

0 commit comments

Comments
 (0)