⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monopoly.java

📁 This A java game to play monopoly
💻 JAVA
字号:
/*

 */
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.event.*;
import java.awt.image.*;
import java.lang.*;
import java.util.*;
import java.net.*;
import java.awt.*;
import java.io.*;
import java.awt.GridBagLayout;
import java.awt.BorderLayout;

public class Monopoly extends Applet implements ActionListener, WindowListener {
	static Frame mainFrame = new Frame( " Monopoly " );
	static MonopolyBoard monopolyBoard;
	static MonopolyPlayer monopolyplayer;
	static final DoubleBufferPanel dbp = new DoubleBufferPanel();
	static final BufferPanel bp = new BufferPanel();
	static final Frame a = new Frame();
	static final Frame help = new Frame();
	static PropertyManager propertymanager;
	private Button yes = new Button(" Yes ");
	private Button no = new Button (" No ");
	private Button Roll  = new Button( "Roll Dice" );
	private Button Buy   = new Button( "Buy Property" );
	private Button Add   = new Button( "Add a House" );
	private Button Rem   = new Button( "Sell a House" );
	private Button New   = new Button( "New Game" );
	private Button Done  = new Button( "Done" );
	private Button pay50 = new Button( "Get out of Jail!" );
	private Button start  = new Button( "Start" );
	private Button stop = new Button( "Stop" );
	private Button Help  = new Button( "Help" );
	private Button Credits = new Button( "Credits ");
	private Button ShortCuts = new Button ( "");
//	private List property;// = new List();
	static final TextField tf1 = new TextField("Player 1", 13 );
	static final TextField tf2 = new TextField("Player 2", 13 );
	static final Button b = new Button( "Start the Game!" );
	static final Button Quit = new Button ("Close X");
	static final Button Exit = new Button ("Exit this Game X");
	static final Button Exit2 = new Button ("Exit this Game X");
	static final Label comments = new Label ("Welcome to Monopoly! This game is created by " );
	static final Label comments1 = new Label ("Shahrukh Hassan and Obaid Ahmed."); 
	static final Label comments2 = new Label ("Please enter your names for player 1 and player 2 .");
	static final Label comments3 = new Label (" NB: this is a two player game only!");
	static final Label comments4 = new Label ("");
	static final Button Info = new Button ("Rules");
	private AudioClip sound;
	int Money = 1500;
	Image back ;
	
