Created
June 6, 2017 00:39
-
-
Save joffilyfe/fc6bd57c53d300e56dd9e2a32f65608a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
public class Servidor { | |
public static void main(String[] args) throws IOException { | |
ServerSocket servidor = new ServerSocket(7171, 1); | |
Socket cliente = servidor.accept(); | |
String forca = "Sol"; | |
DataInputStream dataInput = new DataInputStream(cliente.getInputStream()); | |
DataOutputStream dataOutput = new DataOutputStream(cliente.getOutputStream()); | |
String response = ""; | |
int tentativas = forca.length(); | |
while (response != null) { | |
// Ver se as tentativas encerraram | |
if (tentativas == 0) { | |
cliente.close(); | |
break; | |
} | |
// Ler o envio pelo socket | |
response = dataInput.readUTF(); | |
// Se for bye, então killa o loop e a conexao | |
if (response.equals("bye")) { | |
cliente.close(); | |
break; | |
} | |
// Acertou mizeravi | |
if (response.equals(forca)) { | |
dataOutput.writeUTF("Você acertou mizeravi..."); | |
cliente.close(); | |
break; | |
} | |
dataOutput.writeUTF("Você errou e tem " + tentativas + " tentativas restantes"); | |
tentativas--; | |
} | |
servidor.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment