Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  help plzz  (Read 1292 times)
0 Members and 1 Guest are viewing this topic.
Offline mmc

Innocent Bystander





« Posted 2006-03-30 15:17:52 »

Hello,

I have to create game called "Noughts and Crosses". There are 4 classes OXGame.java, OXGUI.java, OXBoard.java, OXCell.java. The layout is done, below are the coding for layout. Now i need to make the game work, i dont know how to do that. Below is the link to see how the layout looks like:

http://img235.imageshack.us/img235/4863/nnc5tl.jpg

This below info is how to create the game:

Outline of the design of the system

    * The OXGame class is the OXO game expert - it understands the rules of the OXO game and keeps track of the state of a game during play, and detects the end of play including the outcome of the game.
    * The OXGUI and OXBoard class are responsible for communication with the users of the system - collecting inputs from the user and displaying the state of the OXO game. These classes utilise the functionality of the OXGame class.

OXGame

    * A method public makePlay (int rowOfPlay, int columnOfPlay) is required so that a play can be made for the player whose turn it is to make a play.
    * A method public getb (int row, int column) is required so that the state of the positions on the board can be checked by other classes.
    * After each valid play, if the game is not finished, it becomes the other player's turn to make a play.
    * If the computer player is taking the part of the 'O' player and it is the 'O' player's turn, the OXGame will utilise a CompPlayer instance to make that play.

OXGUI

    * Complete the method actionPerformed of the class OXGUI - the class needs to become an ActionListener to capture user inputs from the buttons. These actions being translated into method calls against other objects in the system when necessary.

OXBoard

    * Complete one or more (you decide!) implementation(s) of 'mouse' method(s) of the class OXBoard - this class needs to become a MouseListener to capture user requests' to make a play in a particular position of the board. Specific mouse event(s) being translated into method calls against other objects in the system as necessary.
    * The user interface needs to be updateable to represent the current state of the board.

CompPlayer

    * You will need to write a new class, CompPlayer, that has three instance methods, void generatePlay (int [] [] pBoard) , int getColumnOfPlay () and int getRowOfPlay () , such that:
          o Once an instance of CompPlayer is created, a call to method void generatePlay ( int [] [] pBoard ) should create a valid play for 'O' based upon the OXO board state, pBoard. The row and column of this generated play being stored within the instance, ready for the assessor methods (described below) to be called to obtain the play.
          o After a call to generatePlay the column value of the generated play can be determined via int getColumnOfPlay () and the row value of the generated play can be determined via int getRowOfPlay () .
    * Note: that a random number generator should be used to choose the computer's move.

