שמע אחי הדלקת אותי עם הרעיוןשל איקס עיגול עם גרפיקה במיוחד שאני עכשיו מנסה לחזור לתחום הזה ולהתעסק עם גאווה שוב .
התחלתי לכתוב קוד בנתיים רק בנתי את התבנית ואת ההגדרות שאם לוחצים זה מצייר איק סאו עיגול תלוי תור של מי זה . הנה הקוד :
קוד:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class X_And_O implements ActionListener
{
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}, //vertical wins
{0, 4, 8}, {2, 4, 6} //diagonal wins
};
private JFrame windows = new JFrame ("Tic Tac Tow");
private JButton button[] = new JButton[9];
private int count=0;
private String letter="";
private boolean win=false;
public TicTacToe(){
windows.setSize(300,300);
windows.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
windows.setLayout(new GridLayout(3,3));
for (int i=0;i<=8;i++){
button[i]=new JButton();
windows.add(button[i]);
button[i].addActionListener(this);
}
windows.setVisible(true);
}
public void actionPerformed(ActionEvent a){
count++;
if(count%2==0)
letter="O";
else
letter="X";
JButton pressedButton = (JButton)a.getSource();
pressedButton.setText(letter);
pressedButton.setEnabled(false);
}
public static void main(String[] args){
new X_And_O();
}
}
אמשח אם יוכלו לעזור לנו ( או יותר נכון לי איך אני בודק מי ניצח ? ומיישם את זה ? ף ושנית איך אני יכול לשחק נגד המחשב כלמור להתעסק עם RANDOM ) תודה