tic tac toe (승리조건은 아직...)

~cpp 
import java.awt.Graphics;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.*;

public class FirstJava extends JFrame {
	int array [][] = new int [3][3];
	int x,y;
	int i;
	int count;
	boolean isStarted = false;

	public FirstJava() {

		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				x = e.getX();
				y = e.getY();
				
				System.out.println("x 좌표 : " + x); 
				System.out.println("y 좌표 : " + y); 


				if (x >= 0 && x <= 200 & y >= 0 && y <= 200 && array[0][0] ==0){
					if(count%2 == 0)
						array[0][0]=1;
					else
						array[0][0]=2;
					count++;
	
				}
				else if(x >= 200 && x <= 400 & y >= 0 && y <= 200&& array[0][1] ==0){
					if(count%2 == 0)
						array[0][1]=1;
					else
						array[0][1]=2;
					count++;
	
				}
				else if(x >= 400 && x <= 600 & y >= 0 && y <= 200&& array[0][2] ==0){
					if(count%2 == 0)
						array[0][2]=1;
					else
						array[0][2]=2;
					count++;
					
	
				}
				else if(x >= 0 && x <= 200 & y >= 200 && y <= 400&& array[1][0] ==0){
					if(count%2 == 0)
						array[1][0]=1;
					else
						array[1][0]=2;
					count++;
		
				}
				else if(x >= 200 && x <= 400 & y >= 200 && y <= 400&& array[1][1] ==0){
					if(count%2 == 0)
						array[1][1]=1;
					else
						array[1][1]=2;
					count++;
	
				}
				else if(x >= 400 && x <= 600 & y >= 200 && y <= 400&& array[1][2] ==0){
					if(count%2 == 0)
						array[1][2]=1;
					else
						array[1][2]=2;
					count++;
		
				}
				else if(x >= 0 && x <= 200 & y >= 400 && y <= 600&& array[2][0] ==0){
					if(count%2 == 0)
						array[2][0]=1;
					else
						array[2][0]=2;
					count++;
				}
				else if(x >= 200 && x <= 400 & y >= 400 && y <= 600&& array[2][1] ==0){
					if(count%2 == 0)
						array[2][1]=1;
					else
						array[2][1]=2;
					count++;
	
				}
				else if(x >= 400 && x <= 600 & y >= 400 && y <= 600&& array[2][2] ==0){
					if(count%2 == 0)
						array[2][2]=1;
					else
						array[2][2]=2;
					count++;
	
				}
				isStarted = true;
				
				
				repaint();
			

			}
		});
	}
	public void paint(Graphics g) {
		g.drawLine(200,0,200,600);
		g.drawLine(400,0,400,600);
		g.drawLine(0,200,600,200);
		g.drawLine(0,400,600,400);
		if( isStarted ){
			for (i=0;i<3;i++)
			{
				for (int j=0;j<3;j++)
				{
					if (array[i][j] == 1)
						g.fillOval(50+200*j,50+200*i,100,100);
					else if (array[i][j] == 2)
						g.drawOval(50+200*j,50+200*i,100,100);
				}

			}
			}
			}
	public static void main(String[] args) {
		FirstJava helloworld = new FirstJava();
		helloworld.setBounds(100, 100, 600, 600);
		helloworld.show();
	}
}
Retrieved from http://wiki.zeropage.org/wiki.php/TicTacToe/조동영
last modified 2021-02-07 05:28:14