package gamestates;
import java.awt.Color;
import java.awt.Toolkit;
import core.KeyInputHandler;
import core.Renderer;
import core.Score;
import core.MainGame.GameLoop;
import core.Score.ScoreEntry;
/**
*
* @author Derk Sacklowski
*
* Diese Klasse bietet die Funktionalitäten
*
* Spiel starten
* Highscore anzeigen
* Hilfe anzeigen
* Spiel beenden
*
*/
public class InStartmenu extends InMenu {
//InstanzVariablen und kram
private static InStartmenu inStartmenu; // Instanz des Menüs
private MenuItem scorebutton;
/**
* Diese Klasse ist ein Singleton
*
*/
public static synchronized InStartmenu getInstance() {
if (inStartmenu == null)
inStartmenu = new InStartmenu();
return inStartmenu;
}
private InStartmenu()
{
super();
menu = new MenuItem(
Toolkit.getDefaultToolkit().getImage( getClass().getResource("/images/tiles/menu_start.png") ),
404, 440, false); // Startmenü
menu.getHitbox().x = 198;
menu.getHitbox().y = 60;
drawList.add(menu);
scorebutton = new MenuItem(
Toolkit.getDefaultToolkit().getImage( getClass().getResource("/images/tiles/menu_scorelist.png") ),
496, 58, false); //Button um zurück ins menu zu Springen
scorebutton.getHitbox().x = 150;
scorebutton.getHitbox().y = 550;
}
/**
* Spiel Starten
*/
private void startGame()
{
GameLoop.getInstance().goInGame();
} //startGame end
/**
* Highscore anzeigen
*/
protected void showHighscore()
{
drawList.clear();
drawList.add(scorebutton);
highscore = true;
navigateable = false;
} //showHighscore end
/**
* Tastatureingaben abfragen und passende Aktionen auslösen
*/
protected void inputHandling() {
//Nach oben Navigieren
if (KeyInputHandler.getInstance().upIsPressed)
{
menuIndex --;
arrows.getHitbox().y -= 50;
if (menuIndex < 0)
{
menuIndex = 3;
arrows.getHitbox().y = 450;
}
KeyInputHandler.getInstance().upIsPressed = false;
}
//Nach unten Navigieren
if (KeyInputHandler.getInstance().downIsPressed)
{
menuIndex ++;
arrows.getHitbox().y += 50;
if (menuIndex > 3)
{
menuIndex = 0;
arrows.getHitbox().y = 300;
}
KeyInputHandler.getInstance().downIsPressed = false;
}
//auswählen
if (KeyInputHandler.getInstance().enterIsPressed)
{
switch(menuIndex)
{
case 0:
startGame();
break;
case 1:
showHighscore();
break;
case 2:
showHelp();
break;
case 3:
endGame();
break;
}
KeyInputHandler.getInstance().enterIsPressed = false;
}
}
/**
* alles Zeichnen
*/
@Override
public void draw() {
background.draw();
super.draw(drawList);
if(highscore)
{
for(int i = 0; i < Score.getInstance().getScorelist().length; i++)
{
ScoreEntry temp = Score.getInstance().getScorelist()[i]; // Temporärer Scoreentry
Renderer.getInstance().drawText(temp.getName(), 200, i * 50 + 40, Color.BLACK);
Renderer.getInstance().drawText(String.valueOf(temp.getPoints()), 500, i * 50 + 40, Color.BLACK);
}
}
} //draw end
}