-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
110 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
.../main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_READY.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.nico.ratel.landlords.client.event; | ||
|
||
import io.netty.channel.Channel; | ||
import org.nico.ratel.landlords.channel.ChannelUtils; | ||
import org.nico.ratel.landlords.client.SimpleClient; | ||
import org.nico.ratel.landlords.enums.ServerEventCode; | ||
import org.nico.ratel.landlords.helper.MapHelper; | ||
import org.nico.ratel.landlords.print.SimplePrinter; | ||
import org.nico.ratel.landlords.print.SimpleWriter; | ||
|
||
import java.util.Map; | ||
|
||
public class ClientEventListener_CODE_GAME_READY extends ClientEventListener { | ||
@Override | ||
public void call(Channel channel, String data) { | ||
Map<String, Object> map = MapHelper.parser(data); | ||
if (SimpleClient.id == (int) map.get("clientId")) { | ||
SimplePrinter.printNotice("you are ready to play game."); | ||
return; | ||
} | ||
SimplePrinter.printNotice(map.get("clientNickName").toString() + " is ready to play game."); | ||
} | ||
|
||
static void gameReady(Channel channel) { | ||
SimplePrinter.printNotice("\nPress any key to get ready(Press [exit|e] to exit the room)"); | ||
String line = SimpleWriter.write("notReady"); | ||
if (line.equals("")) { | ||
gameReady(channel); | ||
return; | ||
} | ||
if (line.equalsIgnoreCase("exit") || line.equalsIgnoreCase("e")) { | ||
ChannelUtils.pushToServer(channel, ServerEventCode.CODE_CLIENT_EXIT, ""); | ||
return; | ||
} | ||
ChannelUtils.pushToServer(channel, ServerEventCode.CODE_GAME_READY, ""); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ public enum ClientStatus { | |
|
||
TO_CHOOSE, | ||
|
||
NO_READY, | ||
NOT_READY, | ||
|
||
READY, | ||
|
||
|
This file contains 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
This file contains 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
54 changes: 54 additions & 0 deletions
54
.../main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_READY.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.nico.ratel.landlords.server.event; | ||
|
||
import org.nico.ratel.landlords.channel.ChannelUtils; | ||
import org.nico.ratel.landlords.entity.ClientSide; | ||
import org.nico.ratel.landlords.entity.Room; | ||
import org.nico.ratel.landlords.enums.*; | ||
import org.nico.ratel.landlords.helper.MapHelper; | ||
import org.nico.ratel.landlords.print.SimplePrinter; | ||
import org.nico.ratel.landlords.server.ServerContains; | ||
|
||
import java.util.concurrent.ConcurrentSkipListMap; | ||
|
||
public class ServerEventListener_CODE_GAME_READY implements ServerEventListener { | ||
@Override | ||
public void call(ClientSide clientSide, String data) { | ||
Room room = ServerContains.getRoom(clientSide.getRoomId()); | ||
SimplePrinter.serverLog("房间状态:" + room.getStatus()); | ||
SimplePrinter.serverLog("玩家状态:" + clientSide.getStatus()); | ||
if (room.getStatus() == RoomStatus.STARTING) { | ||
return; | ||
} | ||
if (clientSide.getStatus() == ClientStatus.PLAYING || clientSide.getStatus() == ClientStatus.TO_CHOOSE || clientSide.getStatus() == ClientStatus.CALL_LANDLORD) { | ||
return; | ||
} | ||
clientSide.setStatus(clientSide.getStatus() == ClientStatus.READY ? ClientStatus.NOT_READY : ClientStatus.READY); | ||
String result = MapHelper.newInstance() | ||
.put("clientNickName", clientSide.getNickname()) | ||
.put("status", clientSide.getStatus()) | ||
.put("clientId", clientSide.getId()) | ||
.json(); | ||
boolean allReady = true; | ||
ConcurrentSkipListMap<Integer, ClientSide> roomClientMap = (ConcurrentSkipListMap<Integer, ClientSide>) room.getClientSideMap(); | ||
if (roomClientMap.size() < 3) { | ||
allReady = false; | ||
} else { | ||
for (ClientSide client : room.getClientSideList()) { | ||
if (client.getRole() == ClientRole.PLAYER && client.getStatus() != ClientStatus.READY) { | ||
allReady = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
for (ClientSide client : room.getClientSideList()) { | ||
if (client.getRole() == ClientRole.PLAYER) { | ||
ChannelUtils.pushToClient(client.getChannel(), ClientEventCode.CODE_GAME_READY, result); | ||
} | ||
} | ||
|
||
if (allReady) { | ||
ServerEventListener.get(ServerEventCode.CODE_GAME_STARTING).call(clientSide, data); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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