Score Anzeige und Berechnung, Timer angefangen

This commit is contained in:
feschi55
2014-11-24 18:58:09 +01:00
parent 2397cf6053
commit 72e02c3c9a
3 changed files with 102 additions and 43 deletions
+23 -10
View File
@@ -18,15 +18,14 @@ import de.heatup.ui.statusPanel.Timer;
public class StatusPanelAdder{ public class StatusPanelAdder{
private Score score;
private Timer timer;
private static JPanel panel; private static JPanel panel;
private static int hgap=30; private static int hgap=30;
private static int vgap=9; private static int vgap=9;
private static int modifier=-1; private static int modifier=-1;
private static int temping=0;
private static int manipulations=0;
private static double tempPlus=0.0; private static double tempPlus=0.0;
private static double tempMinus=0.0; private static double tempMinus=0.0;
private static int temping=0;
private static double barSpeed=0.01; private static double barSpeed=0.01;
private static boolean ende=false; private static boolean ende=false;
private static JLabel labelTempC= new JLabel("§"); private static JLabel labelTempC= new JLabel("§");
@@ -37,7 +36,7 @@ public class StatusPanelAdder{
private static JLabel labelPowerUp = new JLabel("PowerUp"); private static JLabel labelPowerUp = new JLabel("PowerUp");
private static JLabel powerUpLabel = new JLabel(/*new ImageIcon("path_to_image.png")*/"powerUpLabel"); private static JLabel powerUpLabel = new JLabel(/*new ImageIcon("path_to_image.png")*/"powerUpLabel");
private static JLabel labelTime=new JLabel("Time"); private static JLabel labelTime=new JLabel("Time");
private static JLabel timeLabel = new JLabel("123456789"); private static JLabel timeLabel = new JLabel("0");
private static Font emulogicheading; private static Font emulogicheading;
private static Font emulogictext; private static Font emulogictext;
private static Font ttfBase; private static Font ttfBase;
@@ -73,20 +72,32 @@ public class StatusPanelAdder{
} }
public int getScore(){ public int getScore(){
return score.getScore(); return Score.getScore();
}
public double getTime(){
return timer.getTime();
} }
/**
* @param newPanel das zu verwendende Panel zur Bearbeitung
*/
public static void setPanel(JPanel newPanel){ public static void setPanel(JPanel newPanel){
newPanel.setLayout(new FlowLayout(FlowLayout.CENTER, hgap,5)); newPanel.setLayout(new FlowLayout(FlowLayout.CENTER, hgap,5));
panel=newPanel; panel=newPanel;
} }
public static void addManipulations(){
manipulations+=1;
Score.raiseScore(25);
}
public static int getManipulations(){
return manipulations;
}
public static void tick() { public static void tick() {
Timer.tickTimer();
timeLabel.setText(Timer.getMinuteS() + ":" + Timer.getSecondsS());
/**
* Temperaturbearbeitung
*/
labelTempC.setText(tempBar.getValue() + "°C"); labelTempC.setText(tempBar.getValue() + "°C");
temping=0; temping=0;
if (modifier<0){ if (modifier<0){
@@ -123,7 +134,9 @@ public class StatusPanelAdder{
/**
* fügt dem der Klasse übergebenen Panel Objekte hinzu & formatiert diese
*/
public static void createPanel(){ public static void createPanel(){
implementFont(); implementFont();
emulogicheading = ttfBase.deriveFont(Font.PLAIN, 16); emulogicheading = ttfBase.deriveFont(Font.PLAIN, 16);
+45 -14
View File
@@ -1,35 +1,66 @@
package de.heatup.ui.statusPanel; package de.heatup.ui.statusPanel;
import de.heatup.ui.StatusPanelAdder;
public class Score { public class Score {
private int score; private static int score;
public Score(){ private static int bonusTime=180;
score=0; /**
} * @return Score
//returns score */
public int getScore(){ public static int getScore(){
return score; return score;
} }
public String getScoreS(){ /**
* @return Score as String
*/
public static String getScoreS(){
int score=getScore(); int score=getScore();
Integer string= new Integer(score); Integer string= new Integer(score);
return string.toString(); return string.toString();
} }
//resets score /**
public void resetScore(){ * setzt die BonusZeit bis dahin es den Zeitbonus gibt
score=0; * @param bonusTime
*/
public static void setBonusTime(int bonusTime){
Score.bonusTime=bonusTime;
} }
//raises score
public void raiseScore(int additional){ /**
* erhöht den Score um:
* @param additional
*/
public static void raiseScore(int additional){
score+=additional; score+=additional;
} }
//reduces score; when score<0, score=0; /**
public void reduceScore(int reduce){ * senkt den Score um:
* @param reduce
*/
public static void reduceScore(int reduce){
score-=reduce; score-=reduce;
//when score less than 0 //when score less than 0
if (score<0){ if (score<0){
score=0; score=0;
} }
} }
/**
* berechnet den endgültigen Score und gibt diesen zurück
* @return endScore
*/
public static int endScore(){
int manipulations=StatusPanelAdder.getManipulations();
int manipulationsBonus=600/manipulations;
int endScore=score + manipulationsBonus;
if (Timer.getAllInSeconds()<bonusTime){
endScore+=(bonusTime-Timer.getAllInSeconds());
}
return endScore;
}
} }
+32 -17
View File
@@ -1,27 +1,42 @@
package de.heatup.ui.statusPanel; package de.heatup.ui.statusPanel;
import java.util.Date;
public class Timer { public class Timer {
private static int minute;
private static int seconds;
private static int ticktick;
static double elapsedTime = 0L;
public static void main(String[] args){
double startTime = System.currentTimeMillis();
//1s = 1000ms public static void tickTimer(){
while (elapsedTime <10000) { ticktick++;
if (ticktick==60){
elapsedTime = (new Date()).getTime() - startTime; ticktick=0;
System.out.println(elapsedTime); raiseSeconds();
} }
} }
private static void raiseSeconds(){
public double getTime(){ seconds++;
return elapsedTime; if (seconds==60){
minute++;
seconds=0;
}
}
public static String getMinuteS(){
String formatted = String.format("%02d", minute);
return formatted;
}
public static String getSecondsS(){
String formatted = String.format("%02d", seconds);
return formatted;
}
public static int getMinute(){
return minute;
}
public static int getSeconds(){
return seconds;
}
public static int getAllInSeconds(){
int all=minute*60+seconds;
return all;
} }
} }