diff --git a/.idea/misc.xml b/.idea/misc.xml index 7299e9f..7866fee 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,8 @@ - + + diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java index 01256d0..980193a 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java @@ -5,6 +5,7 @@ import android.app.Dialog; import android.content.Context; import android.content.Intent; +import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -27,6 +28,7 @@ import androidx.lifecycle.ViewModelProvider; import org.ntlab.irisclient.models.Drawing; +import org.ntlab.irisclient.resources.GameRest; import org.ntlab.irisclient.viewmodels.GameViewModel; import java.io.IOException; @@ -167,7 +169,7 @@ gameViewModel.getEndStateLiveData().observe ( getViewLifecycleOwner(), endStateObserver -> { - System.out.println("kota: " + endStateObserver); + System.out.println("kota:" + endStateObserver); if(endStateObserver == 0) { System.out.println("kota: ゲームが終了!!:" + endStateObserver); finishGameAlertMake(myTeam, nowTurn); @@ -400,7 +402,7 @@ backColors[i].setBackground(resources.getDrawable(R.drawable.black_image)); imageButtons[i].setVisibility(View.INVISIBLE); gameViewModel.sendEndState(); - //finishGameAlertMake(myTeam, nowTurn); + finishGameAlertMake(myTeam, nowTurn); } setAnime(i); nowOpenList.set(i, true); @@ -433,6 +435,23 @@ private void setOpenRealTime(int cno, boolean isOK) { if(isOK == true) { gameViewModel.sendOpenList(cno); + + if( colorList.get(cno).equals("d") ){ + System.out.println("黒引きました"); + gameViewModel.sendEndState(); + } else if ( colorList.get(cno).equals(myTeam) ){ + System.out.println("チームと同じなのでまだ引けます"); + } else { + if( myTeam.equals("r") ){ + nowTurn = "b"; + System.out.println("青に切り替わり"); + } else if( myTeam.equals("b") ){ + nowTurn = "r"; + System.out.println("赤に切り替わり"); + } + gameViewModel.addTurns(); + } + } } diff --git a/app/src/main/java/org/ntlab/irisclient/GameMasterActivity.java b/app/src/main/java/org/ntlab/irisclient/GameMasterActivity.java index e01c83b..488e32e 100644 --- a/app/src/main/java/org/ntlab/irisclient/GameMasterActivity.java +++ b/app/src/main/java/org/ntlab/irisclient/GameMasterActivity.java @@ -141,7 +141,9 @@ @Override public void onClick(View view) { - if(!isActive){return;}//アクティブのときだけボタンを押せる + if(!isActive){ + return; + }//アクティブのときだけボタンを押せる EditText Hint = findViewById(R.id.GameHint); EditText HintMax = findViewById(R.id.GameHintMax); @@ -159,7 +161,7 @@ System.out.println("Gakuto:MasterActivity ヒントマックス" + HintMax.getText().toString()); hintMax = Integer.parseInt(HintMax.getText().toString()); //マックス0は受け付けない - if(hintMax == 0){ + if(hintMax < 0){ hintMax = 1; } } @@ -188,23 +190,25 @@ boolean isActive = false; - //自分のチームのターンで、かつ「ヒント入力」時間の場合は行動可能 - if(currentTeam.equals(myTeam) && turnState == 0){ - isActive = true; - } + //System.out.println("currentTeam:" + currentTeam + " myteam:" + myTeam); + + //非アクティブであればヒントの入力を禁止する EditText Hint = findViewById(R.id.GameHint); EditText HintMax = findViewById(R.id.GameHintMax); Button SendHintButton = (Button) findViewById(R.id.SendHint); - if(isActive == false){ - Hint.setFocusable(false); - HintMax.setFocusable(false); - SendHintButton.setFocusable(false); - }else{ - Hint.setFocusable(true); - HintMax.setFocusable(true); - SendHintButton.setFocusable(true); + + Hint.setFocusableInTouchMode(false); + HintMax.setFocusableInTouchMode(false); + SendHintButton.setFocusableInTouchMode(false); + + //自分のチームのターンで、かつ「ヒント入力」時間の場合は行動可能 + if(currentTeam.equals(myTeam) && turnState == 0){ + isActive = true; + Hint.setFocusableInTouchMode(true); + HintMax.setFocusableInTouchMode(true); + SendHintButton.setFocusableInTouchMode(true); } //デバッグ用 diff --git a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java index c4be43e..d2036a8 100644 --- a/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java +++ b/app/src/main/java/org/ntlab/irisclient/viewmodels/GameViewModel.java @@ -36,6 +36,7 @@ final private MutableLiveData> mapMutableLiveData; final private MutableLiveData imageMutableLiveData; final private MutableLiveData QMutableLiveData; + final private MutableLiveData addTurnsMutableLiveData; private GameJson game = new GameJson(); final private GameRest gameRest; final private Retrofit retrofit; @@ -52,6 +53,7 @@ private List opensPreData = null; private Boolean[] QPreData = null; + private Void addTurnsPreData = null; //------------------------------------------------------------------ //コンストラクタ @@ -68,6 +70,7 @@ this.opensMutableLiveData = new MutableLiveData<>(); this.imageMutableLiveData = new MutableLiveData<>(); this.QMutableLiveData = new MutableLiveData<>(); + this.addTurnsMutableLiveData = new MutableLiveData<>(); this.retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") @@ -96,6 +99,9 @@ public LiveData getTurnStateLiveData() { return this.turnStateMutableLiveData; } + public LiveData getTurnNumberLiveData() { + return this.turnNumberMutableLiveData; + } public LiveData getEndStateLiveData() { return this.endStateMutableLiveData; } @@ -117,6 +123,9 @@ public LiveData getQLiveData() { return this.QMutableLiveData; } + public LiveData getAddTurnsLiveData() { + return this.addTurnsMutableLiveData; + } public GameJson getGame() { return game; } @@ -150,6 +159,7 @@ if (response.isSuccessful()){ System.out.println("通信成功:sendOpenList"); } + } @Override public void onFailure(Call call, Throwable t) { @@ -216,6 +226,25 @@ }); } + //ターン数変更 + public void addTurns() { + Call call = gameRest.addTurns(rid); + + call.enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()){ + System.out.println("通信成功:addTurns"); + } + } + @Override + public void onFailure(Call call, Throwable t) { + System.out.println("通信失敗:addTurns"); + System.out.println(t); + } + }); + } + //カードのカラー(r,b,g,d)の取得 private void startColor() { Call> call = gameRest.getColorList(rid);