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

📄 monopolyboard.java

📁 This A java game to play monopoly
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		g.drawLine( 266, 79, 266, 7 );		g.drawLine( 300, 79, 300, 7 );		g.drawLine( 333, 79, 333, 7 );		g.drawLine( 366, 79, 366, 7 );		g.drawLine( 400, 79, 400, 7 );		g.drawLine( 100, 421, 100, 490 );		g.drawLine( 133, 421, 133, 490 );		g.drawLine( 166, 421, 166, 490 );		g.drawLine( 200, 421, 200, 490 );		g.drawLine( 233, 421, 233, 490 );		g.drawLine( 266, 421, 266, 490 );		g.drawLine( 300, 421, 300, 490 );		g.drawLine( 333, 421, 333, 490 );		g.drawLine( 366, 421, 366, 490 );		g.drawLine( 400, 421, 400, 490 );		//the array of positions for the location of where to draw the houses		int places[][] = {	{-1,-1},{85,378},{-1,345},{85,312},{-1,-1},{85,245},{85,212},						{-1,-1},{85,145},{85,112},{-1,-1},{112,85},{145,85},{178,85},						{212,85},{245,85},{278,85},{-1,-1},{345,85},{378,85},{-1,-1},						{405,112},{-1,-1},{405,178},{405,212},{405,245},{405,278},						{405,312},{405,345},{405,378},{-1,-1},{378,405},{345,405},						{-1,-1},{278,405},{245,405},{-1,-1},{178,405},{145,-1},						{112,405}};				//Draw how many houses are on each owned property		for( int i=0;  i<40;  i++ ) {			if( propertymanager.Properties[i][0] == 1 ) {				g.setColor( Color.blue );				g.fill3DRect(places[i][0],places[i][1],10,10,true );				g.setColor( Color.white );				g.setFont( new Font( "Verdana", Font.PLAIN, 8 ) );				if(  propertymanager.Properties[i][1] != -1 )					g.drawString( propertymanager.Properties[i][1]+"",places[i][0]+3,places[i][1]+8 );			}			else if( propertymanager.Properties[i][0] == 2 ) {				g.setColor( Color.red );				g.fill3DRect(places[i][0],places[i][1],10,10,true );				g.setColor( Color.white );				g.setFont( new Font( "Verdana", Font.PLAIN, 8 ) );				if(  propertymanager.Properties[i][1] != -1 )					g.drawString( propertymanager.Properties[i][1]+"",places[i][0]+3,places[i][1]+8 );			}		}		//Draw the dice		g.setColor( new Color( (230), (230), (230) ) );		g.setFont( new Font( "verdana", Font.BOLD, 20 ) );		g.fillRoundRect( 120, 150, 33, 33 ,5,5);		g.fillRoundRect( 161, 150, 33, 33,5,5);//		g.setFont( new Font( "Arial", Font.BOLD, 20 ) );		g.setColor( Color.black );		//Dice 1		if (Dice1 ==1){			g.fill3DRect(130,165,6,6,true);		}		else if (Dice1 == 2){			g.fill3DRect(125,165,6,6,true);			g.fill3DRect(145,165,6,6,true);		}		else if (Dice1 == 3){			g.fill3DRect(125,155,6,6,true);			g.fill3DRect(135,165,6,6,true);			g.fill3DRect(145,175,6,6,true);		}		else if (Dice1 == 4){			g.fill3DRect(125,155,6,6,true);			g.fill3DRect(125,170,6,6,true);			g.fill3DRect(140,155,6,6,true);			g.fill3DRect(140,170,6,6,true);		}		else if (Dice1 == 5){			g.fill3DRect(125,155,6,6,true);			g.fill3DRect(125,170,6,6,true);			g.fill3DRect(140,155,6,6,true);			g.fill3DRect(140,170,6,6,true);			g.fill3DRect(132,165,6,6,true);		}		else if (Dice1 == 6) {			g.fill3DRect(125,155,6,6,true);			g.fill3DRect(125,165,6,6,true);			g.fill3DRect(125,175,6,6,true);			g.fill3DRect(140,155,6,6,true);			g.fill3DRect(140,165,6,6,true);			g.fill3DRect(140,175,6,6,true);		}		//Dice 2		g.setColor(Color.black);		if (Dice2 ==1){			g.fill3DRect(172,165,6,6,true);		}		else if (Dice2 == 2){			g.fill3DRect(165,165,6,6,true);			g.fill3DRect(185,165,6,6,true);		}		else if (Dice2 == 3){			g.fill3DRect(165,155,6,6,true);			g.fill3DRect(175,165,6,6,true);			g.fill3DRect(185,175,6,6,true);		}		else if (Dice2 == 4){			g.fill3DRect(165,155,6,6,true);			g.fill3DRect(165,170,6,6,true);			g.fill3DRect(175,155,6,6,true);			g.fill3DRect(175,170,6,6,true);		}		else if (Dice2 == 5){			g.fill3DRect(165,155,6,6,true);			g.fill3DRect(165,170,6,6,true);			g.fill3DRect(180,155,6,6,true);			g.fill3DRect(180,170,6,6,true);			g.fill3DRect(172,165,6,6,true);		}		else if (Dice2 == 6) {			g.fill3DRect(165,155,6,6,true);			g.fill3DRect(165,165,6,6,true);			g.fill3DRect(165,175,6,6,true);			g.fill3DRect(180,155,6,6,true);			g.fill3DRect(180,165,6,6,true);			g.fill3DRect(180,175,6,6,true);		}		g.drawString("Total=" + (Dice1 + Dice2),200,190);				//Draw the border around the property stats		//g.setColor( new Color( (200), (200), (240) ) );		g.setColor(Color.white);			g.fill3DRect( 107, 203, 184, 192, true );		g.setColor(Color.black);		g.drawRect( 112,205,170,185);	/*	if (propertymanager.one.Position == 1  || propertymanager.one.Position == 3 ||propertymanager.two.Position == 1 || propertymanager.two.Position== 3   )			g.setColor(Color.blue);		else if (propertymanager.one.Position == 0 || propertymanager.one.Position == 2 || propertymanager.one.Position == 4 || propertymanager.one.Position == 7|| propertymanager.one.Position == 17|| propertymanager.one.Position == 22 || propertymanager.one.Position == 4 || propertymanager.one.Position == 36|| propertymanager.one.Position == 38|| propertymanager.two.Position == 0 || propertymanager.two.Position == 2 || propertymanager.two.Position == 4 || propertymanager.two.Position == 7|| propertymanager.two.Position == 17|| propertymanager.two.Position == 22 || propertymanager.two.Position == 33|| propertymanager.two.Position == 36|| propertymanager.two.Position == 38)			g.setColor(Color.lightGray);		else if (propertymanager.one.Position == 6 || propertymanager.one.Position == 8 || propertymanager.one.Position == 9 || propertymanager.two.Position== 6 ||propertymanager.two.Position== 8||propertymanager.two.Position== 9)			g.setColor( new Color( (200), (200), (240) ) );		else if (propertymanager.one.Position == 11 || propertymanager.one.Position == 13 || propertymanager.one.Position == 14 || propertymanager.two.Position== 11 ||propertymanager.two.Position== 13||propertymanager.two.Position== 14)			g.setColor( new Color( (200), (30), (200) ) );		else if (propertymanager.one.Position == 16 || propertymanager.one.Position == 18 || propertymanager.one.Position == 19 || propertymanager.two.Position== 16 ||propertymanager.two.Position== 18 || propertymanager.two.Position== 19)			g.setColor( new Color( (220), (140), (140) ) );		else if (propertymanager.one.Position == 21 || propertymanager.one.Position == 23 || propertymanager.one.Position == 24 || propertymanager.two.Position== 21 ||propertymanager.two.Position== 23 ||propertymanager.two.Position== 24)			g.setColor( new Color( (180), (10), (10) ) );		else if (propertymanager.one.Position == 26 || propertymanager.one.Position == 27 || propertymanager.one.Position == 29 || propertymanager.two.Position== 26 ||propertymanager.two.Position== 27 ||propertymanager.two.Position== 29 )			g.setColor(Color.yellow);		else if (propertymanager.one.Position == 31 || propertymanager.one.Position == 32 || propertymanager.one.Position == 34 || propertymanager.two.Position== 31 ||propertymanager.two.Position== 32 ||propertymanager.two.Position== 34)			g.setColor(new Color( (10),(180),(10)));		else if (propertymanager.one.Position == 37 || propertymanager.one.Position == 39  || propertymanager.two.Position== 37 ||propertymanager.two.Position== 39)			g.setColor(new Color( (30), (30), (100) ));		else 			g.setColor(Color.white);			g.fillRect(116,210,160,50);*/			g.setColor(Color.black);			g.drawRect( 116,210,160,50);			//g.drawRect( 110,207,182,190);		//Draw the property stats for the property just landed on by the player		if( turn ) {		if (propertymanager.one.Position == 1  || propertymanager.one.Position == 3 ){			g.setColor(Color.blue);			g.fillRect(116,210,160,50);}					else if (propertymanager.one.Position == 0 || propertymanager.one.Position == 2 || propertymanager.one.Position == 4 || propertymanager.one.Position == 7|| propertymanager.one.Position == 17|| propertymanager.one.Position == 22 || propertymanager.one.Position == 4 || propertymanager.one.Position == 36|| propertymanager.one.Position == 38){			g.setColor(Color.lightGray);			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 6 || propertymanager.one.Position == 8 || propertymanager.one.Position == 9 ){			g.setColor( new Color( (200), (200), (240) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 11 || propertymanager.one.Position == 13 || propertymanager.one.Position == 14){			g.setColor( new Color( (200), (30), (200) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 16 || propertymanager.one.Position == 18 || propertymanager.one.Position == 19 ){			g.setColor( new Color( (220), (140), (140) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 21 || propertymanager.one.Position == 23 || propertymanager.one.Position == 24 ){			g.setColor( new Color( (180), (10), (10) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 26 || propertymanager.one.Position == 27 || propertymanager.one.Position == 29 ){			g.setColor(Color.yellow);			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 31 || propertymanager.one.Position == 32 || propertymanager.one.Position == 34 ){			g.setColor(new Color( (10),(180),(10)));			g.fillRect(116,210,160,50);}		else if (propertymanager.one.Position == 37 || propertymanager.one.Position == 39  ){			g.setColor(new Color( (30), (30), (100) ));			g.fillRect(116,210,160,50);}				else {			g.setColor(Color.white);			g.fillRect(116,210,160,50);}								propertymanager.DrawPropertyStats( Player1.Position, 110, 207, g );			g.setColor( Color.blue );			g.setFont( new Font( "Courier", Font.PLAIN, 18 ) );			g.drawString( "Turn = " + Player1.Name, 110, 120 );			if( !rolled )				g.drawString( "Roll", 180, 140 );		}		else { // for player 2		if (propertymanager.two.Position == 1  || propertymanager.two.Position == 3 ){			g.setColor(Color.blue);			g.fillRect(116,210,160,50);}					else if (propertymanager.two.Position == 0 || propertymanager.two.Position == 2 || propertymanager.two.Position == 4 || propertymanager.two.Position == 7|| propertymanager.two.Position == 17|| propertymanager.two.Position == 22 || propertymanager.two.Position == 4 || propertymanager.two.Position == 36|| propertymanager.two.Position == 38){			g.setColor(Color.lightGray);			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 6 || propertymanager.two.Position == 8 || propertymanager.two.Position == 9 ){			g.setColor( new Color( (200), (200), (240) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 11 || propertymanager.two.Position == 13 || propertymanager.two.Position == 14){			g.setColor( new Color( (200), (30), (200) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 16 || propertymanager.two.Position == 18 || propertymanager.two.Position == 19 ){			g.setColor( new Color( (220), (140), (140) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 21 || propertymanager.two.Position == 23 || propertymanager.two.Position == 24 ){			g.setColor( new Color( (180), (10), (10) ) );			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 26 || propertymanager.two.Position == 27 || propertymanager.two.Position == 29 ){			g.setColor(Color.yellow);			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 31 || propertymanager.two.Position == 32 || propertymanager.two.Position == 34 ){			g.setColor(new Color( (10),(180),(10)));			g.fillRect(116,210,160,50);}		else if (propertymanager.two.Position == 37 || propertymanager.two.Position == 39  ){			g.setColor(new Color( (30), (30), (100) ));			g.fillRect(116,210,160,50);}				else {			g.setColor(Color.white);			g.fillRect(116,210,160,50);}			propertymanager.DrawPropertyStats( Player2.Position, 110, 207, g );			g.setColor( Color.red);			g.setFont( new Font( "Courier", Font.PLAIN, 18 ) );			g.drawString( "Turn = " + Player2.Name, 110, 120 );			if( !rolled )				g.drawString( "Roll", 180, 140 );		}		//Draw the players		Player1.DrawPlayer( g );				Player2.DrawPlayer( g );				//is the player out of money?  if so, draw the frame telling them they		//must sell property		if( (Player1.Money < 0 || Player2.Money < 0) && !frame.isShowing() ) {			frame.setBackground( Color.lightGray );			frame.setSize( 400, 110 );			Label lab = new Label( "You must sell property or houses to pay your debt." );			frame.add( lab );			frame.setVisible( true );			frame.addWindowListener( new WindowAdapter() {				public void windowClosing( WindowEvent e ) {					frame.setVisible( false );				}			});			noMoney = true;			Rem();		}	}		/*public void DrawVertString (String propertyname,int x,int y){		//String m = propertyname.length();		for (int i = 0; i< propertyname;i++){			y = y + 10;			drawString(propertyname,x,y);		}			}*/			//The usual component methods	public boolean contains( int x, int y ) {		if( x>0  &&  x<Width  &&  y>0  &&  y<Height ) 			return true;		return false;	}	public Dimension getPreferredSize() {		return new Dimension( Width, Height );	}	public Dimension getMinimumSize() {		return new Dimension( Width, Height );	}	//mehtods used in Monopoly . java.//getting out of jail...	public void pay50() {			if( turn && Player1.inJail ) {						Player1.Money -= 50;						System.out.println( Player1.Name +" paid $50 to get out of jail." );						propertymanager.Properties[20][1] += 50;						Player1.inJail = false;					}					else if( !turn && Player2.inJail ) {						Player2.Money -= 50;						System.out.println( Player2.Name +" paid $50 to get out of jail." );						propertymanager.Properties[20][1] += 50;						Player2.inJail = false;					}					repaint();				}					//credits			//quiting the program;	public void quit() {	final Frame quit = new Frame();		final Label question = new Label("Are you sure you want to end this game?" );		final Button yes = new Button("Yes" );		final Button no = new Button( "NO" );		quit.setSize( 400, 90 );		quit.setBackground( Color.lightGray );		quit.setLayout( new FlowLayout(FlowLayout.CENTER) );		quit.add( question);		quit.add( yes );		quit.add( no );		quit.setVisible( true );		no.addActionListener( new ActionListener() {			public void actionPerformed( ActionEvent e ) {				quit.setVisible(false);				}						});		yes.addActionListener ( new ActionListener() {		    public void actionPerformed ( ActionEvent e) {			//System.out.println("quit");			quit.setVisible(false);			Monopoly.mainFrame.setVisible(false);//System.exit(0);			}			});		quit.addWindowListener( new WindowAdapter() {			public void windowClosing( WindowEvent e ) {				quit.setVisible( false );				repaint();			}		});		repaint();	}	//either the 'roll' button was clicked or 'r' was pressed.	public void Roll() {		boolean snakeEyes = false;		Dice1 = ( int )( Math.random() * 6 + 1 );		Dice2 = ( int )( Math.random() * 6 + 1 );		if( Dice1 == Dice2 ) {			snakeEyes = true;			rolled = false;		}		else			rolled = true;		if( turn ) {			Player1.Move( Dice1 + Dice2, snakeEyes, propertymanager );			String a1 = propertymanager.CheckProperty( Player1.PlayerNum, Player1.Position );		}

⌨️ 快捷键说明

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