U E D R , A S I H C RSS

Tic Tac Toe/박진영,곽세환

No older revisions available

No older revisions available



~cpp 
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;

public class FirstJava extends JFrame {
	int array[][] = new int[3][3];
	int a = 0;
	boolean overFlag = false;
	public FirstJava() {
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				array[i][j] = -1;

		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				if (overFlag == true)
					return;
				int x = e.getX();
				int y = e.getY();

				if (x > 0 && x < 100 && y > 0 && y < 100 && array[0][0] == -1)
					array[0][0] = ++a;
				if (x > 100
					&& x < 200
					&& y > 0
					&& y < 100
					&& array[1][0] == -1)
					array[1][0] = ++a;
				if (x > 200
					&& x < 300
					&& y > 0
					&& y < 100
					&& array[2][0] == -1)
					array[2][0] = ++a;
				if (x > 0
					&& x < 100
					&& y > 100
					&& y < 200
					&& array[0][1] == -1)
					array[0][1] = ++a;
				if (x > 100
					&& x < 200
					&& y > 100
					&& y < 200
					&& array[1][1] == -1)
					array[1][1] = ++a;
				if (x > 200
					&& x < 300
					&& y > 100
					&& y < 200
					&& array[2][1] == -1)
					array[2][1] = ++a;
				if (x > 0
					&& x < 100
					&& y > 200
					&& y < 300
					&& array[0][2] == -1)
					array[0][2] = ++a;
				if (x > 100
					&& x < 200
					&& y > 200
					&& y < 300
					&& array[1][2] == -1)
					array[1][2] = ++a;
				if (x > 200
					&& x < 300
					&& y > 200
					&& y < 300
					&& array[2][2] == -1)
					array[2][2] = ++a;

				if (array[0][0] % 2 == 0
					&& array[0][1] % 2 == 0
					&& array[0][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[1][0] % 2 == 0
					&& array[1][1] % 2 == 0
					&& array[1][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[2][0] % 2 == 0
					&& array[2][1] % 2 == 0
					&& array[2][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[0][0] % 2 == 0
					&& array[1][0] % 2 == 0
					&& array[2][0] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[0][1] % 2 == 0
					&& array[1][1] % 2 == 0
					&& array[2][1] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[0][2] % 2 == 0
					&& array[1][2] % 2 == 0
					&& array[2][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[0][0] % 2 == 0
					&& array[1][1] % 2 == 0
					&& array[2][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}
				if (array[2][0] % 2 == 0
					&& array[1][1] % 2 == 0
					&& array[0][2] % 2 == 0) {
					System.out.println("play 2 WIN !!! ");
					overFlag = true;
				}

				if (array[0][0] % 2 == 1
					&& array[0][1] % 2 == 1
					&& array[0][2] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[1][0] % 2 == 1
					&& array[1][1] % 2 == 1
					&& array[1][2] % 2 == 1) {

					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[2][0] % 2 == 1
					&& array[2][1] % 2 == 1
					&& array[2][2] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[0][0] % 2 == 1
					&& array[1][0] % 2 == 1
					&& array[2][0] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[0][1] % 2 == 1
					&& array[1][1] % 2 == 1
					&& array[2][1] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[0][2] % 2 == 1
					&& array[1][2] % 2 == 1
					&& array[2][2] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[0][0] % 2 == 1
					&& array[1][1] % 2 == 1
					&& array[2][2] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}
				if (array[2][0] % 2 == 1
					&& array[1][1] % 2 == 1
					&& array[0][2] % 2 == 1) {
					System.out.println("play 1 WIN !!! ");
					overFlag = true;
				}

				if (a == 9)
					System.out.println("무승부");

				repaint();

			}
		});
	}

	public static void main(String args[]) {
		FirstJava helloworld = new FirstJava();
		helloworld.setBounds(200, 200, 310, 330);
		helloworld.show();
	}

	public void paint(Graphics g) {
		g = getContentPane().getGraphics();
		g.drawLine(0, 100, 300, 100);
		g.drawLine(0, 200, 300, 200);
		g.drawLine(100, 0, 100, 300);
		g.drawLine(200, 0, 200, 300);

		if (array[0][0] % 2 == 1)
			g.drawOval(10, 10, 80, 80);
		if (array[1][0] % 2 == 1)
			g.drawOval(110, 10, 80, 80);
		if (array[2][0] % 2 == 1)
			g.drawOval(210, 10, 80, 80);
		if (array[0][1] % 2 == 1)
			g.drawOval(10, 110, 80, 80);
		if (array[1][1] % 2 == 1)
			g.drawOval(110, 110, 80, 80);
		if (array[2][1] % 2 == 1)
			g.drawOval(210, 110, 80, 80);
		if (array[0][2] % 2 == 1)
			g.drawOval(10, 210, 80, 80);
		if (array[1][2] % 2 == 1)
			g.drawOval(110, 210, 80, 80);
		if (array[2][2] % 2 == 1)
			g.drawOval(210, 210, 80, 80);





		if (array[0][0] % 2 == 0)
			g.fillOval(10, 10, 80, 80);
		if (array[1][0] % 2 == 0)
			g.fillOval(110, 10, 80, 80);
		if (array[2][0] % 2 == 0)
			g.fillOval(210, 10, 80, 80);
		if (array[0][1] % 2 == 0)
			g.fillOval(10, 110, 80, 80);
		if (array[1][1] % 2 == 0)
			g.fillOval(110, 110, 80, 80);
		if (array[2][1] % 2 == 0)
			g.fillOval(210, 110, 80, 80);
		if (array[0][2] % 2 == 0)
			g.fillOval(10, 210, 80, 80);
		if (array[1][2] % 2 == 0)
			g.fillOval(110, 210, 80, 80);
		if (array[2][2] % 2 == 0)
			g.fillOval(210, 210, 80, 80);
	}
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:14
Processing time 0.0285 sec