Register and join over 40,000 other developers!
Recent Topics
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
-
Job Gig PHP Form Needed
PJohnson - Apr 18 2019 03:55 AM
-
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
-
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

60 replies to this topic
#25
Posted 26 February 2008 - 05:31 PM
hello...i have a program tictactoe in which a host and a client can play but i got this problem that i wanted to create a server for the two that controls the game. i tried to create one but the other client does not connect to both server and host can you help me out plssss.... i really need it...
#26
Posted 27 February 2008 - 04:41 PM
I've wanted to implement RMI into this tutorial for a while, but I just don't know how to. So I cant help you there - maybe someone else can.
#27
Posted 11 March 2010 - 07:19 AM
John, can you help me, when i use this code
and i want to expand moer pole for example [4][4], so i dont know how to edit this code, can you help me ? Thanks
package general; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TicTacToeV2 implements ActionListener { /*Instance Variables*/ private int[][] winCombinations = new int[][] { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, //horizontal wins {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, //virticle wins {0, 4, 8}, {2, 4, 6} //diagonal wins }; private JFrame window = new JFrame("Tic-Tac-Toe"); private JButton buttons[] = new JButton[9]; private int count, xWins, oWins = 0; private String letter = ""; private boolean win = false; public TicTacToeV2(){ /*Create Window*/ window.setSize(300,300); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setLayout(new GridLayout(3,3)); /*Add Buttons To The Window*/ for(int i=0; i<=8; i++){ buttons[i] = new JButton(); window.add(buttons[i]); buttons[i].addActionListener(this); } /*Make The Window Visible*/ window.setVisible(true); } /** When an object is clicked, perform an action. @param a action event object */ public void actionPerformed(ActionEvent a) { count++; /*Calculate whose turn it is*/ if(count % 2 == 0) letter = "O"; else letter = "X"; /*Write the letter to the button and deactivate it*/ JButton pressedButton = (JButton)a.getSource(); pressedButton.setText(letter); pressedButton.setEnabled(false); /*Determine who won*/ for(int i=0; i<=7; i++){ if( buttons[winCombinations[i][0]].getText().equals(buttons[winCombinations[i][1]].getText()) && buttons[winCombinations[i][1]].getText().equals(buttons[winCombinations[i][2]].getText()) && buttons[winCombinations[i][0]].getText() != ""){ win = true; } } /*Show a dialog when game is over*/ if(win == true){ JOptionPane.showMessageDialog(null, letter + " wins the game!"); playAgainDialog(); } else if(count == 9 && win == false){ JOptionPane.showMessageDialog(null, "The game was tie!"); playAgainDialog(); } } public void playAgainDialog() { if(letter.equals("X")) xWins++; else oWins++; int response = JOptionPane.showConfirmDialog(null, "Do you want to play again?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(response == JOptionPane.YES_OPTION) reset(); else System.exit(0); } public void reset() { for(int i=0; i<=8; i++){ buttons[i].setText(""); buttons[i].setEnabled(true); } win = false; count = 0; } public static void main(String[] args){ TicTacToeV2 starter = new TicTacToeV2(); } }
and i want to expand moer pole for example [4][4], so i dont know how to edit this code, can you help me ? Thanks
for(int i=0; i<=7; i++){ if( buttons[winCombinations[i][0]].getText().equals(buttons[winCombinations[i][1]].getText()) && buttons[winCombinations[i][1]].getText().equals(buttons[winCombinations[i][2]].getText()) && buttons[winCombinations[i][0]].getText() != ""){ win = true; }
#28
Posted 11 March 2010 - 03:46 PM
For the AI
1. You would need to edit the winCombinations to account for a 4x4 grid
2. Check for a win condition:
You will obviously need to edit the GUI as well.
1. You would need to edit the winCombinations to account for a 4x4 grid
private int[][] winCombinations = new int[][] { {0, 1, 2, 3}, {4, 5, 6, 7}...
2. Check for a win condition:
for(int i=0; i<=7; i++){ if( buttons[winCombinations[i][0]].getText().equals(buttons[winCombinations[i][1]].getText()) && buttons[winCombinations[i][1]].getText().equals(buttons[winCombinations[i][2]].getText()) && buttons[winCombinations[i][2]].getText().equals(buttons[winCombinations[i][3]].getText()) && buttons[winCombinations[i][0]].getText() != ""){ win = true; }
You will obviously need to edit the GUI as well.
#29
Posted 12 March 2010 - 06:19 PM
Thanks man
, can you help me last stuff ? I want to create MenuBar, when i paste this code to your code, but it opens two windows... can you help me ?
Thanks you very much

Thanks you very much
setSize(200,200); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem newAction = new JMenuItem("New"); JMenuItem openAction = new JMenuItem("Open"); JMenuItem exitAction = new JMenuItem("Exit"); fileMenu.add(newAction); fileMenu.add(openAction); fileMenu.addSeparator(); fileMenu.add(exitAction); newAction.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { Main novy = new Main(); } }); openAction.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.out.println("You havddddddde clicked on the new action"); } }); public static void main(String[] args) { MujMenu me = new MujMenu(); me.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); me.setVisible(true); }
#30
Posted 12 March 2010 - 09:53 PM
I'm not sure. I haven't programmed in Java in two years - try asking in the Java section/forum.
#31
Posted 09 April 2010 - 08:09 PM
I did a Tic Tac Toe in a tutorial eariler this year, it is quite a good program to practice various skills and I found it a useful way of learning how to use arrays and simple windows. thanks for the tut guys.
#32
Posted 26 May 2010 - 05:04 AM
hey, I'm a beginner in java and i want to know what to do with the code you posted to make the game work ( probably a dumb question :/ ). Thanks in advance.
#33
Posted 28 May 2010 - 04:05 AM
Copy and Paste it into a compiler. If you haven't figured that out. Then you really haven't started coding yet.
#34
Posted 13 June 2010 - 06:06 PM
The only thing with your program is that I think you should explain your package: mytictactoe; because it will put up an error on everyone else's IDE's
#35
Posted 13 June 2010 - 06:07 PM
Mohammed I recommend for you to download the latest Java and also a compiler and interpreter which is what i use: NetBeans though I heard Eclipse is better.
#36
Posted 15 June 2010 - 04:41 AM
Hello guys.
I am quite new in java programming and I would appreciate some help in a problem I have.
I am currently in an artificial intelligence lesson and I have o project of making a tic tac toe game in xj3d. However I have tried a lot lately I could not manage great progress.
So I would need some help if that's not a big problem for you.
Thanks in advance.
I am quite new in java programming and I would appreciate some help in a problem I have.
I am currently in an artificial intelligence lesson and I have o project of making a tic tac toe game in xj3d. However I have tried a lot lately I could not manage great progress.
So I would need some help if that's not a big problem for you.
Thanks in advance.
Also tagged with one or more of these keywords: tic-tac-toe
General Forums →
Game Development →
"Tic-Tac-Toe-Cover-Up" game coding dilemma!Started by contron, 17 Oct 2013 ![]() |
|
![]() |
||
Tutorial Forums →
Pascal and Delphi Tutorials →
A short Tic-Tac-Toe implementation in Pascal/DelphiStarted by medwatt, 13 Aug 2013 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
C++ Tic-tac-toeStarted by dbordzo, 27 Jul 2013 ![]() |
|
![]() |
||
General Forums →
Game Development →
Java Game: Tic-Tac-Toe (Revised Game)Started by Chall, 11 Oct 2012 ![]() |
|
![]() |
||
General Forums →
Everything Else →
Request Services →
Urge For Request Of Help With Msvc++ 2008 And OpenglStarted by hdavidson, 11 Apr 2012 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download