package org.ntlab.irisclient; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import org.ntlab.irisclient.models.Member; import org.ntlab.irisclient.resources.RoomsRest; import java.util.List; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class TestGameActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test_activity_game); //サーバーとの通信を初期化 Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris-websocket/") .addConverterFactory(JacksonConverterFactory.create()) .build(); final RoomsRest roomsRest = retrofit.create(RoomsRest.class); //上の表示を削除 ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.hide(); } //RedSpy(owner)として参加 Button ownerButton = findViewById(R.id.ownergame); ownerButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("gametest"); ((Iris) getApplication()).setNickname("RedSpy(owner)"); ((Iris) getApplication()).setTeam("r"); ((Iris) getApplication()).setMaster(true); Call<List<Member>> call = roomsRest.getRoomMember("gametest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功"); ((Iris) getApplication()).setMemberList(response.body()); Intent intent = new Intent(TestGameActivity.this, GameMasterActivity.class); startActivity(intent); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗"); System.out.println(t); } }); } }); //RedAgentとして参加 Button mem1Button = findViewById(R.id.member1); mem1Button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("gametest"); ((Iris) getApplication()).setNickname("RedAgent"); ((Iris) getApplication()).setTeam("r"); ((Iris) getApplication()).setMaster(false); Call<List<Member>> call = roomsRest.getRoomMember("gametest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功:createDrawTest"); ((Iris) getApplication()).setMemberList(response.body()); Intent intent = new Intent(TestGameActivity.this, GameMemberActivity.class); startActivity(intent); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗:createDrawTest"); System.out.println(t); } }); } }); //BlueSpyとして参加 Button mem2Button = findViewById(R.id.member2); mem2Button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("gametest"); ((Iris) getApplication()).setNickname("BlueSpy"); ((Iris) getApplication()).setTeam("b"); ((Iris) getApplication()).setMaster(true); Call<List<Member>> call = roomsRest.getRoomMember("gametest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功:createDrawTest"); ((Iris) getApplication()).setMemberList(response.body()); Intent intent = new Intent(TestGameActivity.this, GameMasterActivity.class); startActivity(intent); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗:createDrawTest"); System.out.println(t); } }); } }); //BlueAgentとして参加 Button mem3Button = findViewById(R.id.member3); mem3Button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((Iris) getApplication()).setRid("gametest"); ((Iris) getApplication()).setNickname("BlueAgent"); ((Iris) getApplication()).setTeam("b"); ((Iris) getApplication()).setMaster(false); Call<List<Member>> call = roomsRest.getRoomMember("gametest"); call.enqueue(new Callback<List<Member>>() { @Override public void onResponse(Call<List<Member>> call, Response<List<Member>> response) { if (response.isSuccessful()){ System.out.println("通信成功:createDrawTest"); ((Iris) getApplication()).setMemberList(response.body()); Intent intent = new Intent(TestGameActivity.this, GameMemberActivity.class); startActivity(intent); } } @Override public void onFailure(Call<List<Member>> call, Throwable t) { System.out.println("通信失敗:createDrawTest"); System.out.println(t); } }); } }); //backボタン Button backButton = findViewById(R.id.fromgame); backButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(TestGameActivity.this, TestEnterActivity.class); startActivity(intent); } }); } }