U E D R , A S I H C RSS

Tic Tac Toe/유주영

No older revisions available

No older revisions available



~cpp 

	import javax.swing.*;
	import java.awt.Graphics;
	import java.awt.event.MouseAdapter;
	import java.awt.event.MouseEvent;
	
	
	public class WoWJAVA extends JFrame{
		int realx;
		int realy;
		int x;
		int y;
		int count=0; // 이쪽은 계속 갱신되는 것은 아닌듯.
		int [][]ticbox = new int[3][3];

	public WoWJAVA()
	{
		addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				
				x = e.getX();
				y = e.getY();
				
				for(int i=1;i<4;i++)
				{
					if(x>(i*100) && x<((i+1)*100))
					{
					for(int j=1;j<4;j++)
					
					{
						if(y>(j*100) && y<((j+1)*100))
						{
							realx =  (i*100)+20;
							realy =  (j*100)+20;
							if(count%2==0)
								ticbox[i-1][j-1]=2;
							else
								ticbox[i-1][j-1]=3;
							
							}
						}
					}
				}
				count++; // 순서가 매우중요하다.
				

				System.out.println("x 좌표 : " + x);
				System.out.println("y 좌표 : " + y);
				repaint();
			}
		});
	}
	public static void main(String argv[]){
		WoWJAVA helloworld = new WoWJAVA();
		 helloworld.setBounds(300,300,500,550);
		 helloworld.show();
	}
     public void paint(Graphics g)
     {
     	
     	g.drawRect(100,100,300,300);
     	g.drawLine(100,200,400,200);
     	g.drawLine(100,300,400,300);
     	g.drawLine(200,100,200,400);
     	g.drawLine(300,100,300,400);
     	//g.drawString("X가 이겼습니다!",100,450);
     	
     	if((count%2) == 0  && count!=0)
     	g.drawOval(realx,realy,60,60);
     	else if(count!=0)
     	{g.drawLine(realx,realy,realx+60,realy+60);
        g.drawLine(realx,realy+60,realx+60,realy);
     	}
     	
     	for(int k=0;k<3;k++)
     	{
     		if(ticbox[k][0] == 2 && ticbox[k][1]==2 && ticbox[k][2] == 2 && count!=0)
     			
     				g.drawString("X가 이겼습니다!",100,450);
     		else if(ticbox[k][0] == 3 && ticbox[k][1]==3 && ticbox[k][2] == 3 && count!=0)
     				g.drawString("O가 이겼습니다!",300,450);
   	
     	}
     	
     	for(int l=0;l<3;l++)
     	{
     		if(ticbox[0][l] == 2 && ticbox[1][l]==2 && ticbox[2][l] == 2 && count!=0)
       				g.drawString("X가 이겼습니다!",100,450);
     		else if(ticbox[0][l] == 3 && ticbox[1][l]==3 && ticbox[2][l] == 3 && count!=0)
     				g.drawString("O가 이겼습니다!",300,450);
     		
     	}
     	
     	if(ticbox[0][0] == 2 && ticbox[1][1]==2 && ticbox[2][2] == 2 && count!=0)
     		g.drawString("X가 이겼습니다!",100,450);
        if(ticbox[0][0] == 3 && ticbox[1][1]==3 && ticbox[2][2] == 3 && count!=0)
        	g.drawString("O가 이겼습니다!",300,450);
        if(ticbox[0][2] == 2 && ticbox[1][1]==2 && ticbox[2][0] == 2 && count!=0)
        	g.drawString("X가 이겼습니다!",100,450);
        if(ticbox[0][2] == 3 && ticbox[1][1]==3 && ticbox[2][0] == 3 && count!=0)
        	g.drawString("O가 이겼습니다!",300,450);
        
	}
}

세부적인건 GG -_-

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