i417.photobucket.com/albums/pp260/spawnacreature/Opoly.jpg
i need to know how to make the blue boxes, i need to set the size of board to 21.
also how would i get the postions to cycle through and when it reaches the end to say game over in red.
anyhelp would be apreciated
this is what i have so far it works. I have it set up to look like the picture just doesnt do anything
i just dont know what to add, to get the numbers to show up next to the rewards and postion or also the blue squares
and help would be very apreciated.
import java.awt.*; import javax.swing.*; import java.awt.event.*; // needed for event handling public class OpolyPanel extends JPanel implements ActionListener { JMenuBar b; JMenu menu = new JMenu("Actions"); JLabel counterLabel = new JLabel("Position: 0 "); JButton playTurn = new JButton("Play Turn"); JMenuItem white = new JMenuItem("White"); JMenuItem red = new JMenuItem("red"); JMenuItem blue = new JMenuItem("blue"); JMenuItem pink = new JMenuItem("pink"); JMenuItem yellow = new JMenuItem("yellow"); JMenuItem green = new JMenuItem("green"); JMenuItem orange = new JMenuItem("orange"); JMenuItem quit = new JMenuItem("Quit"); JMenuItem newGame = new JMenuItem(" New Game"); JLabel countLabel = new JLabel("Reward: 0 "); public OpolyPanel(JMenuBar bar) { super.Opoly2(25); [B]how do u get this super to work, when that work methods should work [/B] setBackground(Color.white); this.b = bar; b.add(menu); this.add(counterLabel); this.add(playTurn); // place button in panel playTurn.addActionListener(this);// panel is listener for button this.add(countLabel); menu.add(newGame); newGame.addActionListener(this); menu.add(white); white.addActionListener(this); menu.add(red); red.addActionListener(this); menu.add(blue); blue.addActionListener(this); menu.add(pink); pink.addActionListener(this); menu.add(yellow); yellow.addActionListener(this); menu.add(green); green.addActionListener(this); menu.add(orange); orange.addActionListener(this); menu.add(quit); quit.addActionListener(this); } public void paintComponent(Graphics g) { super.paintComponent(g); } public void actionPerformed(ActionEvent e) { if (e.getSource() == quit){ System.exit(0);} if (e.getSource() == red) setBackground(Color.red); else if (e.getSource() == blue) setBackground(Color.blue); else if (e.getSource() == pink) setBackground(Color.pink); else if (e.getSource() == yellow) setBackground(Color.yellow); else if (e.getSource() == green) setBackground(Color.green); else if (e.getSource() == orange) setBackground(Color.orange); else if (e.getSource() == white) setBackground(Color.white); if(e.getSource() == playTurn()) reset(); [B]I want the game to reset when i hit new game[/B] } }
import java.awt.*; import javax.swing.*; public class GopolyDriver{ public static void main(String[] args){ DisplayWindow d = new DisplayWindow(); JMenuBar menuBar = new JMenuBar(); d.setJMenuBar(menuBar); OpolyPanel p = new OpolyPanel(menuBar); d.addPanel(p); d.showFrame(); } }
The game cant change this file...
public class Opoly2{ private int boardSize; private int pos = 0; private int steps = 0; private int reward = 10; public Opoly2(int boardSize){ this.boardSize=boardSize; } public int getPos(){return pos;} public int getSteps(){return steps;} public int getReward(){return reward;} public int getBoardSize(){return boardSize;} public void reset(){ // resets game for another start pos = 0; steps = 0; reward = 10; } public int spin(){ // gives a random spin 1-5 int p=(1+(int)(Math.random()*5)); return p; } public void move(int p){ // rules for advancing board piece steps++; if (pos + p > boardSize) return; if(pos+p == boardSize-1){ reward=reward/3; pos=0; } else if (pos + p == boardSize) {pos = pos + p; return;} else{ pos = pos + p; if(pos%4==0) reward = 2*reward; } } public boolean isGameOver(){ // game over when piece equals board size exactly return (pos==boardSize); } public void spinAndMove(){ // does a spin, then move int p=spin(); move(p); } public void drawBoard(){ // a crude drawing of the board; shows current reward for(int j=0; j<boardSize; j++){ if(j!=pos){ System.out.print("*");} else{ System.out.print("o");} } if (pos == boardSize)System.out.print("o"); System.out.println(" " + reward); } public void playGame(){ // top level play of game; play continues until game over (duh!) System.out.println("Board Size: " + boardSize); drawBoard(); while (isGameOver()==false){ spinAndMove(); drawBoard(); } System.out.println("game over"); System.out.println("rounds of play: " + steps); System.out.println("final reward: " + reward); } }
Display window
import java.awt.*; import javax.swing.*; public class DisplayWindow extends JFrame{ private Container c; public DisplayWindow(){ super("Display"); c = this.getContentPane(); } public void addPanel(JPanel p){ p.setPreferredSize(new Dimension(500,400)); c.add(p); } public void showFrame(){ this.pack(); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); } }