Recent

Author Topic: Card Games  (Read 5328 times)

TheBlackSheep

  • Jr. Member
  • **
  • Posts: 93
Card Games
« on: April 08, 2012, 02:22:02 pm »
Hi,

I thought I'd try and get my kids developing some games and thought a good starting place would be a simple card game.  Unfortunately, I couldn't find any Lazarus libraries containing card components (are there any?) - I modified a couple of Delphi sources to make them work on Lazarus and started to develop a cribbage board component but wondered if there was anything out there I hadn't managed to locate that did something similar (I don't really want to reinvent the wheel if there something already available). 

I know there are full graphics/games libraries that will allow more control over a full canvass but it's probably overkill and just wanted a simple form based component (as the card components are) - my idea was to load an background image of a board (and it really could be anything here) and then show the players' positions on here by overlaying other images on top at specific locations to represent the position in the game.  In the cribbage board case it's simply a list of co-ordinates of the positions of the pegs on the board.  A board could be any shape (like the one attached);  the players position is simply the item number of the collection item - i.e. scoring a point moves the peg forward to the next coordinate.

I'm currently holding the list of coordinates as float percentages (X & Y) of the size of the image in a  TCollection.  That way if you resize the image it sort of still works although the player position marker really needs to scale as well.  I'm using the BGRABitmap to display the images currently - seems to work fine but might also be overkill for this.  It might work better to store TRect's rather than TPoints being mapped that way the size of the marker would also scale.

In theory any image could work with multiple containers holding various image positions that could be overlaid at their relevant co-ordinates - a simple snakes and ladders game for example would just keep the coordinates of the players' counters (although some modification might be necessary for multiple counters on the same square) but a monopoly game might need to replicate various images at various positions (houses, hotels etc). 

The idea is really just a 2d map with containers holding the various markers that could be shown or removed so could have a multitude of uses but just wanted to know if anyone had seen something that has this functionality already...

TheBlackSheep

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Card Games
« Reply #1 on: April 08, 2012, 04:50:31 pm »
You may want to have easiest possible time for yourself when handling the cards. I would make myself a procedure like DrawCard(x, y, angle, scale: integer; backside: boolean), drawn centered on the point X, Y. Maybe you don't even need the scale parameter, if the graphics are so simple. But i guess most card games can rotate the cards at least in all 90 degrees.

 

TinyPortal © 2005-2018