Commit 8d3ff8c7 authored by Shaun Burch's avatar Shaun Burch 💻

#3 Start new game, fix draw & win if winning on final move

parent 6721f061
Pipeline #22998109 passed with stages
in 10 minutes and 15 seconds
......@@ -14,6 +14,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;
......@@ -27,7 +28,7 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
private Game mGame;
private Disposable mGameUpdates;
private List<Player> mPlayers = new ArrayList<>();
private List<Player> mPlayers;
@BindView(R.id.toolbar)
Toolbar mToolbar;
......@@ -35,6 +36,9 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
TextView mPlayerOne;
@BindView(R.id.name_player_2)
TextView mPlayerTwo;
@BindViews({R.id.cell_A1, R.id.cell_A2, R.id.cell_A3, R.id.cell_B1, R.id.cell_B2, R.id.cell_B3, R.id.cell_C1,
R.id.cell_C2, R.id.cell_C3})
List<ImageView> mBoardViews;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -43,7 +47,7 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getPlayer(1);
newGame();
}
@Override
......@@ -78,8 +82,17 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
*/
@OnClick(R.id.fab)
void onFabClicked(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
Snackbar.make(view, "Start a New Game?", Snackbar.LENGTH_LONG)
.setAction("Yes", v -> newGame()).show();
}
private void newGame() {
// Clear players
mPlayers = new ArrayList<>();
// Clear board
ButterKnife.apply(mBoardViews, (view, index) -> view.setImageDrawable(null));
// Get get players
getPlayer(1);
}
private void getPlayer(int player) {
......@@ -128,14 +141,16 @@ public class MainActivity extends AppCompatActivity implements AddPlayerDialog.A
private void checkForGameOver(Update update) {
// TODO Disable board on win
// Check for draw move
// Check for winning move
if (update.isWinner()) {
// TODO Dialog
String message = String.format("Player %1s has WON!!", update.getPlayer().getName());
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
return;
}
// Check for winning move
// Check for draw move
if (update.isDraw()) {
// TODO Dialog
Toast.makeText(this, "We have a DRAW!!", Toast.LENGTH_LONG).show();
......
......@@ -39,6 +39,6 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
app:srcCompat="@drawable/ic_new_game" />
</android.support.design.widget.CoordinatorLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment