diff --git a/src/main/java/com/ntlab/irisserver/entities/DrawingController.java b/src/main/java/com/ntlab/irisserver/entities/DrawingController.java index 6c5c48d..13a7222 100644 --- a/src/main/java/com/ntlab/irisserver/entities/DrawingController.java +++ b/src/main/java/com/ntlab/irisserver/entities/DrawingController.java @@ -22,7 +22,7 @@ private int drawingTime; //お絵描きのタイムリミット private int countdown; //あと何秒でタイムリミットになるか private boolean isDrawingTimer; //タイマーを使うかどうか - + //描いている最中にタイムリミット(countdown==0)がくれば、描いている途中のものをputさせる。既に描き終わっている人は何もしない //時間が0になったときに、描き終わっていない人は「描いている最中の絵をput」する。(クライアントサイド) デバッグがしにくい assingmentのgetで見れるようにする //getdnoの番号が変わっていたら、「新しい絵を描く」 @@ -45,7 +45,7 @@ //お絵描きのタイムリミットを記録 Settings setting = game.getSettings(); - startTime = System.nanoTime(); + startTime = System.currentTimeMillis(); this.drawingTime = setting.getDrawingTimerTimes(); this.isDrawingTimer = setting.isDrawingTimer(); @@ -73,7 +73,7 @@ stage += 1; //タイマーをリセット - startTime = System.nanoTime(); + startTime = System.currentTimeMillis(); countdown = drawingTime; //ゲームに必要な枚数がそろうと、roomのstateを「お絵描き中2」から「ゲーム中3」に変更 @@ -86,7 +86,7 @@ //お絵描き中のタイマーを更新 private void updateTimer(){ //経過した時間を計算(秒) - nowTime = System.nanoTime(); + nowTime = System.currentTimeMillis(); int count = ((int)nowTime - (int)startTime)/1000; if(drawingTime - count > 0){ @@ -111,12 +111,13 @@ return dno; } - public int getCountdown(){ + //これはどこのRESTで使う? assignmentでもいいけど、名前と機能が一致しない assignmentの下にtimerを作ってもいい + public Integer getCountdown(){ if(isDrawingTimer){ updateTimer(); return countdown; }else{ - return 1; + return null; } } diff --git a/src/main/java/com/ntlab/irisserver/entities/Settings.java b/src/main/java/com/ntlab/irisserver/entities/Settings.java index 4eb2764..81b29da 100644 --- a/src/main/java/com/ntlab/irisserver/entities/Settings.java +++ b/src/main/java/com/ntlab/irisserver/entities/Settings.java @@ -23,7 +23,7 @@ //コンストラクタで初期値設定 public Settings(){ drawingTimer = false; - drawingTimerTimes = 0; + drawingTimerTimes = 50; gameTimer = true; gameTimerTimes = 30; gameTimerFirstThinkingTimes = 10; diff --git a/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java b/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java index 93c5330..080c417 100644 --- a/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java +++ b/src/main/java/com/ntlab/irisserver/resources/AssignmentRest.java @@ -48,4 +48,32 @@ return dno; } + + @GET + @Path("/{rid}/game/drawings/assignment/timer") + @Produces(MediaType.APPLICATION_JSON) + public Integer getTime(@PathParam("rid") String rid){ + + Integer countdown = null; + + RoomManager rm = RoomManager.getInstance(); + Room room = rm.getRoom(rid); + if(room != null) { + Game game = room.getGame(); + DrawingController drawingController = game.getDrawingController(); + + //絵を描ける時間を取得 + countdown = drawingController.getCountdown(); + }else{ + //部屋がなければエラー + var response = Response.status(Response.Status.NO_CONTENT); + response.status(404).entity("部屋が存在しません"); + throw new WebApplicationException(response.build()); + } + + + return countdown; + + + } }