Added simple rendering
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@
|
|||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
/bin/
|
||||||
|
|||||||
55
src/ch/bfh/sevennotseven/Field.java
Normal file
55
src/ch/bfh/sevennotseven/Field.java
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
package ch.bfh.sevennotseven;
|
||||||
|
|
||||||
|
import java.awt.Canvas;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
|
public class Field extends Canvas {
|
||||||
|
|
||||||
|
private int size;
|
||||||
|
private int[][] field;
|
||||||
|
|
||||||
|
static final Color[] colors = {Color.red,Color.green, Color.blue, Color.yellow,Color.magenta};
|
||||||
|
|
||||||
|
public void setSize(int s) {
|
||||||
|
this.size = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setField(int[][] field){
|
||||||
|
this.field = field;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
g.setColor(Color.lightGray);
|
||||||
|
|
||||||
|
int total = this.getHeight();
|
||||||
|
int space = total/size;
|
||||||
|
|
||||||
|
g.setClip(0, 0, total,total);
|
||||||
|
g.fillRect(0, 0, total,total);
|
||||||
|
|
||||||
|
g.setColor(Color.white);
|
||||||
|
|
||||||
|
for(int i=0; i<=size; i++) {
|
||||||
|
g.drawLine(0,i*space,total,i*space);
|
||||||
|
g.drawLine(i*space,0,i*space,total);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(field==null) return;
|
||||||
|
|
||||||
|
for(int x=0; x<size; x++) {
|
||||||
|
for(int y=0; y<size; y++) {
|
||||||
|
int colorCode = field[x][y];
|
||||||
|
if(colorCode!=0) {
|
||||||
|
g.setColor(colors[colorCode-1]);
|
||||||
|
g.fillRect(x*space+2, y*space+2, space -3, space -3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,11 +4,12 @@
|
|||||||
package ch.bfh.sevennotseven;
|
package ch.bfh.sevennotseven;
|
||||||
|
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.GraphicsConfiguration;
|
|
||||||
import java.awt.HeadlessException;
|
import java.awt.HeadlessException;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aaron
|
* @author aaron
|
||||||
*
|
*
|
||||||
@@ -16,6 +17,7 @@ import java.awt.event.WindowEvent;
|
|||||||
public class Window extends Frame {
|
public class Window extends Frame {
|
||||||
|
|
||||||
private Game game;
|
private Game game;
|
||||||
|
private Field field;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param title
|
* @param title
|
||||||
@@ -23,7 +25,7 @@ public class Window extends Frame {
|
|||||||
*/
|
*/
|
||||||
public Window(String title) throws HeadlessException {
|
public Window(String title) throws HeadlessException {
|
||||||
super(title);
|
super(title);
|
||||||
this.setVisible(true);
|
|
||||||
this.addWindowListener(new WindowAdapter(){
|
this.addWindowListener(new WindowAdapter(){
|
||||||
@Override
|
@Override
|
||||||
public void windowClosing(WindowEvent e){
|
public void windowClosing(WindowEvent e){
|
||||||
@@ -31,7 +33,22 @@ public class Window extends Frame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
field = new Field();
|
||||||
|
field.setSize(7);
|
||||||
game = new Game();
|
game = new Game();
|
||||||
|
|
||||||
|
|
||||||
|
this.add(field);
|
||||||
|
this.setSize(400,400);
|
||||||
|
this.setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
int [][] testfield = new int[7][7];
|
||||||
|
testfield[0][0] = 2;
|
||||||
|
testfield[1][3] = 4;
|
||||||
|
field.setField(testfield);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user