import java.util.*;
import java.awt.*;
import java.applet.*;
//import javax.swing.*;
import java.net.*;
import javax.imageio.*;
import java.io.IOException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Monopoly extends Applet {
ArrayList<Player> players = new ArrayList<Player>();
Spaces[] property = new Spaces[40];
Dimension dim;
Graphics bufferGraphics;
Button playUp;
Button playDown;
Button startGame;
Button start;
Button roll;
int current;
int turn;
int round = -1;
int numPlay=1;
int ctr = 0;
Image logo;
Image rail;
Image community;
Image chance;
Image board;
public void init() {
board = createImage(getWidth(),getHeight());
bufferGraphics = board.getGraphics();
setLayout(null);
setProperty();
players.add(new Player(Color.RED));
dim = getSize();
try {
logo = ImageIO.read(new URL(getCodeBase(), "logo.jpg"));
rail = ImageIO.read(new URL(getCodeBase(), "railroad.gif"));
chance = ImageIO.read(new URL(getCodeBase(), "chance.png"));
community = ImageIO.read(new URL(getCodeBase(), "community.png"));
} catch (MalformedURLException ex) { ex.printStackTrace(); }
catch (IOException e) { System.out.println("BAD FILE"); }
}
public void paintSetup(){
bufferGraphics.setColor(Color.WHITE);
bufferGraphics.fillRect(0,0,620,670);
bufferGraphics.setColor(Color.BLACK);
bufferGraphics.drawImage(logo,199,0,null);
//top
bufferGraphics.drawRect(50,100,80,80);
bufferGraphics.drawRect(130,100,40,80);
bufferGraphics.drawRect(170,100,40,80);
bufferGraphics.drawRect(210,100,40,80);
bufferGraphics.drawRect(250,100,40,80);
bufferGraphics.drawRect(290,100,40,80);
bufferGraphics.drawRect(330,100,40,80);
bufferGraphics.drawRect(370,100,40,80);
bufferGraphics.drawRect(410,100,40,80);
bufferGraphics.drawRect(450,100,40,80);
bufferGraphics.drawRect(490,100,80,80);
//left
bufferGraphics.drawRect(50,180,80,40);
bufferGraphics.drawRect(50,220,80,40);
bufferGraphics.drawRect(50,260,80,40);
bufferGraphics.drawRect(50,300,80,40);
bufferGraphics.drawRect(50,340,80,40);
bufferGraphics.drawRect(50,380,80,40);
bufferGraphics.drawRect(50,420,80,40);
bufferGraphics.drawRect(50,460,80,40);
bufferGraphics.drawRect(50,500,80,40);
//right
bufferGraphics.drawRect(490,180,80,40);
bufferGraphics.drawRect(490,220,80,40);
bufferGraphics.drawRect(490,260,80,40);
bufferGraphics.drawRect(490,300,80,40);
bufferGraphics.drawRect(490,340,80,40);
bufferGraphics.drawRect(490,380,80,40);
bufferGraphics.drawRect(490,420,80,40);
bufferGraphics.drawRect(490,460,80,40);
bufferGraphics.drawRect(490,500,80,40);
//bottom
bufferGraphics.drawRect(50,540,80,80);
bufferGraphics.drawRect(130,540,40,80);
bufferGraphics.drawRect(170,540,40,80);
bufferGraphics.drawRect(210,540,40,80);
bufferGraphics.drawRect(250,540,40,80);
bufferGraphics.drawRect(290,540,40,80);
bufferGraphics.drawRect(330,540,40,80);
bufferGraphics.drawRect(370,540,40,80);
bufferGraphics.drawRect(410,540,40,80);
bufferGraphics.drawRect(450,540,40,80);
bufferGraphics.drawRect(490,540,80,80);
//writing
bufferGraphics.setFont(new Font("Bold",0,30));
bufferGraphics.drawString("GO",510,150);
bufferGraphics.setFont(new Font("Dialog",0,20));
bufferGraphics.drawString("Go to",60,135);
bufferGraphics.drawString("Jail",70,160);
bufferGraphics.drawString("Free",70,580);
bufferGraphics.drawString("Parking",55,595);
bufferGraphics.setColor(Color.LIGHT_GRAY);
bufferGraphics.fillRect(497,541,5,48);
bufferGraphics.fillRect(512,541,5,48);
bufferGraphics.fillRect(527,541,5,48);
bufferGraphics.setColor(Color.BLACK);
bufferGraphics.drawRect(490,540,50,50);
bufferGraphics.drawString("Jail",500,570);
//LOGOS
//green
bufferGraphics.setColor(new Color(0,100,0));
bufferGraphics.fillRect(131,160,39,20);
bufferGraphics.fillRect(171,160,39,20);
bufferGraphics.fillRect(251,160,39,20);
//dark blue
bufferGraphics.setColor(new Color(0,0,128));
bufferGraphics.fillRect(371,160,39,20);
bufferGraphics.fillRect(451,160,39,20);
//purple
bufferGraphics.setColor(new Color(102,0,153));
bufferGraphics.fillRect(491,181,20,39);
bufferGraphics.fillRect(491,261,20,39);
//light blue
bufferGraphics.setColor(new Color(100,149,237));
bufferGraphics.fillRect(491,381,20,39);
bufferGraphics.fillRect(491,461,20,39);
bufferGraphics.fillRect(491,501,20,39);
//magenta
bufferGraphics.setColor(Color.MAGENTA);
bufferGraphics.fillRect(331,541,39,20);
bufferGraphics.fillRect(371,541,39,20);
bufferGraphics.fillRect(451,541,39,20);
//orange
bufferGraphics.setColor(Color.ORANGE);
bufferGraphics.fillRect(131,541,39,20);
bufferGraphics.fillRect(171,541,39,20);
bufferGraphics.fillRect(251,541,39,20);
//red
bufferGraphics.setColor(Color.RED);
bufferGraphics.fillRect(110,381,20,39);
bufferGraphics.fillRect(110,421,20,39);
bufferGraphics.fillRect(110,501,20,39);
//yellow
bufferGraphics.setColor(Color.YELLOW);
bufferGraphics.fillRect(110,181,20,39);
bufferGraphics.fillRect(110,261,20,39);
bufferGraphics.fillRect(110,301,20,39);
//rail
bufferGraphics.drawImage(rail,510,340,null);
bufferGraphics.drawImage(rail,70,340,null);
bufferGraphics.drawImage(rail,290,560,null);
bufferGraphics.drawImage(rail,290,120,null);
//community
bufferGraphics.drawImage(community,210,120,null);
bufferGraphics.drawImage(community,210,560,null);
bufferGraphics.drawImage(community,510,220,null);
//chance
bufferGraphics.drawImage(chance,330,120,null);
bufferGraphics.drawImage(chance,510,420,null);
bufferGraphics.drawImage(chance,70,460,null);
}
public void paint(Graphics g) {
setBackground(Color.white);
if (ctr==0){
paintSetup();
ctr++;
}
g.drawImage(board,0,0,null);
for (int i=0;i<players.size();i++){
players.get(i).drawMe(g);
}
playGame(g);
}
public void playGame(Graphics g){
ButtonListener blisten = new ButtonListener();
if (round == -1){
startGame = new Button("Play");
startGame.addActionListener(blisten);
startGame.setBounds(880,330,100,30);
add(startGame);
g.setFont(new Font("Bold",0,40));
g.drawString("Welcome to Monopoly",750,250);
g.setFont(new Font("Bold",0,20));
g.drawString("By Connor Giles",850,300);
}
else if(round==0){
startGame.removeActionListener(blisten);
remove(startGame);
playUp = new Button("+");
playDown = new Button("-");
start = new Button("Start");
playUp.addActionListener(blisten);
playDown.addActionListener(blisten);
start.addActionListener(blisten);
playUp.setBounds(1020,325,40,30);
playDown.setBounds(1060,325,40,30);
start.setBounds(790,325,100,30);
add(playUp);
add(playDown);
add(start);
g.setFont(new Font("Bold",0,40));
g.drawString("How Many Players?",770,250);
g.setFont(new Font("Bold",0,30));
g.drawString(""+numPlay+" Player",900,350);
}
else{
if(ctr==1){
remove(playUp);
remove(playDown);
remove(start);
ctr++;
}
//set space
players.get(current).setCurrent(1);
//sets players location on the board
players.get(current).setPosition(property[players.get(current).getCurrent()].getX(),
property[players.get(current).getCurrent()].getY());
}
validate();
}
public void setProperty(){
property[0]=new Spaces("Go",0,520,130,true,false,-200,null);
property[1]=new Spaces("Mediterranean Ave.",60,520,190,false,true,2,"Purple");
property[2]=new Spaces("Community Chest",0,520,230,false,false,0,"Community Chest");
property[3]=new Spaces("Baltic Ave.",60,520,270,false,true,4,"Purple");
property[4]=new Spaces("Income Tax",0,520,310,true,false,200,"Tax");
property[5]=new Spaces("Reading Railroad",200,520,350,false,true,25,"Railroad");
property[6]=new Spaces("Oriental Ave.",100,520,390,false,true,6,"Light-Blue");
property[7]=new Spaces("Chance",0,520,430,false,false,0,"Chance");
property[8]=new Spaces("Vermont Ave.",100,520,470,false,true,6,"Light-Blue");
property[9]=new Spaces("Connecticut Ave.",120,520,510,false,true,8,"Light-Blue");
property[10]=new Spaces("Jail",0,520,570,false,false,0,"Jail");
property[10]=new Spaces("St. Charles Place",140,460,570,false,true,10,"Violet");
// property[11]=new Spaces("Electric Company",150,420,570,false,true,)
}
public class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("+")){
if(numPlay<6)
numPlay++;
}
if (e.getActionCommand().equals("-")){
if (numPlay>1)
numPlay--;
}
if (e.getActionCommand().equals("Start")){
round=round+1;
}
if (e.getActionCommand().equals("Play"))
round=round+1;
repaint();
}
}
}