• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor Porting Java Chess To Android... Advice on the UI?

Axel George

Lurker
Nov 27, 2017
4
0
Hi Jedi Masters,

I am taking an advanced Java class where the professor has decided to make the final project an Android Chess app. The good news is I've already written the Chess logic working in Java. The bad news is I have two weeks to figure out how to port that Java code into an Android app. The time crunch is the real problem here. I've been reading online documentation and working through tutorials, but I'm not making enough headway to hit my deadline. I need to bounce my general game plan off of a few experts and see if I'm on-track.

The first step is to design a UI. Obviously the main screen will need an 8x8 grid. Chess pieces will need to fit on the grid. My reading suggests the best approach is to create a custom View class... but I'm not sure about that. On the other hand, I've also read up on the gridView class, which at first glance, but doesn't look promising when I actually play with one in Studio.

Once the Chessboard is defined, I have to figure out how to place and move the pieces on squares. Without knowing what structure will represent the board, I can't plan that far ahead. Its frustrating.

I don't want anyone to give me a solution. If I had more time, I'd explore and research and explore these options in more detail. But I don't have time to spare. What I'm looking for is general advice like "using a View class should work" or "gridView isn't suitable for what you are looking for." A little advice like that will save me a LOT of development time. Thanks in advance for your consideration.
 
You're really up against it here.
If I was doing this, I wouldn't use a layout. I'd approach this by using 2D graphics to draw the board and place the piece images.
It should be fairly straightforward to draw a grid of coloured squares to represent the board, and place the pieces at specific locations. All the locations (squares) are known.
Good news is that there are plenty of tutorials on 2D graphics. You may even find an example of someone doing just what you want.
If you already have the logic to actually play the game, then that's a big help, and should be fairly easy to port that code into an app.
Good luck!
 
Upvote 0
You're really up against it here.
If I was doing this, I wouldn't use a layout. I'd approach this by using 2D graphics to draw the board and place the piece images.
It should be fairly straightforward to draw a grid of coloured squares to represent the board, and place the pieces at specific locations. All the locations (squares) are known.
Good news is that there are plenty of tutorials on 2D graphics. You may even find an example of someone doing just what you want.
If you already have the logic to actually play the game, then that's a big help, and should be fairly easy to port that code into an app.
Good luck!

Thanks, LV426... and great username!

No layouts, huh? That's great advice, thank you. I've seen documentation on "2D graphics" but I didn't realize that was a formal class or something. In fact, I assumed you HAD to use some kind of layout for this kind of work. (This is a problem with taking a class that tries to tack on an Android assignment at the end... I really don't have time to explore Android Studio and learn this kind of stuff by trial-and-error.)

Yeah, I already have all the code that supports the game. Currently, you can play a full game of Chess via a command-line interface. So I'm hoping the Android port is just a matter of dressing up my Chess game in graphics. Thanks!
 
Upvote 0
I assume your Chess accepts grid coordinates and post results? Did you figure out your 2D graphics to use?

Kf
Thanks for posting. Yes, my current Chess program would work with grid coordinates with relatively little translation. When you decide to move a Knight, for instance, the first thing the code does is calculate all possible squares to where that knight can move. It won't be hard to translate that function to grid coordinates.

I have not, however, figured out anything regarding 2D graphics. In fact, until making this post, I was stuck on trying to decide what layout to use. LV426 suggests that approach is a dead end.

When you say "figure out what 2D graphics to use," do you mean what graphics I'll use for white pawn, white knight, white bishop... black queen, black king? I'm not worried about that, if necessary I'll draw crude pieces in MS Paint or something. Or does your question refer to something else? Is "2D graphics" a module or design mode in Studio or something? I'm a total newbie in this area. Thanks!
 
Upvote 0
If you are looking to write some simple layout, I can suggest this: http://android.processing.org/tutorials/getting_started/index.html

Ok, this is what I can suggest. Run the above tutorial on your own time. If you get the first sketch setup and running on your device, then doing the chess game using that platform should be easy. Ok, maybe you need to be familiar with some examples of how the software works. unfortunately I am busy tomorrow but I could help on Friday or the weekend.

If you run the the first program above (dead simple program), then you have access to a graphical interface that you can modified to your needs. The graphical interface allows you to manage the graphics buffer directly. The second step is to learn about how to use the touch events. Third step would be to lay out a grid and do some panning, and zooming, and picking out squares from your grid. Last step is to map picked up squares with your chess module and process the new chess piece position. It sounds easy the way I put it.

Good news is that you can do all the game in Processing-java and then, with some minor modifications, you can port it to Android. You can add extra GUI elements but I wouldn't plan much on them with the limited time that you have.

-----------

To be able to do the tutorial above, you will need to download and run (no need to install) Processing. Check this page and run some of the examples there: https://processing.org/examples/ (Notice you do not need to work on Android mode but you can do it in java mode) At your leisure time, In the Processing IDE, go to the library manager, select MODES, and install the Processing one. Then follow the instructions in my first link.

Good luck and let me know if you follow this platform.

Kf
 
Upvote 0
If you are looking to write some simple layout, I can suggest this: http://android.processing.org/tutorials/getting_started/index.html

Ok, this is what I can suggest. Run the above tutorial on your own time. If you get the first sketch setup and running on your device, then doing the chess game using that platform should be easy. Ok, maybe you need to be familiar with some examples of how the software works. unfortunately I am busy tomorrow but I could help on Friday or the weekend.

If you run the the first program above (dead simple program), then you have access to a graphical interface that you can modified to your needs. The graphical interface allows you to manage the graphics buffer directly. The second step is to learn about how to use the touch events. Third step would be to lay out a grid and do some panning, and zooming, and picking out squares from your grid. Last step is to map picked up squares with your chess module and process the new chess piece position. It sounds easy the way I put it.

Good news is that you can do all the game in Processing-java and then, with some minor modifications, you can port it to Android. You can add extra GUI elements but I wouldn't plan much on them with the limited time that you have.

-----------

To be able to do the tutorial above, you will need to download and run (no need to install) Processing. Check this page and run some of the examples there: https://processing.org/examples/ (Notice you do not need to work on Android mode but you can do it in java mode) At your leisure time, In the Processing IDE, go to the library manager, select MODES, and install the Processing one. Then follow the instructions in my first link.

Good luck and let me know if you follow this platform.

Kf

...ahhh! Yes, that works! You're a genius, KF! If I was making any money off of this crazy enterprise, I'd send you half. :) many thanks!
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones