diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c3f9cb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/Anurag_Bharadwaj/TicTacToe/build/ +/Anurag_Bharadwaj/TicTacToe/nbproject/private/ \ No newline at end of file diff --git a/Anurag_Bharadwaj/TicTacToe/build.xml b/Anurag_Bharadwaj/TicTacToe/build.xml new file mode 100644 index 0000000..6fd82dd --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + Builds, tests, and runs the project TicTacToe. + + + diff --git a/Anurag_Bharadwaj/TicTacToe/manifest.mf b/Anurag_Bharadwaj/TicTacToe/manifest.mf new file mode 100644 index 0000000..328e8e5 --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/manifest.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +X-COMMENT: Main-Class will be added automatically by build + diff --git a/Anurag_Bharadwaj/TicTacToe/nbproject/build-impl.xml b/Anurag_Bharadwaj/TicTacToe/nbproject/build-impl.xml new file mode 100644 index 0000000..f1d999c --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/nbproject/build-impl.xml @@ -0,0 +1,1413 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No tests executed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + To run this application from the command line without Ant, try: + + java -jar "${dist.jar.resolved}" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + Must select one file in the IDE or set profile.class + This target only works when run from inside the NetBeans IDE. + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + This target only works when run from inside the NetBeans IDE. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set run.class + + + + + + Must select some files in the IDE or set test.includes + + + + + Must select one file in the IDE or set run.class + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + Must select some files in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + Must select one file in the IDE or set test.class + Must select some method in the IDE or set test.method + + + + + + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + Must select one file in the IDE or set applet.url + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Anurag_Bharadwaj/TicTacToe/nbproject/genfiles.properties b/Anurag_Bharadwaj/TicTacToe/nbproject/genfiles.properties new file mode 100644 index 0000000..cffd005 --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +build.xml.data.CRC32=68a265a9 +build.xml.script.CRC32=21e49a08 +build.xml.stylesheet.CRC32=8064a381@1.75.2.48 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=68a265a9 +nbproject/build-impl.xml.script.CRC32=76311a82 +nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48 diff --git a/Anurag_Bharadwaj/TicTacToe/nbproject/project.properties b/Anurag_Bharadwaj/TicTacToe/nbproject/project.properties new file mode 100644 index 0000000..f54a292 --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/nbproject/project.properties @@ -0,0 +1,73 @@ +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processor.options= +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# Files in build.classes.dir which should be excluded from distribution jar +dist.archive.excludes= +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/TicTacToe.jar +dist.javadoc.dir=${dist.dir}/javadoc +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.8 +javac.target=1.8 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=tictactoe.TicTacToe +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/Anurag_Bharadwaj/TicTacToe/nbproject/project.xml b/Anurag_Bharadwaj/TicTacToe/nbproject/project.xml new file mode 100644 index 0000000..06a284e --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/nbproject/project.xml @@ -0,0 +1,15 @@ + + + org.netbeans.modules.java.j2seproject + + + TicTacToe + + + + + + + + + diff --git a/Anurag_Bharadwaj/TicTacToe/src/tictactoe/Cell.java b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/Cell.java new file mode 100644 index 0000000..fb02fce --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/Cell.java @@ -0,0 +1,50 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package tictactoe; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.LineBorder; + +/** + * + * @author Anurag + */ +public class Cell extends JPanel +{ + private char token = ' '; + + public Cell() + { + setBorder(new LineBorder(Color.black, 1)); + addMouseListener(new MouseListener()); + } + public char getToken() + { + return token; + } + public void setToken(char c) + { + token = c; + repaint(); + } + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + + if(token == 'X') + { + g.drawLine(10, 10, getWidth()-10, getHeight()-10); + } + else if(token == 'O') + { + g.drawOval(10, 10, getWidth()-10, getWidth()); + } + } +} diff --git a/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToe.java b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToe.java new file mode 100644 index 0000000..7f08a29 --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToe.java @@ -0,0 +1,32 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package tictactoe; + + +import javax.swing.JFrame; +/** + * + * @author Anurag + */ +public class TicTacToe { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + // TODO code application logic here + + JFrame ticTacToe = new TicTacToeFrame(); + ticTacToe.setTitle("My TicTacToe Game"); + ticTacToe.setSize(600, 600); + ticTacToe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + ticTacToe.setLocationRelativeTo(null); + ticTacToe.setVisible(true); + + + } + +} diff --git a/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToeFrame.java b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToeFrame.java new file mode 100644 index 0000000..b4c3223 --- /dev/null +++ b/Anurag_Bharadwaj/TicTacToe/src/tictactoe/TicTacToeFrame.java @@ -0,0 +1,157 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package tictactoe; + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.LineBorder; + + +/** + * + * @author Anurag + */ +public class TicTacToeFrame extends JFrame +{ + private char whoseTurn = 'X'; + private Cell[][] cells = new Cell[3][3]; + private boolean gameOver = false; + JLabel jlblStatus = new JLabel("X's turn to play"); + + public TicTacToeFrame() + { + JPanel panel = new JPanel(new GridLayout(3, 3, 0, 0)); + for(int i=0; i<3; i++) + { + for(int j=0; j<3; j++) + { + panel.add(cells[i][j] = new Cell()); + } + } + panel.setBorder(new LineBorder(Color.RED, 2)); + // panel.setBackground(Color.BLUE); + jlblStatus.setBorder(new LineBorder(Color.yellow, 1)); + jlblStatus.setBackground(Color.BLUE); + add(panel, BorderLayout.CENTER); + add(jlblStatus, BorderLayout.SOUTH); + } + /** + * + * @return + */ + + + public boolean isFull() + { + for(int i=0; i<3; i++) + { + for(int j=0; j<3; j++) + { + if(cells[i][j].getToken() == ' ') + return false; + } + } + return true; + } + + public boolean isWon(char token) + { + for(int i=0; i<3; i++) + { + if(cells[i][0].getToken() == token + && cells[i][1].getToken() == token + && cells[i][2].getToken() == token) + return true; + } + for(int j=0; j<3; j++) + { + if(cells[0][j].getToken() == token + && cells[1][j].getToken() == token + && cells[2][j].getToken() == token) + return true; + } + if(cells[0][0].getToken() == token + && cells[1][1].getToken() == token + && cells[2][2].getToken() == token) + return true; + if(cells[0][2].getToken() == token + && cells[1][1].getToken() == token + && cells[2][0].getToken() == token) + return true; + + return false; + + } + public class Cell extends JPanel + { + private char token = ' '; + + public Cell() + { + setBorder(new LineBorder(Color.black, 1)); + addMouseListener(new MyMouseListener()); + } + public char getToken() + { + return token; + } + public void setToken(char c) + { + token = c; + repaint(); + } + + @Override + protected void paintComponent(Graphics g) + { + super.paintComponent(g); + + if(token == 'X') + { + g.drawLine(10, 10, getWidth()-10, getHeight()-10); + g.drawLine(getWidth()-10, 10, 10, getHeight()-10); + } + else if(token == 'O') + { + g.drawOval(10, 10, getWidth()-20, getWidth()-20); + } + } + + private class MyMouseListener extends MouseAdapter + { + @Override + public void mouseClicked(MouseEvent e) + { + if(gameOver) + { + System.exit(1); + } + if(token==' ' && whoseTurn != ' ') + setToken(whoseTurn); + if(isWon(whoseTurn)) + { + jlblStatus.setText(whoseTurn + " won, Game Over!"); + whoseTurn = ' '; + gameOver = true; + } + else if(isFull()) + { + jlblStatus.setText("Tie Game.. Game Over!"); + whoseTurn = ' '; + gameOver = true; + } + else + { + whoseTurn = (whoseTurn == 'X')?'O':'X'; + + jlblStatus.setText(whoseTurn + "'s turn."); + } + } + } + } + } +