Código fuente TIC-TAC-TOE<br />package game;<br />import java.awt.Component;<br />import java.awt.Container;<br />import j...
Proyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac Toe
Upcoming SlideShare
Loading in …5
×

Proyecto Poogame Tic Tac Toe

1,569 views

Published on

Código fuente del programa TIC-TAC-TOE
(poogame.blogspot.com)

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,569
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
56
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Proyecto Poogame Tic Tac Toe

  1. 1. Código fuente TIC-TAC-TOE<br />package game;<br />import java.awt.Component;<br />import java.awt.Container;<br />import java.awt.Dimension;<br />import java.awt.event.ActionEvent;<br />import java.awt.event.ActionListener;<br />import javax.swing.JApplet;<br />import javax.swing.JButton;<br />import javax.swing.JLabel;<br />import javax.swing.JPanel;<br />import javax.swing.JTextField;<br />public class Ejecutable extends JApplet implements ActionListener{<br />private JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;<br />private JLabel ganador,jugador;<br />private JButton player,reset;<br />private JPanel panel1;<br />private String playerA,playerB;<br />private String dato;<br />public void init(){<br />//Creacion de los elementos<br />t1=new JTextField(" 1" );<br />t1.disable();<br />t2=new JTextField(" 2" );<br />t2.disable();<br />t3=new JTextField(" 3" );<br />t3.disable();<br />t4=new JTextField(" 4" );<br />t4.disable();<br />t5=new JTextField(" 5" );<br />t5.disable();<br />t6=new JTextField(" 6" );<br />t6.disable();<br />t7=new JTextField(" 7" );<br />t7.disable();<br />t8=new JTextField(" 8" );<br />t8.disable();<br />t9=new JTextField(" 9" );<br />t9.disable();<br />t10= new JTextField(" Name" );<br />jugador=new JLabel();<br />ganador=new JLabel();<br />player=new JButton(" Player 1" );<br />player.addActionListener(this);<br />reset=new JButton(" Reset" );<br />reset.addActionListener(this);<br />panel1=(JPanel)this.getContentPane();<br />panel1.setLayout(null);<br />addComponent(panel1, jugador, 27, 2, 105, 18);<br />addComponent(panel1, ganador, 10, 152, 150, 18);<br />addComponent(panel1, t1, 27, 47, 20, 22);<br />addComponent(panel1, t2, 54, 47, 20, 22);<br />addComponent(panel1, t3, 81, 47, 20, 22);<br />addComponent(panel1, t4, 27, 78, 20, 22);<br />addComponent(panel1, t5, 54, 78, 20, 22);<br />addComponent(panel1, t6, 81, 78, 20, 22);<br />addComponent(panel1, t7, 27, 109, 20, 22);<br />addComponent(panel1, t8, 54, 109, 20, 22);<br />addComponent(panel1, t9, 81, 109, 20, 22);<br />addComponent(panel1, t10, 148, 47,105, 22);<br />addComponent(panel1, player, 148, 78, 105, 22);<br />addComponent(panel1, reset, 148, 109, 105, 22);<br />this.setSize(new Dimension(269,203));<br />}<br />//metodo para insertar objetos por posicon x e y con largo y ancho<br />private void addComponent(Container container, Component c,int x,int y, int ancho,int largo) {<br />c.setBounds(x, y, ancho, largo);<br />container.add(c);<br />}<br />//metodo para capturar los eventos<br />public void actionPerformed(ActionEvent e) {<br />try{<br />game(e);<br />}catch(NullPointerException e1){<br />} catch (Exception e2) {<br />// TODO Auto-generated catch block<br />ganador.setText(" Error" );<br />}<br />}<br />private void game(ActionEvent e) {<br />String check=e.getActionCommand();<br />if(check.equals(" Player 1" )){<br />playerA=t10.getText();<br />player.setText(" Player 2" );<br />t10.setText(" " );<br />}<br />else if(check.equals(" Player 2" )){<br />playerB=t10.getText();<br />player.setText(" Play" );<br />t10.setText(" Ready GO!" );<br />}<br />else if(check.equals(" Play" )){<br />t10.setText(" Insert number " );<br />player.setText(playerA+" (X)" );<br />}<br />else if(check.equals(playerA+" (X)" )){<br />int opc=1;<br />jugador.setText(" Espera: " +playerA);<br />dato=t10.getText();<br />compara(dato,opc);<br />premio();<br />player.setText(playerB+" (O)" );<br />}<br />else if(check.equals(playerB+" (O)" )){<br />int opc=2;<br />jugador.setText(" Espera: " +playerB);<br />dato=t10.getText();<br />compara(dato,opc);<br />premio();<br />player.setText(playerA+" (X)" );<br />}<br />else if(check.equals(" Reset" )){<br />t1.setText(" 1" );<br />t2.setText(" 2" );<br />t3.setText(" 3" );<br />t4.setText(" 4" );<br />t5.setText(" 5" );<br />t6.setText(" 6" );<br />t7.setText(" 7" );<br />t8.setText(" 8" );<br />t9.setText(" 9" );<br />t10.enable();<br />t10.setText(" Name" );<br />player.setText(" Player 1" );<br />jugador.setText(" " );<br />ganador.setText(" " );<br />}<br />else{<br />ganador.setText(" Error inesperado" );<br />}<br />}<br />private void premio() {<br />if(t1.getText().equals(" X" )&&t2.getText().equals(" X" )&&t3.getText().equals(" X" )||<br />t4.getText().equals(" X" )&&t5.getText().equals(" X" )&&t6.getText().equals(" X" )||<br />t7.getText().equals(" X" )&&t8.getText().equals(" X" )&&t9.getText().equals(" X" )||<br />t1.getText().equals(" X" )&&t4.getText().equals(" X" )&&t7.getText().equals(" X" )||<br />t2.getText().equals(" X" )&&t5.getText().equals(" X" )&&t8.getText().equals(" X" )||<br />t3.getText().equals(" X" )&&t6.getText().equals(" X" )&&t9.getText().equals(" X" )||<br />t1.getText().equals(" X" )&&t5.getText().equals(" X" )&&t9.getText().equals(" X" )||<br />t3.getText().equals(" X" )&&t5.getText().equals(" X" )&&t7.getText().equals(" X" )){<br />ganador.setText(" El ganador es: " +playerA);<br />win();<br />}<br />else if(t1.getText().equals(" O" )&&t2.getText().equals(" O" )&&t3.getText().equals(" O" )||<br />t4.getText().equals(" O" )&&t5.getText().equals(" O" )&&t6.getText().equals(" O" )||<br />t7.getText().equals(" O" )&&t8.getText().equals(" O" )&&t9.getText().equals(" O" )||<br />t1.getText().equals(" O" )&&t4.getText().equals(" O" )&&t7.getText().equals(" O" )||<br />t2.getText().equals(" O" )&&t5.getText().equals(" O" )&&t6.getText().equals(" O" )||<br />t3.getText().equals(" O" )&&t6.getText().equals(" O" )&&t9.getText().equals(" O" )||<br />t1.getText().equals(" O" )&&t5.getText().equals(" O" )&&t9.getText().equals(" O" )||<br />t3.getText().equals(" O" )&&t5.getText().equals(" O" )&&t7.getText().equals(" O" )){<br />ganador.setText(" El ganador es: " +playerB);<br />win();<br />player.disable();<br />}<br />}<br />private void win() {<br />t10.setText(" Thanks for playing!" );<br />t10.disable();<br />player.disable();<br />}<br />private void compara(String dato2,int o) {<br />switch(o){<br />case 1:<br />if(t1.getText().equals(dato2)){<br />t1.setText(" X" );<br />}<br />if(t2.getText().equals(dato2)){<br />t2.setText(" X" );<br />}<br />if(t3.getText().equals(dato2)){<br />t3.setText(" X" );<br />}<br />if(t4.getText().equals(dato2)){<br />t4.setText(" X" );<br />}<br />if(t5.getText().equals(dato2)){<br />t5.setText(" X" );<br />}<br />if(t6.getText().equals(dato2)){<br />t6.setText(" X" );<br />}<br />if(t7.getText().equals(dato2)){<br />t7.setText(" X" );<br />}<br />if(t8.getText().equals(dato2)){<br />t8.setText(" X" );<br />}<br />if(t9.getText().equals(dato2)){<br />t9.setText(" X" );<br />}<br />break;<br />case 2:<br />if(t1.getText().equals(dato2)){<br />t1.setText(" O" );<br />}<br />if(t2.getText().equals(dato2)){<br />t2.setText(" O" );<br />}<br />if(t3.getText().equals(dato2)){<br />t3.setText(" O" );<br />}<br />if(t4.getText().equals(dato2)){<br />t4.setText(" O" );<br />}<br />if(t5.getText().equals(dato2)){<br />t5.setText(" O" );<br />}<br />if(t6.getText().equals(dato2)){<br />t6.setText(" O" );<br />}<br />if(t7.getText().equals(dato2)){<br />t7.setText(" O" );<br />}<br />if(t8.getText().equals(dato2)){<br />t8.setText(" O" );<br />}<br />if(t9.getText().equals(dato2)){<br />t9.setText(" O" );<br />}<br />break;<br />}<br />}<br />}<br />

×