How can I make card game with AGS ?

Started by Meystari F, Wed 17/04/2019 21:24:24

Previous topic - Next topic

Meystari F

Has anyone here made a good card game with AGS? Like Black Jack or Solitaire?  :confused: :confused:

If so.  Would you be so kind and share a code or show me how you did it, please?  :-[


What I myself have done so far.  I created first a GUI and add made a sprites and  buttons for the cards  then I added one button wish I named bDeal.



And then I did this:


Code: ags
function bDeal_OnClick(GUIControl *control, MouseButton button)
{
if (Spil == 0)
{
BCards.Animate(VSPIL, 0, 5, eOnce);
Wait(40);
}
Spil++;

BCards.Visible = false;
BDSpil1.Visible = true;
BDSpil2.Visible = true;

BSpil1.Visible = true;
BSpil2.Visible = true;


  if(Vinningspil1 == 0){
   BDSpil1.Animate(VHJARTASPIL, 0, 0, eOnce)&&Heartace;
   BSpil1.Animate(VHJARTASPIL, 5, 0, eOnce)&&Heart6;
  BSpil2.Animate(VHJARTASPIL, 10, 0, eOnce)&&HeartGosi;
  }
  else if(Vinningspil1 == 1)
 {
   BDspil3.Visible = true;
    BDSpil2.Animate(VHJARTASPIL, 10, 0, eOnce)&&HeartGosi;
     BDspil3.Animate(VHJARTASPIL, 3, 0, eOnce)&&Heart4;
 }
 else if (Vinningspil1== 2)
 {   
   BDSpil4.Visible = true;
   BDSpil4.Animate(VHJARTASPIL, 12, 0, eOnce)&&HeartQueen;
   Display("You are Busted");
   
      }
    else if (Vinningspil1== 3)
    {

  BDSpil1.Visible = false;
  BDSpil2.Visible = false;
  BSpil1.Visible = false;
  BSpil2.Visible = false;
  BDspil3.Visible = false;
  BDSpil4.Visible = false;
  BCards.Visible = true;
  BCards.Animate(VSPIL, 0, 5, eOnce);
Wait(40);
BCards.Visible = false;
 BDSpil1.Visible = true;
  BDSpil2.Visible = true;
  BSpil1.Visible = true;
  BDSpil1.Animate(VHJARTASPIL, 0, 0, eOnce)&&Heartace;
   BSpil1.Animate(VHJARTASPIL, 5, 0, eOnce)&&Heart6;
  BSpil2.Animate(VHJARTASPIL, 10, 0, eOnce)&&HeartGosi;
  BDspil3.Visible = false;
  BDSpil4.Visible = false;
    }
 Vinningspil1++;
 }




selmiak

Some examples for cardgames made with AGS:
Magus: https://www.adventuregamestudio.co.uk/site/games/game/1564/
Hubris: https://www.adventuregamestudio.co.uk/site/games/game/1541/
Dungeon Hands: https://www.adventuregamestudio.co.uk/site/games/game/2219/

Maybe eri0 can help you or show you some of his code he used for dungeon hands.
Codingwise you probably store all cards in an array, shuffle the array and then pick cards one after the other. maybe add a counting variable to know how many cards are played and where in the array you are.

Meystari F

Thanks.  This eri0 may send me message if he is interest to help me if he is still here.

Ghost


eri0o

#4
@Fribby, I am not dead :P so the code for Dungeon Hands is open sourced on github.

https://github.com/ericoporto/DungeonHands
https://www.adventuregamestudio.co.uk/forums/index.php?topic=55546.0

I will briefly explain, so feel free to ask more details!

My approach for Dungeon Hands was to use three invisible characters with three inventories: Player 1 Hands, Table, and Player 2 Hands. There is an inventory item for each card in a deck - so if a card has two copies, two items exist. This simplified actually showing the cards on screen and allowed using Drag and Drop module to make moving cards around more natural.

I also had an array for each deck and used the items ID to be able to figure out which cards are in deck and correspond to each inventory items. All of this is coded in a script responsible for the "physical" existence and consistency of the cards, and also responsible to be able to shuffle the deck and draw cards.

Now that the cards exist, a different script has to take care of rules. The rules say who starts, what is a turn, and control the symbol to values mapping of the cards.

I would say to first figure out the "physical" part of a virtual deck of cards and then later making the rules work will be a lot easier, specially because you can visually debug :)

Meystari F

Thanks EriOo.  First of all I'm glad you are not dead.    :grin:

I shall check on this files later today that
you shared and try to see if it can be useful for me.

I have tried your game.  And I'm still learning how to play it. I have never play card games like this before. It looks very good.

All I was asking was just a simple card game like based on Leisure Suit Larry 1.

Thanks.


eri0o

Don't know if helpful, but for reference:

Randomizes sounds for the card drawing and stuff
https://github.com/ericoporto/DungeonHands/blob/master/CardSound.asc

Resizes the cards logical width to allow holding more cards in hands than screen limit
https://github.com/ericoporto/DungeonHands/blob/master/InventoryMonitor.asc

Solves the "physical existence" of cards:
https://github.com/ericoporto/DungeonHands/blob/master/Cards.asc

Takes care of rules and turns:
https://github.com/ericoporto/DungeonHands/blob/master/Play.asc

The hacky place where I check for drag and drop events  :-\
https://github.com/ericoporto/DungeonHands/blob/master/room5.asc

Process clicked on a deck then draw card
https://github.com/ericoporto/DungeonHands/blob/master/GlobalScript.asc


Meystari F

Thanks again.  I'm going to study and learn more after the weekend.

I will show my progress on a video later after few days after that.




SMF spam blocked by CleanTalk