Skip to content
Permalink
e02e5b0e1c
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
201 lines (149 sloc) 5.95 KB
package view;
import model.*;
import controller.*;
import java.awt.*;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import controller.Cashflow;
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[24];
private ArrayList<Positioner> Positioners;
public GameboardWindow(GameBoard board) {
this.board = board;
Dimension size = new Dimension(img.getWidth(null), 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
// the buttons are going to be a little off as i couldnt figure out how to rotate jbuttons
// i guess it doesnt really matter what tile is which but the position matters - 0 is starting
TileButton t1 = new TileButton("Deal", 0, board);
this.add(t1);
t1.setBounds(125,532,95,20); //xstart,ystart,width,height
points[0] = new Point(125,531);
TileButton t2 = new TileButton("Market", 1, board);
this.add(t2);
t2.setBounds(191,586,237-191,637-586); //xstart,ystart,width,height
points[1] = new Point(191,586);
TileButton t3 = new TileButton("Deal", 2, board);
this.add(t3);
t3.setBounds(266,593,307-266,689-593); //xstart,ystart,width,height
points[2] = new Point(266,593);
TileButton t4 = new TileButton("PayDay", 3, board);
this.add(t4);
t4.setBounds(334,601,383-334,718-601); //xstart,ystart,width,height
points[3] = new Point(334,601);
TileButton t5 = new TileButton("Deal", 4, board);
this.add(t5);
t5.setBounds(392,580,440-392,717-580); //xstart,ystart,width,height
points[4] = new Point(392,580);
TileButton t6 = new TileButton("Downsize", 5, board);
this.add(t6);
t6.setBounds(465,566,522-465,697-566); //xstart,ystart,width,height
points[5] = new Point(465,566);
TileButton t7 = new TileButton("Deal", 6, board);
this.add(t7);
t7.setBounds(519,555,586-519,639-555); //xstart,ystart,width,height
points[6] = new Point(519,555);
TileButton t8 = new TileButton("Doodad", 7, board);
this.add(t8);
t8.setBounds(548,500,655-548,89); //xstart,ystart,width,height
points[7] = new Point(548,500);
TileButton t9 = new TileButton("Deal", 8, board);
this.add(t9);
t9.setBounds(576,451,699-576,526-451); //xstart,ystart,width,height
points[8] = new Point(576,451);
TileButton t10 = new TileButton("Market", 9, board);
this.add(t10);
t10.setBounds(589,386,719-589,446-386); //xstart,ystart,width,height
points[9] = new Point(589,386);
TileButton t11 = new TileButton("Deal", 10, board);
this.add(t11);
t11.setBounds(584,328,726-584,376-328); //xstart,ystart,width,height
points[10] = new Point(584,328);
TileButton t12 = new TileButton("PayDay", 11, board);
this.add(t12);
t12.setBounds(586,266,701-586,290-266); //xstart,ystart,width,height
points[11] = new Point(586,266);
TileButton t13 = new TileButton("Deal", 12, board);
this.add(t13);
t13.setBounds(577,193,651-577,226-193); //xstart,ystart,width,height
points[12] = new Point(577,193);
TileButton t14 = new TileButton("Charity", 13, board);
this.add(t14);
t14.setBounds(538,124,572-538,195-124); //xstart,ystart,width,height
points[13] = new Point(538,124);
TileButton t15 = new TileButton("Deal", 14, board);
this.add(t15);
t15.setBounds(473,73,507-473,171-73); //xstart,ystart,width,height
points[14] = new Point(473,73);
TileButton t16 = new TileButton("Doodad", 15, board);
this.add(t16);
t16.setBounds(395,39,438-395,180-39); //xstart,ystart,width,height
points[15] = new Point(395,39);
TileButton t17 = new TileButton("Deal", 16, board);
this.add(t17);
t17.setBounds(325,41,61,138); //xstart,ystart,width,height
points[16] = new Point(325,41);
TileButton t18 = new TileButton("Market", 17, board);
this.add(t18);
t18.setBounds(247,70,69,112); //xstart,ystart,width,height
points[17] = new Point(247,70);
TileButton t19 = new TileButton("Deal", 18, board);
this.add(t19);
t19.setBounds(196,92,51,121); //xstart,ystart,width,height
points[18] = new Point(196,192);
TileButton t20 = new TileButton("PayDay", 19, board);
this.add(t20);
t20.setBounds(108,179,95,57); //xstart,ystart,width,height
points[19] = new Point(108,179);
TileButton t21 = new TileButton("Deal", 20, board);
this.add(t21);
t21.setBounds(71,250,129,63); //xstart,ystart,width,height
points[20] = new Point(71,250);
TileButton t22 = new TileButton("Child", 21, board);
this.add(t22);
t22.setBounds(53,312,130,60); //xstart,ystart,width,height
points[21] = new Point(53,312);
TileButton t23 = new TileButton("Deal", 22, board);
this.add(t23);
t23.setBounds(52,389,138,41); //xstart,ystart,width,height
points[22] = new Point(52,389);
TileButton t24 = new TileButton("Doodad", 23, board);
this.add(t24);
t24.setBounds(88,463,113,31); //xstart,ystart,width,height
points[23] = new Point(88,463);
}
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() { //updates the location of the player on the board
for (int i = 0; i < Cashflow.numPlayers; i++) {
int x = (int) points[Player[i].getLocation()].getX(); // i will fix this later
int y = (int) points[Player[i].getLocation()].getY(); // hopefully lol
Positioners.get(i).setX(x);
Positioners.get(i).setY(y);
}
}
}