Purely tangential to this code discussion, but on the topic of code quality and keeping display code clean, check out this totally reasonable block of code from a prototype I made (this is the high score screen from LCS):
// Title of the screen
set_color(Color.WHITE);
addstr_move(0, 0, "The Liberal ELITE");
// Show top scores
for(var s:int=0; s < MAX_SCORES_SHOWN && s < Game.highScores.length; s++)
{
var y:int = 2 + s * 4;
// Special colors for showing your squad's fate, if relevant
if (Game.yourHighScoreIndex == s) {
if (Game.highScores[s].endtype == Endings.WON) {
set_color(Color.BRIGHT_GREEN);
} else set_color(Color.BRIGHT_RED);
} else set_color(Color.WHITE);
// Slogan
addstr_move(y, 0, Game.highScores[s].slogan);
// Dimmer colors for other stats
if (Game.yourHighScoreIndex == s) {
if (Game.highScores[s].endtype == Endings.WON) {
set_color(Color.DARK_GREEN);
} else set_color(Color.DARK_RED);
} else set_color(Color.LIGHT_GRAY);
// Cause of death (or victory string)
addstr_move(y + 1, 0, Game.highScores[s].endstring);
// Stats
addstr_move(y + 2, 0, "Recruits: " + Game.highScores[s].stats.recruits);
addstr_move(y + 3, 0, "Martyrs: " + Game.highScores[s].stats.dead);
addstr_move(y + 2, 20, "Kills: " + Game.highScores[s].stats.kills);
addstr_move(y + 3, 20, "Kidnappings: " + Game.highScores[s].stats.kidnappings);
addstr_move(y + 2, 40, "$ Taxed: " + Game.highScores[s].stats.funds);
addstr_move(y + 3, 40, "$ Spent: " + Game.highScores[s].stats.spent);
addstr_move(y + 2, 60, "Flags Bought: " + Game.highScores[s].stats.flags);
addstr_move(y + 3, 60, "Flags Burned: " + Game.highScores[s].stats.flagburns);
}
// Universal stats
set_color(Color.BRIGHT_GREEN);
addstr_move(22, 0, "Universal Liberal Statistics");
addstr_move(23, 0, "Recruits: " + Game.universalStats.recruits);
addstr_move(24, 0, "Martyrs: " + Game.universalStats.dead);
addstr_move(23, 20, "Kills: " + Game.universalStats.kills);
addstr_move(24, 20, "Kidnappings: " + Game.universalStats.kidnappings);
addstr_move(23, 40, "$ Taxed: " + Game.universalStats.funds);
addstr_move(24, 40, "$ Spent: " + Game.universalStats.spent);
addstr_move(23, 60, "Flags Bought: " + Game.universalStats.flags);
addstr_move(24, 60, "Flags Burned: " + Game.universalStats.flagburns);
The same high score screen in the normal code:
49 set_color(COLOR_WHITE,COLOR_BLACK,1);
50 move(0,0);
51 addstr("The Liberal ELITE");
52
53 char num[20];
54
55 int y=2;
56 for(s=0;s<SCORENUM;s++)
57 {
58 if(score[s].valid)
59 {
60 if(yourscore==s&&score[s].endtype==END_WON)set_color(COLOR_GREEN,COLOR_BLACK,1);
61 else if(yourscore==s)set_color(COLOR_RED,COLOR_BLACK,1);
62 else set_color(COLOR_WHITE,COLOR_BLACK,1);
63 move(y,0);
64 addstr(score[s].slogan);
65 if(yourscore==s&&score[s].endtype==END_WON)set_color(COLOR_GREEN,COLOR_BLACK,0);
66 else if(yourscore==s)set_color(COLOR_RED,COLOR_BLACK,0);
67 else set_color(COLOR_WHITE,COLOR_BLACK,0);
68 move(y+1,0);
69 switch(score[s].endtype)
70 {
71 case END_WON:
72 addstr("The Liberal Crime Squad liberalized the country in ");
73 break;
74 case END_POLICE:
75 addstr("The Liberal Crime Squad was brought to justice in ");
76 break;
77 case END_CIA:
78 addstr("The Liberal Crime Squad was blotted out in ");
79 break;
80 case END_HICKS:
81 addstr("The Liberal Crime Squad was mobbed in ");
82 break;
83 case END_CORP:
84 addstr("The Liberal Crime Squad was downsized in ");
85 break;
86 case END_DEAD:
87 addstr("The Liberal Crime Squad was KIA in ");
88 break;
89 case END_REAGAN:
90 addstr("The country was Reaganified in ");
91 break;
92 case END_PRISON:
93 addstr("The Liberal Crime Squad died in prison in ");
94 break;
95 case END_EXECUTED:
96 addstr("The Liberal Crime Squad was executed in ");
97 break;
98 case END_DATING:
99 addstr("The Liberal Crime Squad was on vacation in ");
100 break;
101 case END_HIDING:
102 addstr("The Liberal Crime Squad was in permanent hiding in ");
103 break;
104 case END_DISBANDLOSS:
105 addstr("The Liberal Crime Squad was hunted down in ");
106 break;
107 case END_DISPERSED:
108 addstr("The Liberal Crime Squad was scattered in ");
109 break;
110 case END_CCS:
111 addstr("The Liberal Crime Squad was out-Crime Squadded in ");
112 break;
113 case END_FIREMEN:
114 addstr("The Liberal Crime Squad was burned in ");
115 break;
116 }
117 switch(score[s].month)
118 {
119 case 1:addstr("January");break;
120 case 2:addstr("February");break;
121 case 3:addstr("March");break;
122 case 4:addstr("April");break;
123 case 5:addstr("May");break;
124 case 6:addstr("June");break;
125 case 7:addstr("July");break;
126 case 8:addstr("August");break;
127 case 9:addstr("September");break;
128 case 10:addstr("October");break;
129 case 11:addstr("November");break;
130 case 12:addstr("December");break;
131 }
132 addstr(" ");
133 itoa(score[s].year,num,10);
134 addstr(num);
135 addstr(". ");
136
137 move(y+2,0);
138 addstr("Recruits: ");
139 itoa(score[s].stat_recruits,num,10);
140 addstr(num);
141
142 move(y+3,0);
143 addstr("Martyrs: ");
144 itoa(score[s].stat_dead,num,10);
145 addstr(num);
146
147 move(y+2,20);
148 addstr("Kills: ");
149 itoa(score[s].stat_kills,num,10);
150 addstr(num);
151
152 move(y+3,20);
153 addstr("Kidnappings: ");
154 itoa(score[s].stat_kidnappings,num,10);
155 addstr(num);
156
157 move(y+2,40);
158 addstr("$ Taxed: ");
159 itoa(score[s].stat_funds,num,10);
160 addstr(num);
161
162 move(y+3,40);
163 addstr("$ Spent: ");
164 itoa(score[s].stat_spent,num,10);
165 addstr(num);
166
167 move(y+2,60);
168 addstr("Flags Bought: ");
169 itoa(score[s].stat_buys,num,10);
170 addstr(num);
171
172 move(y+3,60);
173 addstr("Flags Burned: ");
174 itoa(score[s].stat_burns,num,10);
175 addstr(num);
176
177 y+=4;
178 }
179 }
180
181 set_color(COLOR_GREEN,COLOR_BLACK,1);
182
183 //UNIVERSAL STATS
184 move(22,0);
185 addstr("Universal Liberal Statistics:");
186
187 move(23,0);
188 addstr("Recruits: ");
189 itoa(ustat_recruits,num,10);
190 addstr(num);
191
192 move(24,0);
193 addstr("Martyrs: ");
194 itoa(ustat_dead,num,10);
195 addstr(num);
196
197 move(23,20);
198 addstr("Kills: ");
199 itoa(ustat_kills,num,10);
200 addstr(num);
201
202 move(24,20);
203 addstr("Kidnappings: ");
204 itoa(ustat_kidnappings,num,10);
205 addstr(num);
206
207 move(23,40);
208 addstr("$ Taxed: ");
209 itoa(ustat_funds,num,10);
210 addstr(num);
211
212 move(24,40);
213 addstr("$ Spent: ");
214 itoa(ustat_spent,num,10);
215 addstr(num);
216
217 move(23,60);
218 addstr("Flags Bought: ");
219 itoa(ustat_buys,num,10);
220 addstr(num);
221
222 move(24,60);
223 addstr("Flags Burned: ");
224 itoa(ustat_burns,num,10);
225 addstr(num);