Building Demolition
Vim, 41 38 bytes
qw:sl 500m␍q/{␍qqjk^v$r*@wdd:-␍@w@qq@q
Here, ^
is used for a literal caret; ␍ is used for CTRL-M.
Explanation
qw:sl 500m␍q
sleeps half a second, while recording the half second sleep as macro w. /{␍
moves to the floor with explosives. qq
begins recording macro q, which will recursively call itself.
jk
moves down and up; this generates an error if you're on the last line (ground); the error terminates the recursive macro. ^v$r*
replaces everything from the first non-whitespace character to the end of the line with *'s. @w
waits half a second, then dd
deletes the current floor. :-␍
moves up a floor without terminating the macro if you're on the top line. @w
then waits another half second, and @q
calls the q macro (initially empty).
q@q
stops recording the macro q, then calls it, triggering the recursion.
Animation
JavaScript (ES6), 208 198 bytes
f=
(t,s=f=>setTimeout(f,500),v=t.value.split(/(\S.*\n)/),i=v.findIndex(s=>/}/.test(s)),c=_=>t.value=v.join``,d=_=>c(v.splice(--i,2),v[3]&&s(e,i?--i:++i)),e=_=>c(v[i]=v[i].replace(/./g,'*'),s(d)))=>s(e)
<textarea id=t rows=9>
|
|#|
{#}
|# #|
|# # #|
|# # #|
|# # #|
TTTTTTT
</textarea><input type=button value=Go! onclick=f(t)>
Java 7, 589 477 476 bytes
import java.util.*;void x(List<String>b,int x)throws Exception{Thread.sleep(500);int i=0,l=b.size(),z=x;String w;for(;i<l;i++){System.out.println(w=b.get(i));if(w.contains("{"))x=i;}System.out.println();w=b.get(x);i=w.contains("*")?1:0;if(i>0)b.remove(x);else b.set(x,z<0?r(w,'{','}'):r(w,'|','|'));if(l>1)x(b,i>0&x>0?x-1:x);}String r(String s,char y,char z){int a,b;return s.substring(0,a=s.indexOf(y))+s.substring(a,b=s.lastIndexOf(z)+1).replaceAll(".","*")+s.substring(b);}
Ok, it's a mess/long, but this challenge has so many annoying things for Java.. Printing multi-line; Thread.sleep(500)
which requires a throws Exception
; replacing a substring between two delimiters with an equal amount of *
; etc.
All this causes the program to be pretty big.. It can defintely be golfed some more, maybe even halved with a different approach, but at least there is an answer now. ;)
Ungolfed:
void x(List<String>b, int x) throws Exception{
Thread.sleep(500);
int i = 0,
l = b.size(),
z = x;
String w;
for(;i<l; i++){
System.out.println(w=b.get(i));
if(w.contains("{")){
x = i;
}
}
System.out.println();
w = b.get(x);
i = s.contains("*")
? 1
: 0;
if(i>0){
b.remove(x);
}
else{
b.set(x, z < 0
? r(s, '{', '}')
: r(s, '|', '|'));
}
if(l>1){
x(b, i > 0 & x > 0
? x-1
: x);
}
}
String r(String s, chary, char z){
int a, b;
return s.substring(0, a=s.indexOf(y)) + s.substring(a, b=s.lastIndexOf(z) + 1).replaceAll(".", "*") + s.substring(b);
}
Test code:
import java.util.*;
class M{
void x(List<String>b,int x)throws Exception{Thread.sleep(500);int i=0,l=b.size(),z=x;String w;for(;i<l;i++){System.out.println(w=b.get(i));if(w.contains("{"))x=i;}System.out.println();w=b.get(x);i=w.contains("*")?1:0;if(i>0)b.remove(x);else b.set(x,z<0?r(w,'{','}'):r(w,'|','|'));if(l>1)x(b,i>0&x>0?x-1:x);}String r(String s,char y,char z){int a,b;return s.substring(0,a=s.indexOf(y))+s.substring(a,b=s.lastIndexOf(z)+1).replaceAll(".","*")+s.substring(b);}
public static void main(String[] a){
try{
List<String> l = new ArrayList(){{
add(" | ");
add(" |#| ");
add(" |#| ");
add(" {# #} ");
add("|# # #|");
add("|# # #|");
add("|# # #|");
add("TTTTTTT");
}};
new M().c(l, -1);
}
catch(Exception e){}
}
}
Try it here. (On ideone it outputs at once and ignores the sleep
..)