<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Assistance with writing a tic tac toe program!"]]></title>
		<link>http://forums.hotjoe.com/posts/list/14.page</link>
		<description><![CDATA[Latest messages posted in the topic "Assistance with writing a tic tac toe program!"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ I'm new to java; I'm in my second Java collegiate course, and have to say am barely treading water.  I have a project to create tic tac toe without a gui.  Can anyone point me in the right direction of where to get some leads.  Thanks!]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/579.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/579.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 13:06:55]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Re:Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Sure, <br /> <br /> check out the tutorials at [url]http://java.sun.com/docs/books/tutorial/index.html[/url]  There are a ton of them.  Let us know if you need any help along the way. Good luck]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/580.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/580.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 13:37:53]]> GMT</pubDate>
				<author><![CDATA[ tfecw]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ This is my potential Tic Tac Program without GUI; written in pseudo/java.  If anyone could assist me with this I would greatly appreciate it!<br /> <br /> <br /> <br /> [code]package njohnsonp5;<br /> import java.util.*;<br /> /**<br />  *<br />  * @author Nathan Johnson<br />  */<br /> public class NJohnsonP5Main <br /> {<br />     private char [][] board;<br />     private boolean xturn;<br />     private int numMoves;<br />     <br />     public static void main()<br />     {<br />         Scanner keyb = new Scanner(System.in);<br />         String response;<br />         <br />         do<br />         {<br />             NJohnsonP5Main game = new NJohnsonP5Main();<br />             play();<br />             System.out.println("Would you like to play <br />                                        again?");<br />             response = keyb.nextLine();<br />         }while(response.equalsIgnoreCase("yes"));        <br />         <br />     }<br />     <br />     public NJohnsonP5Main()<br />     {<br />          board = new char [5][5];<br />          xturn = true;<br />          numMoves = 0;<br />     }<br />     <br />     public void play()<br />     {<br />         do<br />         {<br />             //show board<br />             //get valid move<br />             //update board<br />             //determine winner if possible<br />         }while((no one has won)&&(moves &lt; 9));    <br />     }<br />     <br />     public boolean won(int row, int col)//computer indices<br />                                                         (inside)<br />     {<br />         if(allSquaresInRowAreSame) or board[0][0]<br />            ==board[2][2]&&board[0][2]==board[0][4]<br />           return true;<br />         if(allSquaresInColAreSame)<br />           return true;<br />         return wonOnDiagonal();<br />     }<br />     <br />     public boolean wonOnDiagonal()<br />     {<br />         if(board[0][0]==board[2][2]&&board[2][2]<br />            ==board[4][4]&&board[0][0]!=space or " ")<br />             return true;<br />         return //same on positive and not space<br />     }<br /> }[/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/583.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/583.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 14:12:45]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Re:Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Looks good to me.<br /> <br /> PS. Next time when posting make sure to use the [code][[i][/i]/code] tags. It makes it much easier to read. Thanks!]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/585.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/585.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 14:19:18]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Thanks Destin, but I was looking for some assitance in writing the actual code where I have pseudocode.<br /> <br /> I've also submitted my .java in the previous message.]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/588.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/588.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 14:30:31]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Re:Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Ah, sorry :P. Well, what have you tried?<br /> <br /> First of all, you'll need a board.<br /> [code]<br /> private char[][] board = new char[3][3];<br /> [/code]<br /> I would recommend making final chars to represent what is in each sqaure.<br /> [code]<br /> private final char EMPTY = ' ';<br /> private final char PLAYER1 = 'X';<br /> private final char PLAYER2 = 'O';<br /> [/code]<br /> Then, you need to initialize the board.<br /> [code]<br /> public void init() {<br />     for (int x = 0; x &lt; 3; x++) {<br />         for (int y = 0; y &lt; 3; y++) {<br />            board[x][y] = EMPTY;<br />         }<br />     }<br /> }[/code]<br /> Then, to check the winner, this gets a bit tedious.<br /> [code]<br /> public char winner() {<br />     for (int i = 0; i &lt; board.length; i++) {<br />         /* check horizontally */<br />         if (board[i][0] == board[i][1] &&<br />                 board[i][0] == board[i][2]) {<br />             if (board[i][0] != EMPTY) {<br />                 return board[i][0];<br />             }<br />         }<br />         /* check vertically */<br />         if (board[0][i] == board[1][i] &&<br />                 board[0][i] == board[2][i]) {<br />             if (board[0][i] != EMPTY) {<br />                 return board[0][i];<br />             }<br />         }<br />     }<br />      <br />     /* check diagonally */<br />     if (board[0][0] == board[1][1] &&<br />             board[0][0] == board[2][2]) {<br />         if (board[0][0] != EMPTY) {<br />             return board[0][0];<br />         }<br />     }<br />     if (board[0][2] == board[1][1] &&<br />              board[0][2] == board[2][0]) {<br />         if (board[0][2] != EMPTY)) {<br />             return board[0][2];<br />         }<br />     }<br />     return EMPTY;<br /> }[/code]<br /> <br /> Hope this helps a little. Post back if you're still having trouble.]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/592.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/592.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 14:49:57]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ So, I'm adding another array for another board.  Add this to the board I have already?<br /> <br /> And also, I know this might seem extra tedious, but my professor is anal, and he wants us to use his methods, so is there anyway you could alter the win method into my already won method?<br /> <br /> I can't have a gui as well.  He wants to see a old style tic tac toe bracket like<br /> <br />      |     |<br /> ----|----|----<br /> ----|----|----<br />      |     |<br /> <br /> <br /> Thanks a bunch!]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/595.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/595.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:03:21]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ [quote=WannaBe]So, I'm adding another array for another board.  Add this to the board I have already?[/quote]<br /> No, you only need one board. I'm just confused as to why you initialize your board with 5 by 5.<br /> [quote=WannaBe]<br /> And also, I know this might seem extra tedious, but my professor is anal, and he wants us to use his methods, so is there anyway you could alter the win method into my already won method?<br /> [/quote]<br /> Why don't you give it a shot?]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/596.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/596.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:06:16]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ I believe it has to do with a manual tic tac toe screen as opposed to GUI.  <br /> <br /> 01234<br />  -----<br /> 0 |<br /> 1 |<br /> 2 |<br /> 3 |<br /> 4 |]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/597.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/597.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:11:00]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ [quote=WannaBe]I believe it has to do with a manual tic tac toe screen as opposed to GUI.  <br /> <br /> 01234<br />  -----<br /> 0 |<br /> 1 |<br /> 2 |<br /> 3 |<br /> 4 |[/quote]<br /> I understand that there's no GUI. I just pictured it like this:<br /> [code]<br /> ---<br /> ---<br /> ---[/code]<br /> [code]<br /> -X-<br /> OOX<br /> -X-[/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/598.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/598.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:13:58]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Would you know how to convert my public void play() method into actual java code?<br /> <br /> [code]public void play()<br />      {<br />          do<br />          {<br />              //show board<br />              //get valid move<br />              //update board<br />              //determine winner if possible<br />          }while((no one has won)&&(moves &lt; 9));    <br />      }[/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/600.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/600.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:22:48]]> GMT</pubDate>
				<author><![CDATA[ WannaBe]]></author>
			</item>
			<item>
				<title>Re:Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Again, try it first, [i]then[/i] ask for help. No one will not do it for you; we will only point you in the right direction.<br /> <br /> So try it, if you're having problems, tell us exactly what you're having trouble with, what you don't understand.<br /> <br /> Good luck!]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/602.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/602.page</link>
				<pubDate><![CDATA[Mon, 20 Feb 2006 15:30:08]]> GMT</pubDate>
				<author><![CDATA[ destin]]></author>
			</item>
			<item>
				<title>Re:Assistance with writing a tic tac toe program!</title>
				<description><![CDATA[ Found this for you, it might help. But i suggest you to try it on your own. Just take this a reference.<br /> <br /> <br /> [code]import java.awt.*;<br /> import java.awt.event.*;<br /> import javax.swing.*;<br /> public class TicTacToe {<br />     private int turn;<br />     private JFrame frame;<br />     private JButton[] button;<br />     private JLabel status;<br />     TicTacToe(){<br />         turn = 0;<br />         frame = new JFrame("Tic Tac Toe!");<br />         status = new JLabel("X's Turn");<br />         frame.setVisible(true);<br />         frame.setBounds(500,200, 350, 350);<br />         frame.setLayout(new GridLayout(4,3));<br />         frame.setResizable(false);<br />         button = new JButton[9];<br />         //Using for loop to add 9 buttons to the window<br />         for(int i=0;i&lt;9;i++)<br />         {<br />             button[i]= new JButton(i+1+"");<br />             frame.add(button[i]);<br />             button[i].addActionListener(new HandlerClass());<br />         }<br />         frame.add(status,BorderLayout.SOUTH);<br />         status.setPreferredSize(new Dimension(1,1));<br />  <br />     }<br />     public static void main(String[] args) {<br />         new TicTacToe();<br />     }<br />     class HandlerClass implements ActionListener{<br />  <br />         public void actionPerformed(ActionEvent ae){<br />  <br />        JButton temp[] = new JButton[9];<br />        temp[turn] = (JButton) ae.getSource();<br />        temp[turn].setEnabled(false);<br />        if(turn%2 == 0)<br />        {<br />         temp[turn].setText("X");<br />         temp[turn].setBackground(Color.CYAN);<br />         status.setText("O's Turn");<br />        }<br />        else{<br />             temp[turn].setText("O");<br />             temp[turn].setBackground(Color.YELLOW);<br />             status.setText("X's Turn");<br />        }<br />        turn++;<br />  //Horizontal check starts<br />        for(int i = 0; i&lt;7;i=i+3){<br />              if(button[i].getText().equals(button[i+1].getText()) && button[i].getText().equals(button[i+2].getText()) ){<br />                  button[i].setBackground(Color.GREEN);<br />                  button[i+1].setBackground(Color.GREEN);<br />                  button[i+2].setBackground(Color.GREEN);<br />                  status.setText("Game Over!");<br />                  if(button[i].getText().equals("X")){<br />                  JOptionPane.showMessageDialog(null, "Game Over!, X wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE); <br />                  }//End if<br />                  else{<br />                      JOptionPane.showMessageDialog(null, "Game Over!, 'O' wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE);<br />                  }//End else<br />        }//end first if<br />        }//End Horizontal check for<br />        //Horizontal Check ends<br />        //Vertical Check starts<br />        for(int i=0; i&lt;3;i++){<br />            if(button[i].getText().equals(button[i+3].getText()) && button[i].getText().equals(button[i+6].getText())){<br />                     button[i].setBackground(Color.GREEN);<br />                     button[i+3].setBackground(Color.GREEN);<br />                     button[i+6].setBackground(Color.GREEN);<br />                     status.setText("Game Over!");<br />                  if(button[i].getText().equals("X")){<br />                  JOptionPane.showMessageDialog(null, "Game Over!, X wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE); <br />                  }//End if<br />                  else{<br />                      JOptionPane.showMessageDialog(null, "Game Over!, 'O' wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE);<br />                  }//End else<br />  <br />            }//End if<br />  <br />        }//End vertical check for <br />  <br />        //Vertical Check ends<br />  <br />        //Diagonal Check starts <br />        if(button[0].getText().equals(button[4].getText()) && button[0].getText().equals(button[8].getText())){<br />                     button[0].setBackground(Color.GREEN);<br />                     button[4].setBackground(Color.GREEN);<br />                     button[8].setBackground(Color.GREEN);<br />                     status.setText("Game Over!");<br />                  if(button[8].getText().equals("X")){<br />                  JOptionPane.showMessageDialog(null, "Game Over!, X wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE); <br />                  }//End if<br />                  else{<br />                      JOptionPane.showMessageDialog(null, "Game Over!, 'O' wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE);<br />                  }//End else<br />        } //End if diagonal 1<br />  <br />        //Diagonal Check 2<br />        if(button[2].getText().equals(button[4].getText()) && button[2].getText().equals(button[6].getText())){<br />                     button[6].setBackground(Color.GREEN);<br />                     button[4].setBackground(Color.GREEN);<br />                     button[2].setBackground(Color.GREEN);<br />                     status.setText("Game Over!");<br />                  if(button[2].getText().equals("X")){<br />                  JOptionPane.showMessageDialog(null, "Game Over!, X wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE); <br />                  }//End if<br />                  else{<br />                      JOptionPane.showMessageDialog(null, "Game Over!, 'O' wins!", "Game Information", JOptionPane.INFORMATION_MESSAGE);<br />                  }//End else<br />        }//End if diagonal 2<br />  <br />        if(turn &gt; 8)<br />        {<br />            status.setText("Game Over!");<br />            JOptionPane.showMessageDialog(null, "Game Over! Its a Draw", "Game Information", JOptionPane.INFORMATION_MESSAGE);<br />        }//End if<br />      }<br />     }<br /> }[/code]<br /> <br /> Source: [url]http://www.mycoding.net/2011/06/tic-tac-toe-in-java/[/url]<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/159/4094.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/159/4094.page</link>
				<pubDate><![CDATA[Thu, 30 Jun 2011 11:44:37]]> GMT</pubDate>
				<author><![CDATA[ frozenmonkey]]></author>
			</item>
	</channel>
</rss>
