revamped card system
This commit is contained in:
parent
0c6ae26e93
commit
3ac717a452
6 changed files with 80 additions and 138 deletions
52
icons/desktop.ini
Normal file
52
icons/desktop.ini
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
[LocalizedFileNames]
|
||||
car.png=@car.png,0
|
||||
dot.png=@dot.png,0
|
||||
candy.png=@candy.png,0
|
||||
baby.png=@baby.png,0
|
||||
chalk.png=@chalk.png,0
|
||||
thread.png=@thread.png,0
|
||||
cord.png=@cord.png,0
|
||||
towel.png=@towel.png,0
|
||||
table.png=@table.png,0
|
||||
chain.png=@chain.png,0
|
||||
hammer.png=@hammer.png,0
|
||||
nail.png=@nail.png,0
|
||||
key.png=@key.png,0
|
||||
tomato.png=@tomato.png,0
|
||||
bowl.png=@bowl.png,0
|
||||
banana.png=@banana.png,0
|
||||
sponge.png=@sponge.png,0
|
||||
cork.png=@cork.png,0
|
||||
mirror.png=@mirror.png,0
|
||||
screw.png=@screw.png,0
|
||||
bread.png=@bread.png,0
|
||||
money.png=@money.png,0
|
||||
camera.png=@camera.png,0
|
||||
brush.png=@brush.png,0
|
||||
purse.png=@purse.png,0
|
||||
bottle.png=@bottle.png,0
|
||||
clock.png=@clock.png,0
|
||||
door.png=@door.png,0
|
||||
spoon.png=@spoon.png,0
|
||||
fork.png=@fork.png,0
|
||||
boat.png=@boat.png,0
|
||||
cat.png=@cat.png,0
|
||||
sign.png=@sign.png,0
|
||||
eraser.png=@eraser.png,0
|
||||
fan.png=@fan.png,0
|
||||
sock.png=@sock.png,0
|
||||
ring.png=@ring.png,0
|
||||
keyboard.png=@keyboard.png,0
|
||||
bow.png=@bow.png,0
|
||||
pencil.png=@pencil.png,0
|
||||
glasses.png=@glasses.png,0
|
||||
bed.png=@bed.png,0
|
||||
desk.png=@desk.png,0
|
||||
book.png=@book.png,0
|
||||
paper.png=@paper.png,0
|
||||
toy.png=@toy.png,0
|
||||
computer.png=@computer.png,0
|
||||
person.png=@person.png,0
|
||||
tree.png=@tree.png,0
|
||||
phone.png=@phone.png,0
|
||||
elephant.png=@elephant.png,0
|
||||
BIN
icons/dot.png
BIN
icons/dot.png
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB |
|
|
@ -1,131 +0,0 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
public class gameServer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ServerSocket listener = new ServerSocket(8901);
|
||||
System.out.println("Game Server is Running");
|
||||
try {
|
||||
while (true) {
|
||||
Game game = new Game();
|
||||
Game.Player player1 = game.new Player(listener.accept());
|
||||
Game.Player player2 = game.new Player(listener.accept());
|
||||
player1.setOpponent(player2);
|
||||
player2.setOpponent(player1);
|
||||
game.currentPlayer = player1;
|
||||
player1.start();
|
||||
player2.start();
|
||||
}
|
||||
} finally {
|
||||
listener.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Game {
|
||||
Player currentPlayer;
|
||||
|
||||
// winner
|
||||
public boolean hasWinner() {
|
||||
return
|
||||
(board[0] != null && board[0] == board[1] && board[0] == board[2])
|
||||
||(board[3] != null && board[3] == board[4] && board[3] == board[5])
|
||||
||(board[6] != null && board[6] == board[7] && board[6] == board[8])
|
||||
||(board[0] != null && board[0] == board[3] && board[0] == board[6])
|
||||
||(board[1] != null && board[1] == board[4] && board[1] == board[7])
|
||||
||(board[2] != null && board[2] == board[5] && board[2] == board[8])
|
||||
||(board[0] != null && board[0] == board[4] && board[0] == board[8])
|
||||
||(board[2] != null && board[2] == board[4] && board[2] == board[6]);
|
||||
}
|
||||
|
||||
// no empty squares
|
||||
public boolean boardFilledUp() {
|
||||
for (int i = 0; i < board.length; i++) {
|
||||
if (board[i] == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// thread when player tries a move
|
||||
public synchronized boolean legalMove(int location, Player player) {
|
||||
if (player == currentPlayer && board[location] == null) {
|
||||
board[location] = currentPlayer;
|
||||
currentPlayer = currentPlayer.opponent;
|
||||
currentPlayer.otherPlayerMoved(location);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
class Player extends Thread {
|
||||
char mark;
|
||||
Player opponent;
|
||||
Socket socket;
|
||||
BufferedReader input;
|
||||
PrintWriter output;
|
||||
// thread handler to initialize stream fields
|
||||
public Player(Socket socket) {
|
||||
this.socket = socket;
|
||||
this.mark = mark;
|
||||
try {
|
||||
input = new BufferedReader(
|
||||
new InputStreamReader(socket.getInputStream()));
|
||||
output = new PrintWriter(socket.getOutputStream(), true);
|
||||
output.println("WELCOME " + mark);
|
||||
output.println("MESSAGE Waiting for opponent to connect");
|
||||
} catch (IOException e) {
|
||||
System.out.println("Player died: " + e);
|
||||
}
|
||||
}
|
||||
//Accepts notification of who the opponent is.
|
||||
public void setOpponent(Player opponent) {
|
||||
this.opponent = opponent;
|
||||
}
|
||||
|
||||
|
||||
//Handles the otherPlayerMoved message.
|
||||
public void otherPlayerMoved(int location) {
|
||||
output.println("OPPONENT_MOVED " + location);
|
||||
output.println(
|
||||
hasWinner() ? "DEFEAT" : boardFilledUp() ? "TIE" : "");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
// The thread is only started after everyone connects.
|
||||
output.println("MESSAGE All players connected");
|
||||
|
||||
// Tell the first player that it is his/her turn.
|
||||
if (mark == 'X') {
|
||||
output.println("MESSAGE Your move");
|
||||
}
|
||||
|
||||
// Repeatedly get commands from the client and process them.
|
||||
while (true) {
|
||||
String command = input.readLine();
|
||||
if (command.startsWith("MOVE")) {
|
||||
int location = Integer.parseInt(command.substring(5));
|
||||
if (legalMove(location, this)) {
|
||||
output.println("VALID_MOVE");
|
||||
output.println(hasWinner() ? "VICTORY"
|
||||
: boardFilledUp() ? "TIE"
|
||||
: "");
|
||||
} else {
|
||||
output.println("MESSAGE ?");
|
||||
}
|
||||
} else if (command.startsWith("QUIT")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("Player died: " + e);
|
||||
} finally {
|
||||
try {socket.close();} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue