Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,424 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,352 people online right now. Registration is fast and FREE... Join Now!




Tic Tac Toe with JAVA

 
Reply to this topicStart new topic

Tic Tac Toe with JAVA, Hint(s) to complete my Tic Tac Toe game.

BradburyRob
14 Oct, 2008 - 11:29 PM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 5


My Contributions
java
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JTicTacToe extends JApplet implements ActionListener
{



JLabel someText = new JLabel(" Enter the number of expected guest for the event: ");



JTextField firstNum = new JTextField(15);

JLabel test_two = new JLabel("");

Container test = getContentPane();

String letter4User = "O";

String letterForPC = "X";



String[] dummyInput = {" ", " ", " ", " ", " ", " ", " ", " ", " "};

int [] verify = { 0, 1, 2, 3, 4, 5, 6, 7, 8};

JButton[] TicTac = new JButton[dummyInput.length];

int random = ((int) (Math.random() * 100) % 9 + 1);

int count = 0;

int y;






Font convertion = new Font ("Bookman Old Style", Font.ITALIC, 13);




public void init()

{



test.setLayout(new FlowLayout());


firstNum.addActionListener(this);


for(int y = 0; y < dummyInput.length; y++)

{
TicTac[y] = new JButton(dummyInput[y]);

test.add(TicTac[y]);

TicTac[y].addActionListener(this);

}





}

public void actionPerformed(ActionEvent r)



{


Object source = r.getSource();

y = verify[y];

if(source == TicTac[0])
TicTac[0].setText(letter4User);

else

if(source == TicTac[1])
TicTac[1].setText(letter4User);

else

if(source == TicTac[2])
TicTac[2].setText(letter4User);

else

if(source == TicTac[3])
TicTac[3].setText(letter4User);

else

if(source == TicTac[4])
TicTac[4].setText(letter4User);

else

if(source == TicTac[5])
TicTac[5].setText(letter4User);

else

if(source == TicTac[6])
TicTac[6].setText(letter4User);

else

if(source == TicTac[7])
TicTac[7].setText(letter4User);

else

if(source == TicTac[8])
TicTac[8].setText(letter4User);

else


if(random == 1 )
TicTac[0].setText(letterForPC);






{



}


}






}





** Edit ** code.gif Fixed the ridiculously large font size
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Tic Tac Toe With JAVA
14 Oct, 2008 - 11:33 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,462



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
...ok so you've got about 2 pages of Java code there.

Do you have a question or you just want to post some Java code? Sorry, my crystal ball is in the shop today.
User is online!Profile CardPM
+Quote Post

BradburyRob
RE: Tic Tac Toe With JAVA
14 Oct, 2008 - 11:38 PM
Post #3

New D.I.C Head
*

Joined: 14 Oct, 2008
Posts: 5


My Contributions
//I am trying to implement random numbers in this game but I am pretty brain dead as to how to do that. I was able to implement random numbers on a rock paper scissors game. I started with a 2dArray approach to create a 3 X 3 layout on the applet. Now I just changed the size of the applet so the single D array can fit nicely.


//Right now I need to have the PC make a move on the game, then follow that move with a human user then the PC again and so on, until either one has won or 9 moves have been made on the board.

//How do I make the PC make a move? Thank you,
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:23PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month