fdai7012
11 months ago
5 changed files with 216 additions and 5 deletions
-
2.settings/org.eclipse.core.resources.prefs
-
6src/main/java/pacmanGame/GameManager.java
-
4src/main/java/pacmanGame/Program.java
-
208src/main/java/pacmanGame/VisualizerPlainTextUltra.java
-
1src/test/java/pacmanTests/GameManagerTest.java
@ -0,0 +1,2 @@ |
|||
eclipse.preferences.version=1 |
|||
encoding//src/main/java/pacmanGame/VisualizerPlainTextUltra.java=UTF-8 |
@ -0,0 +1,208 @@ |
|||
package pacmanGame; |
|||
|
|||
import java.util.HashMap; |
|||
|
|||
public class VisualizerPlainTextUltra implements Visualizer { |
|||
|
|||
public boolean showScore = true; |
|||
|
|||
public final int playerAnimationTime = 2; |
|||
|
|||
private String output; |
|||
|
|||
public GameManager gameManager; |
|||
|
|||
public HashMap<String, String[]> sprites = new HashMap<String,String[]>(){{ |
|||
|
|||
this.put("empty", new String[] { |
|||
" ", |
|||
" " |
|||
}); |
|||
this.put("dot", new String[] { |
|||
" . ", |
|||
" " |
|||
}); |
|||
this.put("wall", new String[] { |
|||
"|''|", |
|||
"|__|" |
|||
}); |
|||
this.put("cherry", new String[] { |
|||
" /\\ ", |
|||
" 0O " |
|||
}); |
|||
}}; |
|||
|
|||
public final String[][] ghostSprites = { |
|||
{ |
|||
"/--\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/°°\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/^^\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/oo\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/''\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/**\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/00\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/++\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/..\\", |
|||
"~~~~" |
|||
}, |
|||
{ |
|||
"/§§\\", |
|||
"~~~~" } |
|||
}; |
|||
|
|||
public final String[] playerSprite = { |
|||
"▄██▄", |
|||
"▀██▀" |
|||
}; |
|||
|
|||
public final String[][] playerAltSprites = { |
|||
{ |
|||
"▄ ▄", |
|||
"▀██▀" |
|||
}, |
|||
{ |
|||
"▄██▄", |
|||
"▀ ▀" |
|||
}, |
|||
{ |
|||
" ▀█▄", |
|||
" ▄█▀" |
|||
}, |
|||
{ |
|||
"▄█▀ ", |
|||
"▀█▄ " |
|||
} |
|||
}; |
|||
|
|||
public VisualizerPlainTextUltra(GameManager gameManager) { |
|||
this.gameManager = gameManager; |
|||
} |
|||
|
|||
@Override |
|||
public Object GetOutput() { |
|||
return output; |
|||
} |
|||
|
|||
public void Update() { |
|||
|
|||
output = ""; |
|||
|
|||
if(showScore) { |
|||
output = "\nSCORE: " + gameManager.score + "\n\n"; |
|||
} |
|||
|
|||
int lineBufferSize = 2; |
|||
String[] lineBuffer = new String[lineBufferSize]; |
|||
|
|||
Map map = gameManager.map; |
|||
|
|||
for(int y = 0; y < map.size.y; y++) { |
|||
|
|||
if(gameManager.isPaused && y > 10 && y < 20) { |
|||
|
|||
|
|||
for(int i = 0; i < lineBufferSize; i++) { |
|||
if(y == 15 && i == 0) { |
|||
output += " Paused! \n"; |
|||
} |
|||
else{ |
|||
output += "\n"; |
|||
} |
|||
} |
|||
} |
|||
else { |
|||
for(int i = 0; i < lineBufferSize; i++) { |
|||
lineBuffer[i] = ""; |
|||
} |
|||
|
|||
for(int x = 0; x < map.size.x; x++) { |
|||
Cell cell = map.GetCell(new Vector2(x, map.size.y - 1 - y)); |
|||
|
|||
boolean containsGhosts = false; |
|||
boolean containsPlayer = false; |
|||
int ghostIndex = -1; |
|||
|
|||
for( int i = 0; i < gameManager.ghosts.length; i++) { |
|||
if(gameManager.ghosts[i].position.equals(cell.pos)) { |
|||
containsGhosts = true; |
|||
ghostIndex = i; |
|||
} |
|||
} |
|||
if(gameManager.player.position.equals(cell.pos)) { |
|||
containsPlayer = true; |
|||
} |
|||
|
|||
if(containsPlayer) { |
|||
if((gameManager.time / playerAnimationTime) % 2 == 0) { |
|||
int directionIndex = 0; |
|||
|
|||
if(gameManager.player.direction.equals(new Vector2(0, 1))) { |
|||
directionIndex = 0; |
|||
} |
|||
else if(gameManager.player.direction.equals(new Vector2(0, -1))) { |
|||
directionIndex = 1; |
|||
} |
|||
else if(gameManager.player.direction.equals(new Vector2(-1, 0))) { |
|||
directionIndex = 2; |
|||
} |
|||
else if(gameManager.player.direction.equals(new Vector2(1, 0))) { |
|||
directionIndex = 3; |
|||
} |
|||
|
|||
lineBuffer = AttachToBuffer(lineBuffer, playerAltSprites[directionIndex]); |
|||
} |
|||
else { |
|||
lineBuffer = AttachToBuffer(lineBuffer, playerSprite); |
|||
} |
|||
} |
|||
else if(containsGhosts) { |
|||
lineBuffer = AttachToBuffer(lineBuffer, ghostSprites[ghostIndex]); |
|||
} |
|||
else if (sprites.containsKey(cell.type)) { |
|||
|
|||
lineBuffer = AttachToBuffer(lineBuffer, sprites.get(cell.type)); |
|||
} |
|||
else { |
|||
System.out.println("unknown type" + cell.type); |
|||
} |
|||
} |
|||
|
|||
for(int i = 0; i < lineBufferSize; i++) { |
|||
output += lineBuffer[i] + "\n"; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public String[] AttachToBuffer(String[] buffer, String[] sprite) { |
|||
for(int i = 0; i < buffer.length; i++) { |
|||
buffer[i] += sprite[i]; |
|||
} |
|||
return buffer; |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue