Creating Connect4 in Android - 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.

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.

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/

Related

how to create a crossword puzzle shape in android

I want to create a crossword puzzle using android studio. the problem that I run into is I can't figure out a good way to draw the crossword puzzle the crossword
upon selecting a word from that shape. the user will access an interface that is designed specifically for that word. where to enter the answer
The problem I have is how to actually create that crossword shape, especially since I need it to be created dynamically afterwards based on the supplied data.
After 15 days of research all I can find are those possibilities:
Using Table layout with each cell representing a character. But this approach is not appropriate and not optimate and create many problems.
Using GridView with the unused cells set to be invisible. this is better but I think there is a better way than creating Grids only to set most of it to invisible.*
**I am sure there is a better way, but can't figure it out.
I know I have to give a code sample for what I have but I can't even do that till I know what approach I need to create this. If there is any suggestion to make my question clear that will be welcomed as well.
Neither. This calls for custom view for the word grid. While you can probably get it to work without one, it's going to look very amateurish, and you're going to be very hacky. Instead, you'll want a totally custom view doing its own keyboard input handling. Unless this is like a school project where looks and UX don't matter and you just need it done.

Creating a dynamic/complex Android viewText + editText layout

I'd like to do something a little complex for my android application, and I'm struggling a little.
Overview -
I'm creating a game where the player is given a sentence with some words blanked out, and they must fill in the gaps.
'22 P____ on a F____ P____' becomes '22 Players on a Football Pitch'
'J_____ B_____ is 007' - 'James Bond is 007',
and so forth.
I'm having trouble laying out the textViews + editText's in a way that I like. Their are lots, and lots of these questions - so many that I don't want to hand code a solution.
I want to dynamically create the textViews + the editViews - from the question I pass it. I can create them just fine, it's the adding to the final view I am struggling with - all of the items are bunched into one corner! A linearLayout changes that, but then it's a single element on each line.
I've tried looking online - but I'm not convinced I'm looking at any of the right materials.
What I want is to create something exactly like the picture below (sorry it's so huge) - I think I want to create a wrapper of sorts for all the separate elements (so it lays out nicely) or a make my own custom view class(?) - but I really am unsure of how to progress - so any advice would be great.
Thank you
I had a similar situation where I wanted to have a list of names that would go side-to-side if possible, but if a name was long to begin on the next line.
I played around with a library called android-flowlayout. It has good examples and is fairly easy to customize.

A view for a game without a layout

I'm at the beginning of my development for my game and I have a basic question.
Is the layout necessary for displaying a view?
I have the method which allows me to make the toolbar disappear and set the view screen wide, but it seems a bit useless to do so.
Besides in the snake sample provided in the sdk, the views are merged without a layout.
So, which one is the best practice.
And if it's the layout-less solution, how to do for a unique view to display?
Thanks.
Well, I am as new as you are too, but as far as I have searched and learned online and with a few examples, all I can say is, NO. Game programming does not need any xml layouts. For developing a game, you need to first create a good basic framework. All the views, sprites, actions, audio, etc... is created at background.
This is a very nice tutorial to start with.
It depends on lots of things, but yes you don't need to create an XML layout. Pay attention to the word XML. You can create a custom class which extends SurfaceView and work in cooperate with Thread to do the update. So in this case you just need to set your Activity's Content View to this subclass of SurfaceView. But by using SurfaceView you have a raw of context which means you should do everything from stratch, e.g you should implement your own button.
Beside this it depends on the engine/framework you use too. But for SurfaceView/Canvas API the lines I mentioned above is valid.

MvxListView in Android with MvvmCross

I'm using MvvmCross v3 and I have a little problem with list in Android.
I actually have a Mvx.MvxListView who works well, but I'm working on tablet, and ListView is a little bit inapropriate. So I want to have a control like WrapPannel in XAML to have more than one item in a row.
How can I have this kind of control?
Thanks
There are two challenges here:
1. Find or make the control you want
The first is really up to you and your UX/design team to do - although people might be able to suggest apps and projects which might help. When choosing a control always be careful to understand it's memory use - especially:
whether it virtualises the UI reusing cells (like a list does)
or whether it creates a cell for every item even if the item is not visible (like a SL WrapPanel does?)
2. Add data-binding to it
This second step is generally quite simple to do - take a look at one of the Mvx layout controls and see how it is converted for databinding - e.g. https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Droid/Views/MvxLinearLayout.cs
You can generally just cut-and-paste this code over to your new type.
For more on subclassing existing types, also see N=18 in the video series - http://slodge.blogspot.co.uk/2013/05/n18-android-custom-controls-n1-days-of.html - this shows subclassing of a TextView
For a wrappanel, I did previously adapt and use one of #CheeseBaron's ports - FlowLayout - see http://slodge.blogspot.co.uk/2013/01/an-mono-for-android-wrappanelflowlayout.html. However, this has not been updated for v3 - if you do update it, it'd be great if you shared the results back.

android: how to create multiply views screen?

I want to create an activity, which shows a question with 4 answers, and at the bottom of the screen i want to place a timer.
I have already found timer example, and i created a question with the answers. the problem that they are 2 different projects and activities, and i am looking for the best way to implement it. i think i can't show 2 activities on one screen, but i can show 2 views or shell i use the ViewGroup, or maybe to copy-paste one of the activities code to another ( its the easiest way but probably the most ugliest way to implement it).
please tell me what is the best way, that i will study and not to waste time to study all the ways and only then to choose one of them.
welcome to StackOverflow.
You are correct in that you cannot display two activities at once. You must instead look into how layouts work in Android by reading some tutorials on the Android developer guide.
For your layout, I would recommend using a LinearLayout with four TextView objects inside it containing the questions (and perhaps your EditText objects below them) as well as your timer. Make sure they are all inside a ScrollView so the software keyboard doesn't force it all to be squeezed up. This is how I would approach it, but I encourage you to read about how layouts work and use the XML resources.
The Notepad tutorial is an excellent way to get started with views and text entry, as well as using SQLite databases.

Categories

Resources