Skip to content
Permalink
7576eda583
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
88 lines (61 sloc) 1.96 KB
package view;
import model.*;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
public class GameboardWindow extends JPanel {
private static final long serialVersionUID = 1L;
private Image img = new ImageIcon(this.getClass().getResource(
"gameboard.png")).getImage();
private GameBoard board; //
private Point[] points = new Point[40];// location of topleft corner of
// buttons
private ArrayList<Positioner> Positioners;
public GameboardWindow(GameBoard board) {
this.board = board;
Dimension size = new Dimension(img.getWidth(null)+250, img.getHeight(null));
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
setSize(size);
setLayout(null);
setUpTiles();
Positioners = new ArrayList<Positioner>();
for (int i = 1; i <= 4; i++) {
String path = "piece" + i + ".png";
Image img = new ImageIcon(this.getClass().getResource(path))
.getImage();
Positioners.add(new Positioner(img, 602, 602));
}
}
public void setUpTiles() {
// implement the tiles into the graphical boardspace??
// Tile t1;
// this.add(t1);
// t1.setBounds(133,521,50,75); //xstart,ystart,width,height
// points[1] = newPoint(133,521);
// LocationButton b2 = new LocationButton("name", 21, board);
// this.add(b2);
// b2.setBounds(98, 10, 56, 88);// xStart, Ystart, width, height
// points[21] = new Point(98, 10);
}
public void paintComponent(Graphics g) {
g.drawImage(img, 0, 0, null);
for (int i = 0; i < Positioners.size(); i++) {
Positioner curr = Positioners.get(i);
g.drawImage(curr.getImage(), curr.getX(), curr.getY(), null);
}
}
public void update(ArrayList<Integer> locP) {
for (int i = 0; i < locP.size(); i++) {
int x = (int) points[locP.get(i)].getX();
int y = (int) points[locP.get(i)].getY();
Positioners.get(i).setX(x);
Positioners.get(i).setY(y);
}
}
}