Here are the codes:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class OXGame {
    public static final int None = 0;
    public static final int Draw = 3;
    public static final int NoPlayer = 0;
    public static final int XPlayer = 1;                  
    public static final int OPlayer = 2;
    //array that keeps track of the moves on the 3x3 grid.
    private int b[][] = new int[3][3];    
 
    //GUI created
    private OXGUI gui;
     public static void main(String[] args){
 OXGame game = new OXGame();      
    }
    public OXGame(){
 gui  = new OXGUI(this);
 newGame();
    }
    public void newGame(){
 for(int r=0; r<3; r++){ for(int c=0; c<3; c++) {b[r][c]= NoPlayer;}}      gui.refresh();
    }
 
    public int getb(int r, int c){
 return b[r][c];
    }
 
}
 
 
 

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 
public class OXGUI extends JFrame implements ActionListener{
    private OXGame game;
    private static final int FRAME_WIDTH=500;
    private static final int FRAME_HEIGHT=500;
    private static int FRAME_X_ORIGIN =150;
    private static int FRAME_Y_ORIGIN= 200;
    private JButton close, newGame;
    private ButtonGroup choiceGroup;
    public  JRadioButton turnon, turnoff;  //read by the parent OXGame
    private OXBoard board;
    private JTextArea textArea;
    public OXGUI(OXGame g){
 game = g;
 setTitle("Noughts and Crosses");
 setSize(FRAME_WIDTH,FRAME_HEIGHT);
 setLocation(FRAME_X_ORIGIN, FRAME_Y_ORIGIN);
 
 Container contentPane = getContentPane();
 contentPane.setBackground(Color.white);
 contentPane.setLayout(new BorderLayout());
 JPanel choice = new JPanel();
 choice.setLayout(new FlowLayout());
 choice.add(new JLabel("Computer Player"));
 ButtonGroup choiceGroup = new ButtonGroup();
 turnon = new JRadioButton("Yes");  
 turnoff = new JRadioButton("No");
 choiceGroup.add(turnon);
 choiceGroup.add(turnoff);  
 choice.add(turnon);
 choice.add(turnoff);
 turnon.setSelected(true);
 contentPane.add(BorderLayout.NORTH, choice);
 board = new OXBoard(game,this);
 contentPane.add(BorderLayout.CENTER, board);
 JPanel southPanel = new JPanel();
 southPanel.setLayout(new BorderLayout());
 textArea = new JTextArea();
 textArea.setColumns(22);
 textArea.setRows(1);
 textArea.setEditable(false);
 southPanel.add(BorderLayout.NORTH,textArea);
 
 JPanel buttons = new JPanel();
 newGame = new JButton("New Game");
 buttons.add(newGame);
 close = new JButton("Quit");
 buttons.add(close);
 southPanel.add(BorderLayout.SOUTH, buttons);
 contentPane.add(BorderLayout.SOUTH,southPanel);
 setVisible(true);
 setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
 
    public void refresh(){
 board.refresh();
        // To be modified!
 textArea.setText("Bla");
    }
  // Deal with clicks on buttons
  public void actionPerformed(ActionEvent e){
      //  Your code!
  }
 
}
 
 
 
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class OXBoard extends JPanel implements MouseListener{
    private OXGame game;
    private OXGUI gui;
    private static final int NMB_COL = 3;
    private static final int NMB_ROW = 3;
    private OXCell[][] board = new OXCell[NMB_COL][NMB_ROW];    
 
    public OXBoard(OXGame a, OXGUI b){    
 game= a;
 gui=b;
 setLayout(new GridLayout(NMB_COL,NMB_ROW));
 for (int row = 0; row < NMB_ROW; row++){
     for (int col = 0; col < NMB_COL; col++){
  OXCell cell = new OXCell(row,col);
  board[row][col] = cell;
 
  // use panel with borderlayout to centre the cell
  Panel p = new Panel();
  p.setLayout(new BorderLayout());
  add(p);
  p.add(Box.createRigidArea(new Dimension(15, 0)), BorderLayout.WEST);
  p.add(cell, BorderLayout.CENTER);
  p.add(Box.createRigidArea(new Dimension(15, 0)), BorderLayout.EAST);
     }
 }
 refresh();
    }    
  // Mouse actions
    public void mouseClicked(MouseEvent e){  //Your code if any
}
    public void mouseEntered(MouseEvent e){ //Your code if any
}
    public void mousePressed(MouseEvent e){ //Your code if any
}
    public void mouseExited(MouseEvent e){ //Your code if any
}
    public void mouseReleased(MouseEvent e){ //Your code if any
}
    public void refresh(){
 // This method should be modified!
 int cont;
 for (int r = 0; r < NMB_ROW; r++){
     for (int c = 0; c < NMB_COL; c++){
  cont = OXCell.BLANK;
  board[r][c].setContent(cont);
     }
 }
    }
}
 

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class OXCell extends JPanel{
    public static final int BLANK = 0;
    public static final int NOUGHT = 1;
    public static final int CROSS = 2;
    private static final String BLANK_STRING = " ";
    private static final String NOUGHT_STRING = "O";
    private static final String CROSS_STRING = "X";
 
    private static final String BLANK_IMAGE_FILE = "blank.gif";
    private static final String NOUGHT_IMAGE_FILE = "nought.gif";
    private static final String CROSS_IMAGE_FILE = "cross.gif";
 
 
    private JLabel content;
    private int row, col;
    public OXCell(int r, int c){
 row = r;
 col = c;
 content = new JLabel(BLANK_STRING);
 setLayout(new BorderLayout());
 setBackground(Color.white);
 setBorder(BorderFactory.createLineBorder(Color.black));
        add(content);
    }
 
    public int getRow()
    {
 return row;
    }
    public int getCol()
    {
 return col;
    }
 
    public void setContent(int i){
 switch (i){
     /*
 case BLANK: content.setText(BLANK_STRING); break;
 case NOUGHT: content.setText(NOUGHT_STRING); break;
 case CROSS: content.setText(CROSS_STRING);
     */

 case BLANK: content.setIcon(new ImageIcon(BLANK_IMAGE_FILE)); break;
 case NOUGHT: content.setIcon(new ImageIcon(NOUGHT_IMAGE_FILE)); break;
 case CROSS: content.setIcon(new ImageIcon(CROSS_IMAGE_FILE)); break;
 default: break;
        }
    }
 
}//OXCell
Offline robertATpm

Junior Newbie





« Reply #1 - Posted 2006-03-30 16:01:51 »

Smells like someone's homework to me... Cheesy

Robert Costello
www.playfulminds.com
Offline Kova

Senior Duke





« Reply #2 - Posted 2006-03-31 01:00:53 »

ok... mmc, you aren't even trying to do it yourself... how about you at least try it and then ask here when you get stuck  Angry
doubt anyone here is going to do your whole assignment  Roll Eyes
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Scrat

Innocent Bystander





« Reply #3 - Posted 2006-05-09 12:28:32 »

Hello mmc you think you are smart aint you???(Why do you always want everything to be done for you)
Lets see what Andy is got to say about this!! Shocked Shocked Shocked Shocked

Offline Mr_Light

Senior Duke


Medals: 1


shiny.


« Reply #4 - Posted 2006-05-09 13:31:39 »

was it nessasery to bump this thread?  Sad

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2006-05-10 04:20:00 »

I dont even understand the question.  Youygave the assignment.  Then  you gave code which I assume implements it.

If your code isnt working, please tell us the specific problem you are having.

If all this, including the code, was provided by your instructor Im not sure *you* understand the assignment.  If you can't explain it here more clearly you better go ask him or her for more explaination.

In any case, while we are willing to help you learn by helping you understand things you don't we are NOT willing to help you avoid learning by doing your work for you.  What are you going to do when you graduate, get a job, and your boss gives you an assignment?  Come back here and ask us to do your work for you??

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (41 views)
2014-10-17 03:59:02

Norakomi (33 views)
2014-10-16 15:22:06

Norakomi (26 views)
2014-10-16 15:20:20

lcass (30 views)
2014-10-15 16:18:58

TehJavaDev (59 views)
2014-10-14 00:39:48

TehJavaDev (60 views)
2014-10-14 00:35:47

TehJavaDev (50 views)
2014-10-14 00:32:37

BurntPizza (66 views)
2014-10-11 23:24:42

BurntPizza (38 views)
2014-10-11 23:10:45

BurntPizza (80 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!