Geoff Fink
September 22nd, 2000, 06:22 PM
Help!
I am a VERY beginner programmer and I'm trying to make a Tic Tac Toe Game.
For the game i want the computer to decide it's move based on a external file which will show all the different games it played,
and in what order they played. It will then check if it won or lost by moving to a certain square if it lost pick a dif. one. If it
won pick the same and it hasn't dont his combo yet pick the first open square. That way after a while it will be impossible for
the player to win! But i can't figure out how to open a file. Can any one show me a basic way to open a file and assign the text to
varaibles.
Here what I have so far(nothing with opening a file though):
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class XO extends Applet implements Runnable
{
int Move = 0,Height = 0, Mark11 = 0,Mark12= 0, Mark13 = 0, Mark21 = 0, Mark22=0, Mark23= 0, Mark31=0,Mark32=0,Mark33=0;
Image XO;
Image X;
Image O;
Thread t;
public void init()
{
XO = getImage(getCodeBase(),"XO.jpg");
X = getImage(getCodeBase(),"X.jpg");
O = getImage(getCodeBase(),"O.jpg");
t=new Thread(this);
t.start();
}
public static File open( String path )
{
return true;
}
public void run()
{
while (true)
{
}
}
public void paint(Graphics g)
{
g.drawImage(XO,1,1,this);
if (Mark11==11)
g.drawImage(X,20,20,this);
if (Mark12==12)
g.drawImage(X,95,20,this);
if (Mark13==13)
g.drawImage(X,170,20,this);
if (Mark21==21)
g.drawImage(X,20,100,this);
if (Mark22==22)
g.drawImage(X,95,100,this);
if (Mark23==23)
g.drawImage(X,170,100,this);
if (Mark31==31)
g.drawImage(X,20,180,this);
if (Mark32==32)
g.drawImage(X,95,180,this);
if (Mark33==33)
g.drawImage(X,170,180,this);
//O
//Win!
if (Mark11==11)
if (Mark12==12)
if (Mark13==13)
g.drawString("You Win!", 85, 260);
if (Mark21==21)
if (Mark22==22)
if (Mark23==23)
g.drawString("You Win!", 85, 260);
if (Mark31==31)
if (Mark32==32)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark11==11)
if (Mark21==21)
if (Mark31==31)
g.drawString("You Win!", 85, 260);
if (Mark12==12)
if (Mark22==22)
if (Mark32==32)
g.drawString("You Win!", 85, 260);
if (Mark13==13)
if (Mark23==23)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark11==11)
if (Mark22==22)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark13==13)
if (Mark22==22)
if (Mark31==31)
g.drawString("You Win!", 85, 260);
}
public boolean mouseUp(Event e, int MouseY, int MouseX)
{
Move++;
// [Height, Width]
// [1,1] [1,2] [1,3]
// [2,1] [2,2] [2,3]
// [3,1] [3,2] [3,3]
//Height 1
if (MouseX<80)
Height = 1;
//Height 2
if (MouseX<160)
if (MouseX>80)
Height = 2;
//Height 3
if (MouseX<240)
if (MouseX>160)
Height = 3;
//Height 1, Width 1
if (Height ==1)
if (MouseY<75)
Mark11 = 11;
//Height 1, Width 2
if (Height ==1)
if (MouseY<150)
if (MouseY>75)
Mark12 = 12;
//Height 1, Width 3
if (Height == 1)
if (MouseY<225)
if (MouseY>150)
Mark13 = 13;
//Height 2, Width 1
if (Height == 2)
if (MouseY<75)
Mark21 = 21;
//Height 2, 2
if (Height == 2)
if (MouseY<150)
if (MouseY>75)
Mark22 = 22;
//Height 2,3
if (Height == 2)
if (MouseY<225)
if (MouseY>150)
Mark23 = 23;
//Height 3,1
if (Height == 3)
if (MouseY<75)
Mark31 = 31;
//Height 3,2
if (Height == 3)
if (MouseY<150)
if (MouseY>75)
Mark32 = 32;
//Height 3,3
if (Height == 3)
if (MouseY<225)
if (MouseY>150)
Mark33 = 33;
repaint();
return true;
}
}
Thanks!
I am a VERY beginner programmer and I'm trying to make a Tic Tac Toe Game.
For the game i want the computer to decide it's move based on a external file which will show all the different games it played,
and in what order they played. It will then check if it won or lost by moving to a certain square if it lost pick a dif. one. If it
won pick the same and it hasn't dont his combo yet pick the first open square. That way after a while it will be impossible for
the player to win! But i can't figure out how to open a file. Can any one show me a basic way to open a file and assign the text to
varaibles.
Here what I have so far(nothing with opening a file though):
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class XO extends Applet implements Runnable
{
int Move = 0,Height = 0, Mark11 = 0,Mark12= 0, Mark13 = 0, Mark21 = 0, Mark22=0, Mark23= 0, Mark31=0,Mark32=0,Mark33=0;
Image XO;
Image X;
Image O;
Thread t;
public void init()
{
XO = getImage(getCodeBase(),"XO.jpg");
X = getImage(getCodeBase(),"X.jpg");
O = getImage(getCodeBase(),"O.jpg");
t=new Thread(this);
t.start();
}
public static File open( String path )
{
return true;
}
public void run()
{
while (true)
{
}
}
public void paint(Graphics g)
{
g.drawImage(XO,1,1,this);
if (Mark11==11)
g.drawImage(X,20,20,this);
if (Mark12==12)
g.drawImage(X,95,20,this);
if (Mark13==13)
g.drawImage(X,170,20,this);
if (Mark21==21)
g.drawImage(X,20,100,this);
if (Mark22==22)
g.drawImage(X,95,100,this);
if (Mark23==23)
g.drawImage(X,170,100,this);
if (Mark31==31)
g.drawImage(X,20,180,this);
if (Mark32==32)
g.drawImage(X,95,180,this);
if (Mark33==33)
g.drawImage(X,170,180,this);
//O
//Win!
if (Mark11==11)
if (Mark12==12)
if (Mark13==13)
g.drawString("You Win!", 85, 260);
if (Mark21==21)
if (Mark22==22)
if (Mark23==23)
g.drawString("You Win!", 85, 260);
if (Mark31==31)
if (Mark32==32)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark11==11)
if (Mark21==21)
if (Mark31==31)
g.drawString("You Win!", 85, 260);
if (Mark12==12)
if (Mark22==22)
if (Mark32==32)
g.drawString("You Win!", 85, 260);
if (Mark13==13)
if (Mark23==23)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark11==11)
if (Mark22==22)
if (Mark33==33)
g.drawString("You Win!", 85, 260);
if (Mark13==13)
if (Mark22==22)
if (Mark31==31)
g.drawString("You Win!", 85, 260);
}
public boolean mouseUp(Event e, int MouseY, int MouseX)
{
Move++;
// [Height, Width]
// [1,1] [1,2] [1,3]
// [2,1] [2,2] [2,3]
// [3,1] [3,2] [3,3]
//Height 1
if (MouseX<80)
Height = 1;
//Height 2
if (MouseX<160)
if (MouseX>80)
Height = 2;
//Height 3
if (MouseX<240)
if (MouseX>160)
Height = 3;
//Height 1, Width 1
if (Height ==1)
if (MouseY<75)
Mark11 = 11;
//Height 1, Width 2
if (Height ==1)
if (MouseY<150)
if (MouseY>75)
Mark12 = 12;
//Height 1, Width 3
if (Height == 1)
if (MouseY<225)
if (MouseY>150)
Mark13 = 13;
//Height 2, Width 1
if (Height == 2)
if (MouseY<75)
Mark21 = 21;
//Height 2, 2
if (Height == 2)
if (MouseY<150)
if (MouseY>75)
Mark22 = 22;
//Height 2,3
if (Height == 2)
if (MouseY<225)
if (MouseY>150)
Mark23 = 23;
//Height 3,1
if (Height == 3)
if (MouseY<75)
Mark31 = 31;
//Height 3,2
if (Height == 3)
if (MouseY<150)
if (MouseY>75)
Mark32 = 32;
//Height 3,3
if (Height == 3)
if (MouseY<225)
if (MouseY>150)
Mark33 = 33;
repaint();
return true;
}
}
Thanks!