| | package org.ntlab.irisclient; |
---|
| | |
---|
| | import androidx.appcompat.app.AppCompatActivity; |
---|
| | import androidx.fragment.app.FragmentManager; |
---|
| | import androidx.fragment.app.FragmentTransaction; |
---|
| | import androidx.lifecycle.Observer; |
---|
| | import androidx.lifecycle.ViewModelProvider; |
---|
| | |
---|
| | import android.content.Intent; |
---|
| | import android.os.Bundle; |
---|
| | import android.view.View; |
---|
| | import android.widget.Button; |
---|
| | import android.widget.EditText; |
---|
| | |
---|
| | import org.ntlab.irisclient.entities.TurnJson; |
---|
| | import org.ntlab.irisclient.models.Game; |
---|
| | import org.ntlab.irisclient.viewmodels.DrawingStateViewModel; |
---|
| | import org.ntlab.irisclient.viewmodels.GameViewModel; |
---|
| | |
---|
| | |
---|
| | public class GameMasterActivity extends AppCompatActivity{ |
---|
| |
---|
| | private GameViewModel gameViewModel; |
---|
| | |
---|
| | //操作可能かどうかを記録。これがfalseの時は何のボタンを押すこともできない。 |
---|
| | //時間があればオフラインの動作はできるようにしたい。 |
---|
| | private boolean IsActive = false; |
---|
| | private boolean isActive = false; |
---|
| | private String myTeam; |
---|
| | |
---|
| | //赤チームの「ヒント入力」からスタート |
---|
| | private String currentTeam = "r"; |
---|
| | private int turnState = 0;//0:ヒント入力,1:カード選択 |
---|
| | |
---|
| | @Override |
---|
| | protected void onCreate(Bundle savedInstanceState) { |
---|
| | super.onCreate(savedInstanceState); |
---|
| |
---|
| | //自分が赤チームマスターの場合はヒントが入力可能 |
---|
| | if(myTeam == null) { |
---|
| | System.out.println(("myteamがnullです")); |
---|
| | }else if(myTeam.equals("r")){ |
---|
| | IsActive = true; |
---|
| | isActive = true; |
---|
| | } |
---|
| | |
---|
| | //タイマースタート呼び出し |
---|
| | gameViewModel.start(500,iris); |
---|
| | |
---|
| | //hintを監視 |
---|
| | gameViewModel.getHintLiveData().observe(this, new Observer<String>() { |
---|
| | @Override |
---|
| | public void onChanged(String hint) { |
---|
| | |
---|
| | //画面に反映 |
---|
| | EditText Hint = findViewById(R.id.GameHint); |
---|
| | Hint.setText(hint); |
---|
| | |
---|
| | //操作できるかを判断する。 |
---|
| | isActive = CheckActivity(); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //hint,openList,max,turnstate,の更新を反映。(gamestate・ゲームの勝敗結果はカードフラグメントが作る) |
---|
| | gameViewModel.getTurnLiveData().observe(this, new Observer<TurnJson>() { |
---|
| | //hintMaxを監視 |
---|
| | gameViewModel.getmaxLiveData().observe(this, new Observer<Integer>() { |
---|
| | @Override |
---|
| | public void onChanged(TurnJson turnJson) { |
---|
| | public void onChanged(Integer hintMax) { |
---|
| | |
---|
| | //turnJsonから情報を貰ってきて、操作できるのかどうかとかを判断する。 |
---|
| | IsActive = CheckActivity(turnJson); |
---|
| | //画面に反映 |
---|
| | EditText HintMax = findViewById(R.id.GameHintMax); |
---|
| | HintMax.setText(hintMax); |
---|
| | |
---|
| | //時間があれば何をしてほしいのかのアナウンスを入れる |
---|
| | //時間があれば背景の色を変える |
---|
| | //操作できるかを判断する。 |
---|
| | isActive = CheckActivity(); |
---|
| | |
---|
| | //ヒントが変更されているか、ターンが切り替わったときに |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | //UpdateHint(); |
---|
| | //どちらのターンかを監視 |
---|
| | gameViewModel.getTurnsLiveData().observe(this, new Observer<String>() { |
---|
| | @Override |
---|
| | public void onChanged(String new_currentTeam) { |
---|
| | |
---|
| | //画面に反映 |
---|
| | currentTeam = new_currentTeam; |
---|
| | |
---|
| | //操作できるかを判断する。 |
---|
| | isActive = CheckActivity(); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | } |
---|
| |
---|
| | SendHintButton.setOnClickListener(new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | |
---|
| | if(!IsActive){return;}//アクティブのときだけボタンを押せる |
---|
| | if(!isActive){return;}//アクティブのときだけボタンを押せる |
---|
| | |
---|
| | EditText Hint = findViewById(R.id.GameHint); |
---|
| | EditText HintMax = findViewById(R.id.GameHintMax); |
---|
| | |
---|
| |
---|
| | |
---|
| | } |
---|
| | |
---|
| | //操作可能かどうかを調べる関数。masterとかturnをオブザーブしておいて、変更があれば反映する。 |
---|
| | private boolean CheckActivity(TurnJson turnjson){ |
---|
| | private boolean CheckActivity(){ |
---|
| | |
---|
| | boolean isActive = false; |
---|
| | |
---|
| | //最新のゲームの状況を取得 |
---|
| | String CurrentTeam = turnjson.getTeam(); |
---|
| | int turnState = turnjson.getTurnstate(); |
---|
| | |
---|
| | //自分のチームのターンで、かつ「ヒント入力」時間の場合は行動可能 |
---|
| | if(CurrentTeam.equals(myTeam) && turnState == 0){ |
---|
| | if(currentTeam.equals(myTeam) && turnState == 0){ |
---|
| | isActive = true; |
---|
| | } |
---|
| | |
---|
| | return isActive; |
---|
| | } |
---|
| | |
---|
| | private void UpdateHint(String hint,Integer hintMax){ |
---|
| | |
---|
| | EditText Hint = findViewById(R.id.GameHint); |
---|
| | EditText HintMax = findViewById(R.id.GameHintMax); |
---|
| | |
---|
| | Hint.setText(hint); |
---|
| | HintMax.setText(hintMax); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |