Archive for June, 2009

Summer with Qt and KDE

June 15, 2009

This is my second writing. The first one was about my GSOC application and the way I would like to work. Now I would like to tell about my work, and the problems I faced to implement it so far.

I applied at GSOC with my knowledge on C++ and other programming languages. Working GUI programming with C++ always seemed a bit tough for me. Though, woking for GUI in Java, seemed nice to me, I can’t help myself in C++ (GOD knows, Why?).

I had a little knowledge about Qt before being accepted in GSOC. So, I thought Qt will be very tough for me to learn (because of my bitter experience with C++ GUI). But, I found it quite easy to start with. The thing I like most is the organization of QT, nice and useful.¬† Qt Assistant has made my life easy. I haven’t seen such nice reference before. Working with QtCreator made my coding simple, and the Qt Examples and demos are superb!!

I found aporoximately all the concepts I gathered on my university courses, implemented in Qt. But, I never expected STL and java like list, vector classes here. Thanks to the Qt Developers.

I found people here (KDE and QtForum) very useful. Tomaz Canabrava, my mentor, always tries so that I can write nice object-oriented code, not a working code only. I remember – in my university courses, I implemented a game with Java, but my teacher was mostly interested in the output, not my coding style. I would like to give an example about this. In C:

#define PI 3.141592654 — is fine, define the constant you need to use.

But, from the perspective of C++, we should use const here. I never thought about these little things. I went on coding define all the places. But, I learnt from my mentor that it is a bad practice. The Qt forum is also very useful to me:

http://www.qtcentre.org/forum

I thought, the code I am writing will only be observed by my mentor. But, only someday before, I got a mail from Stefan Majewsky, where he told me to include license info. Also, he noticed me a little problem, I was using min macro of mine, but, there is qMin in QtGlobal.

Now this is time to give a overview of my GSOC Program, how it is going ….

My GSOC Program:

As I mentioned in my previous writing, I am making a game Mancala. I have made a board of the game (not complete) and now working on the logic part.

Starting

The image shows here the board I made. It is a 2*6 mancala board(6 cups on each side) with 2 Storages(big rounded rectangles). This board corresponds to many mancala games like Kalah(USA), Oware(Africa) etc. The lower row is a player’s side and upper row is another player’s side. The sowing is counter-clockwise. At the starting each cup contains 4 stones, which will change at the game continues. The stones will move within cups, but once any put in storage, will never be back from there. The numbers show the stone number in every cup, shown for the player’s ease. When, there is no stone, no number is given. When the ball will move to storage, number will also be shown here. The image below shows a image after some sowing has been done:

GamePlay

While implementing, I faced some problem. At first, I had to make a perfect object-oriented implementation. I made Board, Cup,Kalah(storage), Stone classes and a perfect parent child relationship among them. My mentor helped me a lot to figure out my problems. I have to learn QGraphicsView, QGraphicsScene,QGraphicsItem etc and clear my concept about GraphicsViewFramework to do this. One thing, that was very nice to me is setZValue(), the way it works seemed nice to me. I had some problem with the zValue also. At some point, my QGraphicsSimpleTextItem(number shown here) was under the ball, and from the parent child relationship of the classes , I solved it.

I have started working on the logic part, and I believe I can come up with a working game within some days¬† ….

Advertisements