Browse Source

加入游戏

master
zhizhi wu 6 years ago
parent
commit
034db5e0d6
  1. 2
      game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java
  2. 5
      game/src/main/java/com/ccsens/game/service/ClientService.java
  3. 6
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  4. 4
      game/src/main/java/com/ccsens/game/util/SendMsg.java
  5. 4
      game/src/main/resources/application.yml

2
game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java

@ -106,7 +106,9 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<BaseMessageDto
case Count:
String userId = ChannelManager.getUserIdByChannel(ctx.channel());
String recordId = ChannelManager.getRecordIdByChannel(ctx.channel());
log.info("统计分数:{},{}",userId, recordId);
GameMessageCountOut gameMessageCountOut = clientService.clientAddTimes(userId,recordId);
log.info("统计分数返回结果:{}", gameMessageCountOut);
ChannelManager.sendTo(ctx.channel(), gameMessageCountOut);
break;
case ChangeStatus:

5
game/src/main/java/com/ccsens/game/service/ClientService.java

@ -280,18 +280,21 @@ public class ClientService implements IClientService {
@Override
public GameMessageCountOut clientAddTimes(String userId,String recordId) {
GameMessageCountOut gameMessageCountOut = new GameMessageCountOut();
log.info("userId:{}", userId);
if(ObjectUtil.isNotNull(userId)){
GameUserJoinExample gameUserJoinExample = new GameUserJoinExample();
gameUserJoinExample.createCriteria().andUserIdEqualTo(Long.valueOf(userId)).andRecordIdEqualTo(Long.valueOf(recordId));
List<GameUserJoin> userJoinList = gameUserJoinDao.selectByExample(gameUserJoinExample);
log.info("游戏对象:{}", userJoinList);
if(CollectionUtil.isNotEmpty(userJoinList)){
GameUserJoin userJoin = userJoinList.get(0);
userJoin.setTimes(userJoin.getTimes() + 1);
userJoin.setScore(userJoin.getScore() + 100);
log.info("更新分数:{}", userJoin);
gameUserJoinDao.updateByPrimaryKeySelective(userJoin);
//更新redis
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin);
log.info("游戏id:{}, 对象:{}, 分数:{}", recordId, user,userJoin.getScore());
redisUtil.zsSet(GameConstant.generateGameKey(Long.parseLong(recordId)), JSON.toJSONString(user), userJoin.getScore(), GameConstant.REDIS_TIME);
gameMessageCountOut = new GameMessageCountOut(userJoin.getTimes(),userJoin.getScore());
}

6
game/src/main/java/com/ccsens/game/service/ScreenService.java

@ -579,9 +579,9 @@ public class ScreenService implements IScreenService{
GameUserJoinExample joinExample = new GameUserJoinExample();
joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId());
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(joinExample);
if (CollectionUtil.isEmpty(userJoins)) {
return startGame;
}
// if (CollectionUtil.isEmpty(userJoins)) {
// return startGame;
// }
userJoins.forEach( userJoin -> {
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin);
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME);

4
game/src/main/java/com/ccsens/game/util/SendMsg.java

@ -48,11 +48,9 @@ public class SendMsg {
userJoins.forEach(join -> {
outs.add(getMsg(gameRecord, join, status));
});
System.out.println("准备发送"+outs);
if (CollectionUtil.isNotEmpty(outs)) {
log.info("==================="+outs);
rabbitTemplate.convertAndSend(RabbitMQConfig.GAME_STATUS, JacksonUtil.beanToJson(outs));
System.out.println("发送成功"+JacksonUtil.beanToJson(outs));
log.info("发送成功:{}",JacksonUtil.beanToJson(outs));
}
}

4
game/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: dev
include: common, util-dev
active: test
include: common, util-test
Loading…
Cancel
Save