Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Tic Tac Toe Java Game

natec22
natec22 


Hi, I'm trying to create a tic tac toe game for class and the game must include certain things. I have the base of the code and need to finish it in the designated way. First, there must be an app class, JFrame class, and JPanel Class. Second, I would like to replace the X, O with two images. Third, I would like the game to prompt the two players for their name at the beginning of the game and have the ability to record high scores via XML. I would also like the intro screen to have an instruction button on an before the game that, if clicked on, would give instructions from XML. I have attached the rubric, recommended XML reader and writer, and relevant java file. At the moment, I have the game as one class, yet this would have to be split into as least the three classes mentioned above and likely more. Attachments Tags Clarifications

Answers

Tic Tac Toe Java Game - Solution

mariobeka
mariobeka 



Soulution for the Tic Tac Toe Java Game. Comments included. Attachments
Screen Shot 2014-05-02 at 1.14.01 AM.png (30 K) Download Preview

Screen Shot 2014-05-02 at 1.13.37 AM.png (41 K) Download Preview

Screen Shot 2014-05-02 at 1.14.19 AM.png (16 K) Download Preview

Screen Shot 2014-05-02 at 1.20.47 AM.png (13 K) Download Preview

TicTacToeApp.java (1 K) Download Preview
{ SwingUtilities.invokeLater(new Runnable() { @Override public void

TicTacToeFrame.java (4 K) Download Preview
implements ActionListener { @Override public void actionPerformed(ActionEvent e) { // set up a new Jframe for displaying the Scores JFrame scoreFrame = new JFrame("Scores"); scoreFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); scoreFrame.setSize(new Dimension(300,200)); setLocationRelativeTo(null); scoreFrame.setLayout(new GridLayout(2, 2, 10, 10)); scoreFrame.setVisible(true); // read from xml file x1.openReaderXML("XML_test_writing.xml"); String player1 = ""; String player2

TicTacToePanel.java (9 K) Download Preview
DrawCanvas(); // Construct a drawing canvas (a JPanel) canvas.setPreferredSize(new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT)); // The canvas (JPanel) fires a MouseEvent upon mouse-click canvas.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // mouse-clicked handler int mouseX = e.getX(); int mouseY = e.getY(); // Get the row and column clicked int rowSelected =

XML_240.java (3 K) Download Preview
Object: x.readObject(); * You need to know what TYPE of Object you are reading * String s = (String) x.readObject(); * * WRITER * Open a XML file to write: x.openWriter(filename); * Close a XML writer file: x.closeWriter(); * * Write an Object: x.writeObject(ANY JAVA OBJECT/INSTANCE HERE) *

Screenshots
Screenshot
Screenshot
Screenshot
Screenshot
Purchase Answer

Soulution for the Tic Tac Toe Java Game

mariobeka
mariobeka 



Netbeans Project Attachments
TicTacToe.zip (32 K) Download



Preview
version="1.7.0_51" class="java.beans.XMLDecoder">

Preview

Preview
class="java.beans.XMLDecoder"> <string>Player 1</string>

Preview

Preview
the build. --> <!-- (If you delete it and reopen the project it will be recreated.) --> <!-- By default, only the Clean and Build commands use this build script. --> <!-- Commands such as Run, Debug, and Test only use this build script if --> <!-- the Compile on Save feature is turned

Preview
depends="-init-macrodef-test-debug-junit,-init-macrodef-test-debug-testng" name="-init-macrodef-test-debug"/> <!-- pre NB7.2 profiling section; consider it deprecated --> <target depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check" if="profiler.info.jvmargs.agent" name="profile-init"/> <target if="profiler.info.jvmargs.agent" name="-profile-pre-init"> <!-- Empty placeholder for easier customization. --> <!-- You can override this targe

Preview
xmlns="http://www.netbeans.org/ns/j2se-project/3"> <name>TicTacToe</name> <source-roots> <root id="src.dir"/>

Preview
args) { SwingUtilities.invokeLater(new Runnable() { @Override public

Preview
to store and display the data from xml file JLabel player1jJLabel = new JLabel(player1); player1jJLabel.setHorizontalAlignment(SwingConstants.CENTER); player1jJLabel.setFont(new Font("Arial", Font.BOLD, 25)); JLabel player2jJLabel = new JLabel(player2); player2jJLabel.setHorizontalAlignment(SwingConstants.CENTER); player2jJLabel.setFont(new Font("Arial", Font.BOLD, 25)); JLabel points1jJLabel = new JLabel(String.valueOf(points1)); points1jJLabel.setHorizontalAlignment(SwingConstants.CENT

Preview
Draw the Seeds of all the cells if they are not empty // Use Graphics2D which allows us to set the pen's stroke Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(SYMBOL_STROKE_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); // Graphics2D // only for (int row = 0; row < ROWS; ++row) { for (int col =

Preview
the class XML_240 x = new XML_240(); * READER * Open a XML file to read: x.openReader(filename); * Close a XML reader file: x.closeReader(); * * Read an Object: x.readObject(); * You need to know what TYPE of Object you are reading * String s = (String) x.readObject(); *

Screenshots
Screenshot
Screenshot
Purchase Answer