Jay
Jay

Reputation: 117

Creating Connect4 in Android

I'm trying to create an Android app to play Connect 4 (Four In A Row, etc). As I'm new to Android dev I created a basic Java application to cope with the logic, which plays connect4 using a 2D array and just uses println to print the array to the console which shows the board.

My question is in my game activity what would be the best way to create a 'board' and have it so I can update it to show the position of counters throughout the game; should I create a canvas object, butcher a table layout, or do something else entirely.

Apologies if this is a silly question; I have very limited Android experience.

Many thanks.

Upvotes: 1

Views: 3539

Answers (2)

wseme
wseme

Reputation: 835

Agreed, as 4x4 grid could work if that is what you want since you have limited android experience. You can really make a board/grid in multiple ways. I would suggest making sure you know a little about the UI and the android activity lifecycle before you start diving into something. Eventually you will like to add additional UI elements such as score, player's turn etc.

UI: http://developer.android.com/guide/topics/ui/index.html

Lifecycle: http://developer.android.com/training/basics/activity-lifecycle/index.html

Here is a grid tutorial instead of opening another view, just update the one with a piece/color or whatever GridView tutorial: http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/

Upvotes: 0

MillaresRoo
MillaresRoo

Reputation: 3848

As the board is always the same (4x4) you could use a GridLayout with 4 cols and 4 rows. Put an ImageView in every cell and modify it following the players touches.

Upvotes: 1

Related Questions