4 Replies - 2726 Views - Last Post: 08 December 2014 - 11:46 AM Rate Topic: -----

#1 M1hai   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 14

[C++ Builder 6]Moving pieces in Backgammon

Posted 07 December 2014 - 07:44 AM

Hello, I am an IT student and as part of my assignment in OOP I was given the task to design a simple game of Backgammon in C++ Builder 6 (the 2002 version). I've made a simple GUI the board and pieces are Bitmap Images...but I cannot move the pieces on the board. I tried to adapt some code that I found in a Chess game, but the results (oh dear, the pieces were moving in a chaotic manner). I've assigned the ids of the pieces as part of onmousedownEvent and the "incepeJoc" method is for the initial setup of the game: begin game. Any help and suggestions are very much appreciated!! Thank you!
class BkgBoard {
public:
bool empty;
int piesa;
void arrange (void){};
} board [12][10];

class Piese{
	int color;
	int value;
	bool inPlay;
} piesa[30];

int id;
int row, col;
int rowColToPixel[14]={32,96,160,224,288,352,464,528,592,656,712,776,0,812};

void mutaPiesa (int piesa, int col, int row){
		id=piesa;
	   int stg = rowColToPixel[col];
	   int sus = rowColToPixel[row];
		switch (piesa){
		//piese albe
		case(0):{MainForm->wpc1->Left=stg; MainForm->wpc1->Top=sus; break;}
		case(1):{MainForm->wpc2->Left=stg; MainForm->wpc2->Top=sus; break;}
		case(2):{MainForm->wpc3->Left=stg; MainForm->wpc3->Top=sus; break;}
		case(3):{MainForm->wpc4->Left=stg; MainForm->wpc4->Top=sus; break;}
		case(4):{MainForm->wpc5->Left=stg; MainForm->wpc5->Top=sus; break;}
		case(5):{MainForm->wpc6->Left=stg; MainForm->wpc6->Top=sus; break;}
		case(6):{MainForm->wpc7->Left=stg; MainForm->wpc7->Top=sus; break;}
		case(7):{MainForm->wpc8->Left=stg; MainForm->wpc8->Top=sus; break;}
		case(8):{MainForm->wpc9->Left=stg; MainForm->wpc9->Top=sus; break;}
		case(9):{MainForm->wpc10->Left=stg; MainForm->wpc10->Top=sus; break;}
		case(10):{MainForm->wpc11->Left=stg; MainForm->wpc11->Top=sus; break;}
		case(11):{MainForm->wpc12->Left=stg; MainForm->wpc12->Top=sus; break;}
		case(12):{MainForm->wpc13->Left=stg; MainForm->wpc13->Top=sus; break;}
		case(13):{MainForm->wpc14->Left=stg; MainForm->wpc14->Top=sus; break;}
		case(14):{MainForm->wpc15->Left=stg; MainForm->wpc15->Top=sus; break;}

		//piese negre
		case(15):{MainForm->bpc1->Left=stg; MainForm->bpc1->Top=sus; break;}
		case(16):{MainForm->bpc2->Left=stg; MainForm->bpc2->Top=sus; break;}
		case(17):{MainForm->bpc3->Left=stg; MainForm->bpc3->Top=sus; break;}
		case(18):{MainForm->bpc4->Left=stg; MainForm->bpc4->Top=sus; break;}
		case(19):{MainForm->bpc5->Left=stg; MainForm->bpc5->Top=sus; break;}
		case(20):{MainForm->bpc6->Left=stg; MainForm->bpc6->Top=sus; break;}
		case(21):{MainForm->bpc7->Left=stg; MainForm->bpc7->Top=sus; break;}
		case(22):{MainForm->bpc8->Left=stg; MainForm->bpc8->Top=sus; break;}
		case(23):{MainForm->bpc9->Left=stg; MainForm->bpc9->Top=sus; break;}
		case(24):{MainForm->bpc10->Left=stg; MainForm->bpc10->Top=sus; break;}
		case(25):{MainForm->bpc11->Left=stg; MainForm->bpc11->Top=sus; break;}
		case(26):{MainForm->bpc12->Left=stg; MainForm->bpc12->Top=sus; break;}
		case(27):{MainForm->bpc13->Left=stg; MainForm->bpc13->Top=sus; break;}
		case(28):{MainForm->bpc14->Left=stg; MainForm->bpc14->Top=sus; break;}
		case(29):{MainForm->bpc15->Left=stg; MainForm->bpc15->Top=sus; break;}
		}
}
void incepeJoc (void){
for (col=0; col<12; col++){
board[0][col].piesa = col + 0;
board[1][col].piesa = col + 12;
board[6][col].piesa = col + 24;
board[7][col].piesa = col + 32;
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: [C++ Builder 6]Moving pieces in Backgammon

#2 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1854
  • View blog
  • Posts: 6,676
  • Joined: 19-February 09

Re: [C++ Builder 6]Moving pieces in Backgammon

Posted 07 December 2014 - 12:19 PM

Are you allowed to use components such as TDrawGrid? You might be able to use it without showing a grid.

Think I would have something like :

class Cell 
{

};

class Board 
{
  Cell board[12][10];

};


Was This Post Helpful? 1
  • +
  • -

#3 M1hai   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 14

Re: [C++ Builder 6]Moving pieces in Backgammon

Posted 08 December 2014 - 09:36 AM

Yes, we are allowed to use TDrawGrid, we are allowed to use everything that C++ Builder 6 has to offer, but quite frankly I really don't know how to use the Draw Grid (I don't know how to add the pieces -- which are bmp nor do i know how to make them move on the grid), i also tried google, like a lot, for c++ builder (but there seems to be a lack of documentation, maybe because the software is outdated)... in the past I only used Visual Studio and MinGW for C++ and NetBeans for Java and most of my coding was not object oriented...that is why i took that approach in designing the moving of the pieces...
Was This Post Helpful? 0
  • +
  • -

#4 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1854
  • View blog
  • Posts: 6,676
  • Joined: 19-February 09

Re: [C++ Builder 6]Moving pieces in Backgammon

Posted 08 December 2014 - 11:31 AM

You have two options it seems, use TDrawGrid or drawing directly, you don't need to choose yet, you could evaluate each, even develop in parallel.

There is help in the IDE.

C++ Builder Programming

and the similar

Borland C++ Builder

It might be worth looking at Bitmaps (TBitmap).
Was This Post Helpful? 1
  • +
  • -

#5 M1hai   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-December 14

Re: [C++ Builder 6]Moving pieces in Backgammon

Posted 08 December 2014 - 11:46 AM

View Post#define, on 08 December 2014 - 08:31 PM, said:

You have two options it seems, use TDrawGrid or drawing directly, you don't need to choose yet, you could evaluate each, even develop in parallel.

There is help in the IDE.

C++ Builder Programming

and the similar

Borland C++ Builder

It might be worth looking at Bitmaps (TBitmap).


yes, thanks, those are the only websites that have something useful on c++ builder i used them a lot since I've been working on this project for a month, by the way I managed to get the pieces to move 80% better (better than nothing)...the problem was that i forgot to add the rows to my code (i used column coordinates for both column and rows) i've also made some changes to the begingame function, now at least they move where they are supposed to (most of the time anyway)..what i'm searching for now is a way to move a bitmap to specific coordinates when the player presses "New Game" (bpc1->Canvas->MoveTo(776,448); doesnt seem to work, bpc1 being the name of the bitmap - something like "black piece 1", anyway i tested that command on NewGame1Click event but it doesn't mvoe)

I'll continue working on the project as I have to present a beta version this week, and a final working version in January. Thank you very much for your support!! I'm still learning and dreamincode seems to be a very good and helping community!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1