Sergey
Sergey

Reputation: 963

Android : Tic tac toe game, need advice about structure

I am new in android development, and I need advice about structure.I want to develop Tic tac toe game, and have 3 images: 1 - 3×3 grid 2 - circle 3- cross.

My idea: I need some layout with background image(3×3 grid) and table 3 x 3 with ImageViews, after clicking on some position we load image(circle or cross) in our table.

Questions:

-First of all is my idea correct?

-I tried to set background with view.setBackgroundResource(res) but it looks not very good, grid(black colour) loading with background colour black ant is difficult to see something.

UPDATE: I found Tic tac toe game example in android sdk, ..\samples\android-8, maybe it helps to somebody

UPDATE: The best solutin is to use SurfaceView

update: If any body need it https://andoid-tictactoe.googlecode.com/

Upvotes: 1

Views: 2729

Answers (1)

user432209
user432209

Reputation: 20177

Your best bet is probably to use a Canvas and draw on it.

There's some great examples included with the SDK. Lunarlander, Jetboy, or maybe Snake.

Edit: Yes, you can. Well kind of...Think of it this way, the order hierarchy of what is displayed is based on the order in which it is drawn. If you did the following, the drawable would be visible over the background:

canvas.drawBitmap(yourBackgroundImage, 0, 0, null);
yourDrawable.setBounds(yourRect);
yourDrawable.draw(canvas);

if you reversed them, the drawable may or may not be visible depending on the background images transparency and size.

yourDrawable.setBounds(yourRect);
yourDrawable.draw(canvas);
canvas.drawBitmap(yourBackgroundImage, 0, 0, null);

Upvotes: 3

Related Questions