Java playground
DWAPS
54K views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Real animation in console
by dwaps
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
// {
public class Main {
public static void main(String[] args) {
// }
String dwapsMsg = "Test that on console !...";
System.out.print(dwapsMsg);
AnimationManager am = new AnimationManager();
am.numberOfRepetition(3);
// am.startAnimation(FramesProvider.FLASH_INFO);
// am.startAnimation(FramesProvider.CAT_AND_MOUSE);
//{
}
}
class AnimationManager {
private int nbOfRepetition = 1;
public void numberOfRepetition(int nb) { nbOfRepetition = Math.abs(nb); }
public void startAnimation(String[][] strFrames) {
startAnimation(strFrames, false);
}
public void startAnimation(String[][] strFrames, boolean reverseAnim) {
if (!reverseAnim) {
for (int i = 0; i < strFrames.length; i++) display(strFrames[i]);
}
else {
for (int i = strFrames.length-1; i >= 0; i--) display(strFrames[i]);
}
nbOfRepetition--;
if (nbOfRepetition > 0) {
reverseAnim = !reverseAnim;
if (strFrames == FramesProvider.CAT_AND_MOUSE) changeCatDirection(strFrames, reverseAnim);
startAnimation(strFrames, reverseAnim);
}
}
private void display(String[] frameParts) {
clearConsole(50);
for (String f : frameParts) System.out.println(f);
sleep();
}
private void sleep() {
try { Thread.sleep(100); Runtime.getRuntime().exec("clear"); }
catch (Exception e) { e.printStackTrace(); }
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content