1 /*
2 * @(#) scan.c - scan functions for trojka
3 * created: 4.iii.1992
4 * last update: 6.iii.1992
5 */
6
7 #include <curses.h>
8
9 #include "trojka.h"
10
11 int scan(),
12 fieldscan(),
13 explode(),
14 shifblocks(),
15 shiftdown(),
16 getstacklevel(),
17 isempty(),
18 reset_f();
19
20 extern unsigned long
21 score,
22 wipes;
23
24 extern char
25 field[VIRT_XSIZE][VIRT_YSIZE];
26
27 extern int stacklevel;
28
29 char f[VIRT_XSIZE][VIRT_YSIZE];
30 /* shadow matrix, where 'tagged' blocks are kept */
31
scan()32 int scan()
33 {
34
35 int wipe_bonus, wipe_count, wiped;
36
37 wipe_bonus = 1;
38 wipe_count = 0;
39
40 while((wiped = fieldscan()) > 0) {
41 explode();
42
43 delay(100);
44 shiftblocks();
45
46 wipe_bonus *= 2;
47 score += (unsigned long)(wipe_bonus * wiped * 10);
48 showscore();
49
50 wipe_count++;
51 if(((int)wipe_count % TROJKA) == 0)
52 handletrojka(wipe_count); /* trojka ! */
53
54 wipes++;
55 }
56 return(stacklevel);
57 }
58
59
fieldscan()60 int fieldscan()
61 {
62 int x, y, wiped, left, right;
63
64 stacklevel = getstacklevel();
65 wiped = 0;
66
67 left = 0 + 1;
68 right = VIRT_XSIZE - 1;
69 for(x = left; x < right; x++)
70 for(y = stacklevel; y >= PLM_BOTTOM; y--) {
71 if(field[x][y] > 0) {
72 /* "\" */ if ((field[x-1][y-1] == field[x][y])
73 && (field[x][y] == field[x+1][y+1])) {
74 f[x-1][y-1] = f[x+1][y+1] = f[x][y] = TAGGED;
75 wiped++;
76 }
77 /* "/" */ if ((field[x-1][y+1] == field[x][y])
78 && (field[x][y] == field[x+1][y-1])) {
79 f[x-1][y+1] = f[x][y] = f[x+1][y-1] = TAGGED;
80 wiped++;
81 }
82 /* "--" */ if ((field[x-1][y] == field[x][y])
83 && (field[x][y] == field[x+1][y])) {
84 f[x-1][y] = f[x+1][y] = f[x][y] = TAGGED;
85 wiped++;
86 }
87 }
88 }
89 return(wiped * 3);
90 }
91
92
explode()93 int explode() /* make fancy stars */
94 {
95 int x,y;
96
97 for(x = 0; x < VIRT_XSIZE; x++)
98 for(y = stacklevel; y > 0; y--)
99 if(f[x][y] == TAGGED)
100 makestars(x, y);
101 }
102
103
shiftblocks()104 int shiftblocks()
105 {
106 int x, y;
107
108 for(x = 0; x < VIRT_XSIZE; x++)
109 for(y = stacklevel; y > 0; y--)
110 if(f[x][y] == TAGGED) {
111 shiftdown(x, y);
112 f[x][y] = CLEAR;
113 }
114 refresh();
115 }
116
117
shiftdown(x,y)118 int shiftdown(x, y) /* both visual and virtual */
119 int x, y;
120 {
121 while(field[x][y] != CLEAR) {
122 field[x][y] = field[x][y+1];
123 makeblock(x, y, field[x][y]);
124 y++;
125 }
126 }
127
128
getstacklevel()129 int getstacklevel()
130 /* returns the last empty line in the virtual field */
131 {
132 int y = PLM_TOP;
133
134 while(isempty(y))
135 y--;
136 return(y);
137 }
138
139
isempty(y)140 int isempty(y)
141 int y;
142 {
143 int x;
144
145 for(x = 0; x < VIRT_XSIZE; x++)
146 if(field[x][y] != CLEAR)
147 return(FALSE);
148 return(TRUE);
149 }
150
151
reset_f()152 int reset_f()
153 {
154 int x,y;
155
156 for(x = 0; x < VIRT_XSIZE;x++)
157 for(y = 0; y < VIRT_YSIZE;y++)
158 f[x][y] = CLEAR;
159 }
160