The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Jogo da Velha
Posted by: Marcos | April 10, 2011 @ 7:16pm
Java Code
[
Download
]
import javax.swing.JOptionPane; public class jogoVelha { int[]v = new int[9]; boolean fim; public void jogaP1(int i){ if (v[i] == 0){ v[i] = 1; System.out.println("O jogador 1 jogou na posi��o " +i); }else if (v[i] != 0){ System.out.println("ERRO! Essa casa j� foi jogada!"); } checaVencedor(); if (fim==true){ System.out.println("O jogador 1 ganhou!"); System.exit(0); } } public void jogaP2(int i){ if (v[i] == 0){ v[i] = 1; System.out.println("O jogador 2 jogou na posi��o " +i); } else if (v[i] != 0){ System.out.println("ERRO! Essa casa j� foi jogada!"); } checaVencedor(); if (fim == true){ System.out.println("O jogador 2 ganhou!"); System.exit(0); } } public void checaVencedor(){ if (v[0] == 1 && v[1] == 1 && v[2] == 1 || v[0] == 1 && v[3] == 1 && v[6] == 1 || v[0] == 1 && v[4] == 1 && v[8] == 1 || v[3] == 1 && v[4] == 1 && v[5] == 1 || v[6] == 1 && v[7] == 1 && v[8] == 1 || v[1] == 1 && v[4] == 1 && v[7] == 1 || v[2] == 1 && v[5] == 1 && v[8] == 1){ fim = true; } else if (v[0] == 2 && v[1] == 2 && v[2] == 2 || v[0] == 2 && v[3] == 2 && v[6] == 2 || v[0] == 2 && v[4] == 2 && v[8] == 2 || v[3] == 2 && v[4] == 2 && v[5] == 2 || v[6] == 2 && v[7] == 2 && v[8] == 2 || v[1] == 2 && v[4] == 2 && v[7] == 2 || v[2] == 2 && v[5] == 2 && v[8] == 2){ fim = true; } } /* * Come�a a minha parte: */ public static void main(String[]args) { new jogoVelha(); } public jogoVelha() { int i = 0; do { if (i % 2 == 0) { jogaP1(Integer.parseInt(JOptionPane.showInputDialog("Player1\n\nJogue:"))); } else { jogaP1(Integer.parseInt(JOptionPane.showInputDialog("Player2\n\nJogue:"))); } i++; } while (fim == false); }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.12 / 8
171 Votes
http://codebin.yi.org/1217
page generated in 0.01 seconds