diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java index bb5199a..74d4494 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java @@ -196,7 +196,7 @@ gameViewModel.getQLiveData().observe ( getViewLifecycleOwner(), QObserver -> { - System.out.println("kota: 疑われた。 疑われた配列: " + QObserver); + System.out.println("kota: 疑われた。 疑われた配列: " + QObserver); setQ(QObserver); } ); @@ -205,10 +205,13 @@ gameViewModel.getEndStateLiveData().observe ( getViewLifecycleOwner(), endStateObserver -> { - System.out.println("kota:" + endStateObserver); + System.out.println("kota:getEndState" + endStateObserver); if(endStateObserver == 0) { - System.out.println("kota: ゲームが終了!!:" + endStateObserver); + + System.out.println("kota: 黒めくってゲームが終了!!:" + endStateObserver); finishGameAlertMake(myTeam, nowTurn); + } else { + finishFullOpenGameAlertMake(myTeam, nowTurn); } } ); @@ -233,6 +236,7 @@ System.out.println("kota: isMasterかどうか:" + isMaster); System.out.println("kota: getrid:" + iris.getRid()); System.out.println("kota: getteame:" + iris.getTeam()); + System.out.println("kota: nowTurn:" + nowTurn); System.out.println("kota: getMemberList:" + iris.getMemberList()); System.out.println("kota: getNickName:" + iris.getNickname()); System.out.println("kota: getImageLiveData:" + gameViewModel.getImageLiveData().getValue()); @@ -300,8 +304,6 @@ map = gameViewModel.getGame().getMap(); colorList = gameViewModel.getGame().getColorList(); - System.out.println("adfasfasdfsf"+drawingList); - Context context = getContext(); for (Integer i: map) { @@ -421,6 +423,8 @@ * Observeして変更加わった度に呼ばれる **/ private void setOpen(List openList) { + OpenRedCard = 0; + OpenBlueCard = 0; for(int i=0; i< openList.size(); i++) { if (openList.get(i) == true && nowOpenList.get(i) == false) { @@ -428,12 +432,21 @@ if (colorList.get(i).contains("r")) { backColors[i].setBackground(resources.getDrawable(R.drawable.red_image)); imageButtons[i].setVisibility(INVISIBLE); + OpenRedCard += 1; + if( !colorList.get(i).equals(myTeam) ){ + gameViewModel.addTurns(); + } } else if (colorList.get(i).contains("b")) { backColors[i].setBackground(resources.getDrawable(R.drawable.blue_image)); imageButtons[i].setVisibility(INVISIBLE); + OpenBlueCard += 1; + if( !colorList.get(i).equals(myTeam) ){ + gameViewModel.addTurns(); + } } else if (colorList.get(i).contains("g")) { backColors[i].setBackground(resources.getDrawable(R.drawable.gray_image)); imageButtons[i].setVisibility(INVISIBLE); + gameViewModel.addTurns(); } else if (colorList.get(i).contains("d")) { backColors[i].setBackground(resources.getDrawable(R.drawable.black_image)); imageButtons[i].setVisibility(INVISIBLE); @@ -442,8 +455,18 @@ } setAnime(i); nowOpenList.set(i, true); + } else if( openList.get(i) == true && colorList.get(i).contains("r") ){ + OpenRedCard += 1; + } else if( openList.get(i) == true && colorList.get(i).contains("b") ){ + OpenBlueCard += 1; } } + + if( OpenRedCard == 6 || OpenBlueCard == 5 ){ + gameViewModel.sendEndState(); + finishFullOpenGameAlertMake(myTeam, nowTurn); + } + } //----------------------------------------------------------------------------- @@ -474,13 +497,12 @@ nowQList.set(cno, false);//疑い関係 gameViewModel.sendOpenList(cno); - if( colorList.get(cno).equals("d") ){ - //Game終了 - gameViewModel.sendEndState(); - } else if ( !colorList.get(cno).equals(myTeam) ){ - //ターン切り替え - gameViewModel.addTurns(); - } +// if( colorList.get(cno).equals("d") ){ +// //Game終了 +// gameViewModel.sendEndState(); +// } else if ( !colorList.get(cno).equals(myTeam) ){ +// gameViewModel.addTurns(); +// } //赤のカードが何枚めくれているか(6枚めくれていたら勝利) if( colorList.get(cno).equals("r") ){ @@ -493,8 +515,8 @@ } nowOpenList.set(cno, false); if( OpenRedCard == 6 ){ - nowTurn = "b"; - finishGameAlertMake(myTeam, nowTurn); + gameViewModel.sendEndState(); + finishFullOpenGameAlertMake(myTeam, nowTurn); } } //青のカードが何枚めくれているか(5枚めくれていたら勝利) @@ -506,10 +528,11 @@ OpenBlueCard += 1; } } + nowOpenList.set(cno, false); if( OpenBlueCard == 5 ){ - nowTurn = "r"; - finishGameAlertMake(myTeam, nowTurn); + gameViewModel.sendEndState(); + finishFullOpenGameAlertMake(myTeam, nowTurn); } } @@ -645,6 +668,32 @@ builder.show(); } + /** + * 赤顔のカードがすべてひかれて、ゲームが終わったときに呼ばれるアラート + */ + private void finishFullOpenGameAlertMake(String myTeam, String nowTurn) { + String strTitle; + String strMessage; + System.out.println("ゲームが終わった時のmyTeam:" + myTeam); + System.out.println("ゲームが終わった時のmyTurn:" + nowTurn); + + if ( !myTeam.equals(nowTurn)) { + strTitle = "Your Lose..."; + strMessage = "お疲れ様でした。\n残念ながら、あなたチームは負けました..."; + } else { + strTitle = "Your Win!!"; + strMessage = "お疲れ様でした。\nおめでとうございます、あなたチームの勝利です!"; + } + + AlertDialog.Builder builder; + builder = new AlertDialog.Builder(getContext()); + builder.setTitle(strTitle); + builder.setMessage(strMessage); + builder.setPositiveButton("完了", (dialog, id) -> setFinish()); + builder.create(); + builder.show(); + } + // TODO: 未完成の関数 /** * ゲームが終了したときに呼ばれる関数