Skip to content

Instantly share code, notes, and snippets.

@wasabili
Created October 31, 2010 05:54
Show Gist options
  • Save wasabili/656194 to your computer and use it in GitHub Desktop.
Save wasabili/656194 to your computer and use it in GitHub Desktop.
NetOthello
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class NetOthello{
Othello oth = null;
int self;
public NetOthello(){
oth = new Othello();
Socket socket = null;
try {
socket = new Socket("localhost", 10000);
} catch (Exception e) {
e.printStackTrace();
}
try{
Scanner scn = new Scanner(socket.getInputStream());
PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
self = scn.nextInt();
System.out.println("Your color is "+((self==oth.BLACK)? "Black":"White"));
while(true){
oth.display();
if(oth.turn == self){
System.out.println("Your turn.");
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
if(oth.canPut(x,y,oth.turn)){
oth.put(x,y,oth.turn);
pw.println(x+" "+y);
oth.changeTurn();
System.out.println("Put");
}else {
System.out.println("Cannot put there");
}
}else{
System.out.println("Not your turn.");
int x = scn.nextInt();
int y = scn.nextInt();
oth.put(x,y,oth.turn);
oth.changeTurn();
}
}
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args){
NetOthello no = new NetOthello();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment