Board.java
Dosyayı İndir
package com.godoro.game.eater;
import com.godoro.game.eater.string.Result;
import com.godoro.game.eater.string.Tag;
import com.godoro.game.eater.image.Player;
import com.godoro.game.eater.string.Score;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;
;
import javax.sound.sampled.Clip;
import javax.swing.JComponent;
import javax.swing.Timer;
import javax.sound.sampled.Clip;
import javax.swing.JComponent;
import javax.swing.Timer;
public class Board extends JComponent {
private Map<String, Image> imageMap;
private Map<String, Clip> soundMap;
private Clip audio;
private Tag tag = new Tag("Obur", 20, 20);
private Result result = new Result("", 240, 240);
private Score score = new Score("Çentik", 200, 20);
private Timer timer;
private Universe universe;
@Override
public void paint(Graphics g) {
paintBackground(g);
universe.drawAll(g, this);
tag.draw(g, this, universe.getStatus());
score.draw(g, this, universe.getStatus());
result.draw(g, this, universe.getStatus());
}
private void paintBackground(Graphics g) {
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
}
public Universe getUniverse() {
return universe;
}
public void setUniverse(Universe universe) {
this.universe = universe;
startTimer();
}
public Map<String, Image> getImageMap() {
return imageMap;
}
public void setImageMap(Map<String, Image> imageMap) {
this.imageMap = imageMap;
//universe.setImageMap(imageMap);
}
public Map<String, Clip> getSoundMap() {
return soundMap;
}
public void setSoundMap(Map<String, Clip> soundMap) {
this.soundMap = soundMap;
universe.setSoundMap(soundMap);
audio = soundMap.get("game");
audio.loop(Integer.MAX_VALUE);
}
private void startTimer() {
ActionListener taskPerformer = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
act();
}
};
timer = new Timer(100, taskPerformer);
timer.setRepeats(true);
timer.start();
}
private void act() {
universe.run();
if (universe.getStatus() != Status.ACTIVE) {
timer.stop();
audio.stop();
}
repaint();
}
private void play(int deltaX, int deltaY) {
if (universe.getStatus() == Status.ACTIVE) {
universe.play(deltaX, deltaY);
score.setNumber(universe.getScore());
repaint();
}
}
public void left() {
play(-Player.SPEED, 0);
}
public void right() {
play(Player.SPEED, 0);
}
public void up() {
play(0, -Player.SPEED);
}
public void down() {
play(0, Player.SPEED);
}
public void fire() {
universe.fire();
repaint();
}
}
Dosyayı İndir