    public static void main(String argv[]) 
    {
     new Monopoly();

    }

 
	public void init() {
		sound = getAudioClip(getDocumentBase(), "music.wav");
		back = getImage(getDocumentBase(),"mono.gif");
		a.setSize( 380, 390 );
		a.setBackground(new Color( (80), (180), (210) ));
		a.setLayout(new FlowLayout(FlowLayout.CENTER));
		a.setResizable(false);
		Panel mainstuff = new Panel(new GridLayout(0,1));
		mainstuff.add(comments);
		mainstuff.add(comments1);
		mainstuff.add(comments2);
		mainstuff.add(comments3);
		mainstuff.add(comments4);
		mainstuff.add(new Label ("            "));
		mainstuff.add( tf1);
		mainstuff.add(tf2);
		mainstuff.add(new Label ("          "));
		mainstuff.add( b );
		mainstuff.add(Info);
		mainstuff.add(Exit);
		a.add(mainstuff);
		a.setVisible( true );
		Exit.addActionListener(this);
		Info.addActionListener(this);
		b.addActionListener( this );
		mainFrame.addWindowListener( this );
	}
	public void paint(Graphics g){
		g.drawImage(back,15,15,this);
	}
	public void actionPerformed( ActionEvent e ) {
	if (e.getSource() == Info) {
			HelpDialog();
		}
		
	if (e.getSource() == Exit){
	    a.setVisible(false);    
	    }
	    
	if (e.getSource() == b){
		sound.loop();
		a.setVisible( false );
		monopolyBoard = new MonopolyBoard( tf1.getText(), tf2.getText() );
		dbp.setLayout( new BorderLayout() );
		bp.setLayout( new BorderLayout() );	
		mainFrame.setSize( 800,650 );
		mainFrame.setBackground(new Color( (80), (180), (210) ) ); //blue color
		mainFrame.setLayout( new FlowLayout(FlowLayout.CENTER));
		mainFrame.add(dbp );
		dbp.add( "Center", bp );
		bp.add( monopolyBoard);
		Panel buttons = new Panel(new GridLayout(0,1));
								
				buttons.add(Roll);
				Roll.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
							if( !monopolyBoard.rolled ) {
								monopolyBoard.Roll();
							}
					}});
				buttons.add(Done);
				Done.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						if( monopolyBoard.rolled ) {
								monopolyBoard.rolled = false;
								monopolyBoard.turn = !monopolyBoard.turn;
								repaint();
							}
						}});

				buttons.add(Buy);
				Buy.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.Buy();
					}});
				buttons.add(Add);
				Add.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.Add();
					}});
				buttons.add(Rem);
				Rem.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.Rem();
					}});
				buttons.add(New);
				New.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.New();
					}});
				buttons.add(pay50);
				pay50.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.pay50();
					}});
					
				buttons.add(Quit);
				Quit.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						monopolyBoard.quit();
					}});
				
				buttons.add(Help);
				Help.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						HelpDialog();
					}});
				
		
				buttons.add(start);
				Credits.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						sound.loop();
					}});

				buttons.add(stop);
				Credits.addActionListener(new ActionListener() {
					public void actionPerformed( ActionEvent e ) {
						sound.stop();
					}});
					
					
		mainFrame.add(buttons);
		mainFrame.setVisible( true );
		}
	}
	public void HelpDialog()  {
		TextArea taHelp;
		String s = "OBJECT\n"+
	"The object of the game is to become the wealthiest player through buying, renting and selling property.\n"+								
	"EQUIPMENT\n"+ 
	"The equipment consists of a board, 2 dice, tokens, 32 houses and 12 hotels. There are Chance and Community Chest cards, a Title Deed card for each property and play money.\n"+
	"PREPARATION\n"+
	"Place the board on a table and put the Chance and Community Chest cards face down on their allotted spaces on the board. Each player chooses one token to represent him/her while traveling around the board.\n"+
	"Each player is given $1500 divided as follows: 2 each of $500's, $100's and $50's; 6 $20's; 5 each of $10's, $5's and $1's."+
	"All remaining money and other equipment go to the Bank."+		
	"BANKER"+
	"Select as Banker a player who will also make a good Auctioneer. A Banker who plays in the game must keep his/her personal funds separate from those of the Bank. When more than five persons play, the Banker may elect to act only as Banker and Auctioneer."+
	"THE BANK"+
	"Besides the Bank's money, the Bank holds the Title Deed cards and houses and hotels prior to purchase and use by the players. The Bank pays salaries and bonuses. It sells and auctions properties and hands out the proper Title Deed cards; it sells houses and hotels to the players and loans money when required on mortgages."+
	"The Bank collects all taxes, fines, loans and interest, and the price of all properties which it sells and auctions."+
	"The Bank never goes broke. If the Bank runs out of money, the Banker may issue as much more as may be needed by writing on any ordinary paper."+
	"THE PLAY"+
	"Starting with the Banker, each player in turn throws the dice. The player with the highest total starts the play: Place your token on the corner marked "+"GO,"+" throw the dice and move your token in the direction of the arrow the number of spaces indicated by the dice. After you have completed your play, the turn passes to the left. The tokens remain on the spaces occupied and proceed from that point on the player's next turn. Two or more tokens may rest on the same space at the same time."+					
	"According to the space your token reaches, you may be entitled to buy real estate or other properties--or obliged to pay rent, pay taxes, draw a Chance or Community Chest card, Go to Jail

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -