Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need help with tic tac toe game

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with tic tac toe game

    Hi everybody!

    The reason from this post is to get some help with my program, which is a tic tac toe game. The objective of the program is to make a game between the computer and the human player, in which the player always lose.
    The problem is that the computer is marking the X two times in the computer's turn I don't know why it happened.
    Could you please help me?

    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.lang.Math.*;
     
    public class gato2 extends Applet implements ActionListener{
    	private Button un, deux, trois, quatre , cinq, six, sept, huit, neuf,one,two, three, four, five,six6,seven,eight,nine, AC,start;
    	private int x,y,z, uno = 0, dos = 0, tres = 0, cuatro = 0, cinco =0, seis =0, siete =0, ocho=0, nueve=0,k,a2,a3,a4,a5,a6,a7,a8,a9,ac=0,inic=0, um=0, dois=0,três=0, quatro=0, cinco5=0, seis6=0, sete=0, oito=0, nove=0, c0,c2,c3,c4,c5,c6,c7,c8,c9;
    	public Panel a1,b1,c1,start1;
     
    	public void init (){
     
    	setLayout(new FlowLayout());
    	a1 = new Panel (new GridLayout (3,3));
    	b1 = new Panel (new GridLayout (1,1));
    	c1 = new Panel (new GridLayout (3,3));
    	start1= new Panel (new GridLayout(1,1));
     
    	start= new Button("Inicio");start.setBackground(Color.green);start.setForeground(Color.WHITE);
    	un= new Button("1");un.setBackground(Color.BLACK);un.setForeground(Color.WHITE);
    	deux = new Button("2");deux.setBackground(Color.BLACK);deux.setForeground(Color.WHITE);
    	trois = new Button("3");trois.setBackground(Color.BLACK);trois.setForeground(Color.WHITE);
    	quatre = new Button("4");quatre.setBackground(Color.BLACK);quatre.setForeground(Color.WHITE);
    	cinq = new Button("5");cinq.setBackground(Color.BLACK);cinq.setForeground(Color.WHITE);
    	six = new Button("6");six.setBackground(Color.BLACK);six.setForeground(Color.WHITE);
    	sept = new Button ("7");sept.setBackground(Color.BLACK);sept.setForeground(Color.WHITE);
    	huit = new Button ("8");huit.setBackground(Color.BLACK);huit.setForeground(Color.WHITE);
    	neuf = new Button ("9");neuf.setBackground(Color.BLACK);neuf.setForeground(Color.WHITE);
    	one = new Button ("1");one.setBackground(Color.blue);one.setForeground(Color.WHITE);
    	two = new Button ("2");two.setBackground(Color.blue);two.setForeground(Color.WHITE);
    	three = new Button ("3");three.setBackground(Color.blue);three.setForeground(Color.WHITE);
    	four = new Button ("4");four.setBackground(Color.blue);four.setForeground(Color.WHITE);
    	five = new Button ("5");five.setBackground(Color.blue);five.setForeground(Color.WHITE);
    	six6 = new Button ("6");six6.setBackground(Color.blue);six6.setForeground(Color.WHITE);
    	seven = new Button ("7");seven.setBackground(Color.blue);seven.setForeground(Color.WHITE);
    	eight = new Button ("8");eight.setBackground(Color.blue);eight.setForeground(Color.WHITE);
    	nine = new Button ("9");nine.setBackground(Color.blue);nine.setForeground(Color.WHITE);
    	AC = new Button ("AC");AC.setForeground(Color.black);
     
    	add(start1);
    	add(a1);
    	add(b1);
    	add(c1);
    	start1.add(start);
    	a1.add(un);
    	a1.add(deux);
    	a1.add(trois);
    	a1.add(quatre);
    	a1.add(cinq);
    	a1.add(six);
    	a1.add(sept);
    	a1.add(huit);
    	a1.add(neuf);
    	b1.add(AC);
    	c1.add(one);
    	c1.add(two);
    	c1.add(three);
    	c1.add(four);
    	c1.add(five);
    	c1.add(six6);
    	c1.add(seven);
    	c1.add(eight);
    	c1.add(nine);
     
    	start.addActionListener(this);
    	un.addActionListener(this);
    	deux.addActionListener(this);
    	trois.addActionListener(this);
    	quatre.addActionListener(this);
    	cinq.addActionListener(this);
    	six.addActionListener(this);
    	sept.addActionListener(this);
    	huit.addActionListener(this);
    	neuf.addActionListener(this);
    	AC.addActionListener(this);
    	one.addActionListener(this);
    	two.addActionListener(this);
    	three.addActionListener(this);
    	four.addActionListener(this);
    	five.addActionListener(this);
    	six6.addActionListener(this);
    	seven.addActionListener(this);
    	eight.addActionListener(this);
    	nine.addActionListener(this);
     
    	}
     
    	public void actionPerformed(ActionEvent e) {
    				Object fuente = e.getSource();
    k=0;
     
     
    							if(fuente==start){
    							inic=1;
    							}
     
    							if(fuente== deux){
    							dos=2;
    							}
     
    							if(fuente== trois){
    							tres=3;
     
    						    }
     
    							if(fuente== quatre){
    							cuatro=4;
     
    							}
     
    							if(fuente== cinq){
    							cinco=5;
     
    							}
     
    							if(fuente== six){
    							seis=6;
     
    							}
     
    							if(fuente== sept){
    							siete=7;
     
    							}
     
    							if(fuente== huit){
    							ocho=8;
     
    							}
     
    							if(fuente== neuf){
    							nueve=9;
     
    							}
     
    							if(fuente== one){
    							um=1;
    							}
     
    							if(fuente== two){
    							dois=2;
    							}
     
    							if(fuente== three){
    							três=3;
    							}
     
    							if(fuente== four){
    							quatro=4;
    							}
     
    							if(fuente== five){
    							cinco5=5;
    							}
     
    							if(fuente== six6){
    							seis6=6;
    							}
     
    							if(fuente== seven){
    							sete=7;
    							}
     
    							if(fuente== eight){
    							oito=8;
    							}
     
    							if(fuente== deux){
    							nove=9;
    							}
     
    							if(fuente== AC){
    								uno = 0;
    								dos = 0;
    								tres = 0;
    								cuatro = 0;
    								cinco =0;
    								seis =0;
    								siete =0;
    								ocho=0;
    								nueve=0;
    								um=0;
    								dois=0;
    								três=0;
    								quatro=0;
    								cinco5=0;
    								seis6=0;
    								sete=0;
    								oito=0;
    								nove=0;
     
    								ac=1;
    								}
     
    repaint();
    						}
     
     
    	public void paint(Graphics g) {
     
     
     
     
    /*botón para borrar*/
     
    	 							if (ac==1){
    									g.setColor(Color.white);
    									g.fillRect(0,0,900,900);
    									ac=0;
    								}
    /*botones para el jugador*/
     
    								if(dos==2){
    								g.drawOval(275,75,50,50);
    								a2=2;
    								}
     
    								if(tres==3){
    								g.drawOval(360,75,49,49);
    								a3=3;
    								}
     
    								if(cuatro==4){
    								g.drawOval(185,160,49,49);
    								a4=4;
    								}
     
    								if(cinco==5){
    								g.drawOval(275,160,50,50);
    								a5=5;
    								}
     
    								if(seis==6){
    								g.drawOval(360,160,49,49);
    								a6=6;
    								}
     
    								if(siete==7){
    								g.drawOval(185,250,49,49);
    								a7=7;
    								}
     
    								if(ocho==8){
    								g.drawOval(275,250,49,49);
    								a8=8;
    								}
     
    								if(nueve==9){
    								g.drawOval(360,250,49,49);
    								a9=9;
    							    }
     
    /*botones computadora*/
     
    							    if(um==1){
    								g.drawLine(175,75,250,135);
    								g.drawLine(250,75,175,135);
    								c0=1;
    								}
     
    								if(dois==2){
    								g.drawLine(250,75,350,135);
    								g.drawLine(350,75,250,135);
    								c2=2;
    							    }
     
    								if(três==3){
    								g.drawLine(350,75,425,135);
    								g.drawLine(425,75,350,135);
    								c3=3;
    							    }
     
    							    if(quatro==4){
    								g.drawLine(175,135,250,235);
    								g.drawLine(250,135,175,235);
    								c4=4;
    							    }
     
    							    if(cinco5==5){
    								g.drawLine(250,135,350,235);
    								g.drawLine(350,135,250,235);
    								c5=5;
    							    }
     
    							    if(seis6==6){
    								g.drawLine(350,135,425,235);
    								g.drawLine(425,135,350,235);
    								c6=6;
    							    }
     
    								if(sete==7){
    								g.drawLine(175,235,250,300);
    								g.drawLine(250,235,175,300);
    								c7=7;
    							    }
     
    							    if(oito==8){
    								g.drawLine(250,235,350,300);
    								g.drawLine(350,235,250,300);
    								c8=8;
    							    }
     
    							    if(nove==9){
    								g.drawLine(350,235,425,300);
    								g.drawLine(425,235,350,300);
    								c9=9;
    							    }
     
    /*líneas del gane*/
     
    /*diagonales*/
    								if((um==1)&&(cinco5==5)&&(nove==9)){
    									g.drawLine(175,75,425,300);
    								}
     
    								if((três==3)&&(cinco5==5)&&(sete==7)){
    									g.drawLine(425,75,175,300);
    								}
     
    /*verticales*/
    								if((um==1)&&(quatro==4)&&(sete==7)){
    									g.drawLine(212,75,212,300);
    								}
     
    								if((três==3)&&(seis6==6)&&(nove==9)){
    									g.drawLine(387,75,387,300);
    								}
     
    /*horizontales*/
    								if((um==1)&&(dois==2)&&(três==3)){
    									g.drawLine(212,105,387,105);
    								}
     
     
    								if((sete==7)&&(oito==8)&&(nove==9)){
    									g.drawLine(175,267,425,267);
    								}
     
     
     
     
     
     
    							if(inic==1){
     
    /*inicio del juego*/
    								g.drawLine(250,75,250,300);
    								g.drawLine(350,75,350,300);
    								g.drawLine(175,135,425,135);
    								g.drawLine(175,235,425,235);
    /*primera jugada*/
    								um=1;
    								}
     
     
    										if (a2==2){
    											cinco5=5;
    												if (a3==3){
    													nueve=9;
    													System.out.println("PERDISTE");
    													}
    												if(a4==4){
    													nove=9;
     
    													g.drawLine(175,75,425,300);
    													System.out.println("PERDISTE");
    													}
    												if(a6==6){
     
    													nove=9;
     
    													g.drawLine(175,75,425,300);
    													System.out.println("PERDISTE");
    													}
    												if(a7==7){
     
    													nove=9;
     
    													g.drawLine(175,75,425,300);
    													System.out.println("PERDISTE");
    													}
     
    												if(a8==8){
     
    													nove=9;
     
    													g.drawLine(175,75,425,300);
    													System.out.println("PERDISTE");
    													}
     
    												if(a9==9){
     
    													sete=7;
     
     
    														if(a4==4){
     
    															três=3;
     
    															g.drawLine(425,75,175,300);
    															System.out.println("PERDISTE");
    													}
    														if(a3==3){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    													}
    														if(a6==6){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    													}
    														if(a8==8){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    													}
    													}
    													}
     
    												if (a3 == 3){
     
     
    													sete=7;
     
     
    														if (a2 ==2){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    																}
     
    														if (a5 ==5){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    																}
     
    														if (a6 ==6){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    																}
     
    														if (a8 ==8){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    																}
    														if (a9 ==9){
     
    															quatro=4;
     
    															g.drawLine(212,75,212,300);
    															System.out.println("PERDISTE");
    																}
     
    														if (a4 ==4){
     
    															nove=9;
     
     
     
    																if (a2 == 2){
     
    																	oito=8;
     
    																	g.drawLine(175,267,425,267);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a5 ==5){
     
    																	oito=8;
     
    																	g.drawLine(175,267,425,267);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a6==6){
     
    																	oito=8;
     
    																	g.drawLine(175,267,425,267);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a8 == 8){
     
    																	cinco5=5;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
    																	}
    																	}
     
    												if (a4 == 4){
     
    													cinco5=5;
     
    														if (a2 ==2){
     
    															nove=9;
     
    															g.drawLine(175,75,425,300);
    															System.out.println("PERDISTE");
    															}
    														if (a3 ==3){
     
    															nove=9;
     
    															g.drawLine(175,75,425,300);
    															System.out.println("PERDISTE");
    															}
    														if (a6 ==6){
     
    															nove=9;
     
    															g.drawLine(175,75,425,300);
    															System.out.println("PERDISTE");
    															}
    														if (a7 ==7){
     
    															nove=9;
     
    															g.drawLine(175,75,425,300);
    															System.out.println("PERDISTE");
    															}
    														if(a8==8){
     
    															nove=9;
     
    															g.drawLine(175,75,425,300);
    															System.out.println("PERDISTE");
    															}
     
    														if (a9==9){
     
    															três=3;
     
     
    																if(a6==6){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a7==7){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a8==8){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    																if (a2==2){
     
    																	sete=7;
     
    																	g.drawLine(425,75,175,300);
    																	System.out.println("PERDISTE");
    																	}
    																	}
    																	}
     
     
    												if (a5 == 5){
     
    													nove=9;
     
    															if (a2 == 2){
     
    															oito=8;
    															g.drawLine(250,300,350,235);
    																if (a3==3){
     
    																sete=7;
     
    																g.drawLine(175,267,425,267);
    																System.out.println("Perdiste :P");
    																}
    																if (a4==4){
     
    																sete=7;
     
    																g.drawLine(175,267,425,267);
    																System.out.println("Perdiste :P");
    																}
    																if (a6==6){
     
    																sete=7;
     
    																g.drawLine(175,267,425,267);
    																System.out.println("Perdiste :P");
    																}
     
    																if (a7==7){
     
    																três=3;
     
    																	if (a4 ==4){
     
    																	seis6=6;
     
    																	g.drawLine(387,75,387,300);
    																	System.out.println("Perdiste! :P");
    																	}
     
    																	if(a6 ==6){
     
    																	quatro=4;
     
    																	System.out.println ("Empate :S");
    																	}
    																	}
    																    }
     
    															if (a3 ==3){
     
    															sete=7;
     
     
    																if (a2 ==2){
     
    																quatro=4;
     
    																g.drawLine(212,75,212,300);
    																System.out.println("Perdiste!!!! :)");
    																}
     
    																if (a8==8){
     
    																quatro=4;
     
    																g.drawLine(212,75,212,300);
    																System.out.println("Perdiste!!!! :)");
    																}
     
    																if (a4==4){
     
    																oito=8;
    																g.drawLine(250,300,350,235);
    																g.drawLine(175,267,425,267);
    																System.out.println("Perdiste!!!! :)");
    																}
     
    																if(a6==6){
     
    																oito=8;
    																g.drawLine(250,300,350,235);
    																g.drawLine(175,267,425,267);
    																System.out.println("Perdiste!!!! :)");
    																}
    																}
     
     
    															if (a4==4){
     
    															seis6=6;
     
     
    																if(a2==2){
     
    																três=3;
     
    																g.drawLine(387,75,387,300);
    																System.out.println("Perdiste!!!! :)");
    																}
    																if(a7==7){
     
    																três=3;
     
    																g.drawLine(387,75,387,300);
    																System.out.println("Perdiste!!!! :)");
    																}
    																if(a8==8){
     
    																três=3;
     
    																g.drawLine(387,75,387,300);
    																System.out.println("Perdiste!!!! :)");
    																}
    																if (a3==3){
     
    																sete=7;
     
    																	if (a2==2){
     
    																	oito=8;
    																	g.drawLine(250,300,350,235);
    																	g.drawLine(175,267,425,267);
    																	System.out.println("Perdiste!!!! :)");
    																	}
    																	if (a8==8){
     
    																	dois=2;
     
    																	System.out.println("Empate :S");
    																	}
    																	}
    																	}
     
    															if (a6==6){
     
    																		quatro=4;
     
    																			if (a2==2){
     
    																			sete=7;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("Perdiste :)");
    																			}
    																			if (a3==3){
     
    																			sete=7;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("Perdiste :)");
    																			}
    																			if(a8==8){
     
    																			sete=7;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("Perdiste :)");
    																			}
     
    																			if (a7==7){
     
    																			três=3;
     
    																				if (a8==8){
     
    																				dois=2;
     
    																				g.drawLine(175,105,425,105);
    																				System.out.println("Perdiste :)");
    																				}
    																				if (a2==2){
     
    																				oito=8;
    																				g.drawLine(250,300,350,235);
    																				System.out.println("Empate :S");
    																				}
    																				}
    																				}
     
    																		if(a7 ==7){
     
    																		três=3;
     
    																			if (a2 ==2){
     
    																			seis6=6;
     
    																			g.drawLine(387,75,387,300);
    																			System.out.println("Perdiste :)");
    																			}
     
    																			if (a8==8){
     
    																			seis6=6;
     
    																			g.drawLine(387,75,387,300);
    																			System.out.println("Perdiste :)");
    																			}
     
    																			if (a4==4){
     
    																			dois=2;
     
    																			g.drawLine(175,105,425,105);
    																			System.out.println("Perdiste!!!! :)");
    																			}
     
    																			if(a6==6){
     
    																			dois=2;
     
    																			g.drawLine(175,105,425,105);
    																			System.out.println("Perdiste!!!! :)");
    																			}
    																			}
     
    																		if(a8==8){
     
    																		dois=2;
     
    																			if(a4==4){
     
    																			três=3;
     
    																			g.drawLine(175,105,425,105);
    																			System.out.println("Perdiste!!!! :)");
    																			}
    																			if (a6==6){
     
    																			três=3;
     
    																			g.drawLine(175,105,425,105);
    																			System.out.println("Perdiste!!!! :)");
    																			}
    																			if(a7==7){
     
    																			três=3;
     
    																			g.drawLine(175,105,425,105);
    																			System.out.println("Perdiste!!!! :)");
    																			}
     
    																			if (a3==3){
     
    																			sete=7;
     
    																				if (a6==6){
     
    																				quatro=4;
     
    																				g.drawLine(212,75,212,300);
    																				System.out.println("Perdiste!!!! :)");
    																				}
     
    																				if (a4==4){
     
    																				seis6=6;
     
    																				System.out.println("Empates, :S");
    																				}
    																				}
    																				}
    																				}
     
    												if (a6 == 6){
     
    														cinco5=5;
     
     
    															if (a2 == 2){
     
    															nove=9;
     
     
    															g.drawLine(175,75,425,300);
    															System.out.println("Perdiste!!");
    															}
    															if (a3==3){
     
    															nove=9;
     
     
    															g.drawLine(175,75,425,300);
    															System.out.println("Perdiste!!");
    															}
    															if (a4==4){
     
    															nove=9;
     
     
    															g.drawLine(175,75,425,300);
    															System.out.println("Perdiste!!");
    															}
    															if (a7==7){
     
    															nove=9;
     
     
    															g.drawLine(175,75,425,300);
    															System.out.println("Perdiste!!");
    															}
    															if (a8==8){
     
    															nove=9;
     
     
    															g.drawLine(175,75,425,300);
    															System.out.println("Perdiste!!");
    															}
     
    																if(a9==9){
     
    																três=3;
     
     
    																	if (a2==2){
     
    																	sete=7;
     
     
    																	g.drawLine(425,75,175,300);
    																	System.out.println("Perdiste!!! :D");
    																	}
    																	if (a4==4){
     
    																	dois=2;
     
     
    																	g.drawLine(212,105,387,105);
    																	System.out.println("Gané!!! Yei!!! :D");
    																	}
    																	if (a7==7){
     
    																	dois=2;
     
     
    																	g.drawLine(212,105,387,105);
    																	System.out.println("Gané!!! Yei!!! :D");
    																	}
    																	if(a8==8){
     
    																	dois=2;
     
     
    																	g.drawLine(212,105,387,105);
    																	System.out.println("Gané!!! Yei!!! :D");
    																	}
    																	}
    																	}
    												if (a7 == 7){
     
    														três=3;
     
     
    															if (a4 == 4){
     
    																dois=2;
     
    																g.drawLine(212,105,387,105);
    																System.out.println ("Gané!!! :D");
    																}
     
    															if(a5==5){
     
    																dois=2;
     
    																g.drawLine(212,105,387,105);
    																System.out.println ("Gané!!! :D");
    																}
     
    														if(a6==6){
     
    																dois=2;
     
    																g.drawLine(212,105,387,105);
    																System.out.println ("Gané!!! :D");
    																}
     
    														if(a8==8){
     
    																dois=2;
     
    																g.drawLine(212,105,387,105);
    																System.out.println ("Gané!!! :D");
    																}
     
    														if(a9==9){
     
    																dois=2;
     
    																g.drawLine(212,105,387,105);
    																System.out.println ("Gané!!! :D");
    																}
     
    														if (a2==2){
     
    																nove=9;
     
     
    																if (a4==4){
     
    																		seis6=6;
     
    																		g.drawLine(387,105,387,267);
    																		System.out.println("Perdiste!!! =)");
    																		}
     
    																if(a5==5){
     
    																		seis6=6;
     
    																		g.drawLine(387,105,387,267);
    																		System.out.println("Perdiste!!! =)");
    																		}
     
    																if(a8==8){
     
    																		seis6=6;
     
    																		g.drawLine(387,105,387,267);
    																		System.out.println("Perdiste!!! =)");
    																		}
     
    																if (a6==6){
     
    																		cinco5=5;
     
    																		g.drawLine(175,75,425,300);
    																		System.out.println("Perdiste!!! =)");
    																			}
    																			}
    																			}
     
    												if (a8 == 8){
     
    														cinco5=5;
     
     
    															if (a2 ==2){
     
    																	nove=9;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a3 ==3){
     
    																	nove=9;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a4 ==4){
     
    																	nove=9;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a6 ==6){
     
    																	nove=9;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a7 ==7){
     
    																	nove=9;
     
    																	g.drawLine(175,75,425,300);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a9 ==9){
     
    																	sete=7;
     
     
     
    																	if (a2 == 2){
     
    																			quatro=4;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a3 ==3){
     
    																			quatro=4;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a4 ==4){
     
    																			três=3;
     
    																			g.drawLine(425,75,175,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a6 == 6){
     
    																			três=3;
     
    																			g.drawLine(425,75,175,300);
    																			System.out.println("PERDISTE");
    																			}
    																			}
    																			}
     
    													if (a9 == 9){
     
    															três=3;
     
     
    															if (a4 ==4){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a5 ==5){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a6 ==6){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a7 ==7){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a8 ==8){
     
    																	dois=2;
     
    																	g.drawLine(175,105,425,105);
    																	System.out.println("PERDISTE");
    																	}
     
    															if (a2 ==2){
     
    																	sete=7;
     
     
     
    																	if (a5 == 5){
     
    																			quatro=4;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a6 ==6){
     
    																			oito=8;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a8 ==8){
     
    																			oito=8;
     
    																			g.drawLine(212,75,212,300);
    																			System.out.println("PERDISTE");
    																			}
     
    																	if (a4 == 4){
     
    																			cinco5=5;
     
    																			g.drawLine(425,75,175,300);
    																			System.out.println("PERDISTE");
    																			}
    																			}
    																			}
     
     
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need help with tic tac toe game

    Try debugging the code by adding lots of println statements to show when different parts of the code is being executed and what the values of the variables are when it is executing.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Game Maker Language and Game Maker and Zelda Classic thread
    By Fira in forum Other Programming Languages
    Replies: 3
    Last Post: April 17th, 2012, 08:59 AM
  2. Simple game that requires me to load game settings from a file
    By 14fenix in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2011, 09:21 PM
  3. Game
    By aneeeeen in forum Paid Java Projects
    Replies: 2
    Last Post: April 16th, 2011, 08:32 AM
  4. Game !
    By Ahmed.Ibrahem in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 08:01 PM
  5. Game 3x3
    By Koren3 in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 20th, 2009, 08:43 PM