By gameoverscreen able to typ a name

This commit is contained in:
Remco
2015-06-12 14:42:40 +02:00
parent 1a3f2cbc17
commit 336a3051ff
6 changed files with 158 additions and 34 deletions
+34
View File
@@ -0,0 +1,34 @@
package model.objects.highscore;
import java.util.Date;
import audio.SongInstance;
public class Highscore {
public SongInstance si;
public String name;
public int score;
public long time;
public Highscore(SongInstance si, String name, int score, long time) {
this.si = si;
this.name = name;
this.score = score;
this.time = time;
}
public int getScore() {
return score;
}
public long getTime(){
return time;
}
public Date getDate(){
return new Date(getTime());
}
public String getName(){
return name;
}
}
@@ -0,0 +1,39 @@
package model.objects.highscore;
import java.awt.Graphics2D;
public class HighscoreLetter {
public static int charLength = 46;
private char[] letters;
private int x,y,index = 0;
public HighscoreLetter(char[] letters, int x, int y) {
super();
this.letters = letters;
this.x = x;
this.y = y;
}
public void draw(Graphics2D g2){
charLength = g2.getFontMetrics().stringWidth(letters[index]+"");
g2.drawString(letters[index]+"", x, y);
g2.drawLine(x, y, x+charLength, y);
}
public void up(){
index++;
index %= letters.length;
}
public void down(){
index--;
if(index < 0){
index = letters.length-1;
}
}
public String getCurrentString(){
return letters[index]+"";
}
}
@@ -0,0 +1,66 @@
package model.objects.highscore;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
public class HighscoreName {
private final char[] characters = " abcdefghijklmnopqrstuvwxyz0123456789†".toUpperCase().toCharArray();
private int spacing = 10;
private HighscoreLetter[] letters;
private Font font;
private int index = 0;
public HighscoreName(int x, int y,int nameLength,Font font) {
this.font = font;
letters = new HighscoreLetter[nameLength];
int marge = (int) (Math.floor(nameLength/2)-1)*spacing;
x -= (double)HighscoreLetter.charLength*(nameLength/2.0) + marge;
System.out.println(x);
for(int i = 0; i < letters.length; i++){
letters[i] = new HighscoreLetter(characters, x+(HighscoreLetter.charLength*i)+(spacing*i), y);
}
}
public void drawName(Graphics2D g2){
g2.setFont(font);
for(int i = 0; i < letters.length; i++){
if(i == index){
g2.setColor(Color.RED);
}else{
g2.setColor(Color.BLACK);
}
letters[i].draw(g2);
}
}
public void left(){
index--;
if(index < 0){
index = letters.length-1;
}
}
public void right(){
index++;
index %= letters.length;
}
public void up(){
letters[index].up();
}
public void down(){
letters[index].down();
}
public String getName(){
String name = "";
for(int i = 0; i < letters.length; i++){
name += letters[i].getCurrentString();
}
return name;
}
}