Ejemplo n.º 1
0
Deck::Deck(QObject *parent) :
    QObject(parent)
{
    //set up the development deck; first cards to be added are the KNIGHT cards
    for(int i = 0; i < 14; i++)
    {
        DevCard* card = new DevCard(DEVELOPMENT::KNIGHT, "Move the robber. Steal 1 resource card from the owner of an adjacent settlement or city.");
        deck.push_back(card);
    }
    //next add 5 VICTORY cards
    for(int i = 0; i < 5; i++)
    {
        DevCard* card = new DevCard(DEVELOPMENT::VICTORY, "1 Victory Point!");
        deck.push_back(card);
    }
    //next add 2 YEAR_OF_PLENTY cards
    DevCard* card1 = new DevCard(DEVELOPMENT::YEAR_OF_PLENTY, "Take any 2 resources from the bank. Add them to your hand. They can be 2 of the same resource or 2 different resources.");
    DevCard* card2 = new DevCard(DEVELOPMENT::YEAR_OF_PLENTY, "Take any 2 resources from the bank. Add them to your hand. They can be 2 of the same resource or 2 different resources.");
    deck.push_back(card1);
    deck.push_back(card2);
    //next add 2 MONOPOLY cards
    DevCard* card3 = new DevCard(DEVELOPMENT::MONOPOLY, "When you Play this card, announce 1 type of resource. All other players must give you all their resource cards of that type");
    DevCard* card4 = new DevCard(DEVELOPMENT::MONOPOLY, "When you Play this card, announce 1 type of resource. All other players must give you all their resource cards of that type");
    deck.push_back(card3);
    deck.push_back(card4);
    //next add 2 ROAD_BUILDIN cards
    DevCard* card5 = new DevCard(DEVELOPMENT::ROAD_BUILDING, "Place 2 new roads as if you had just built them.");
    DevCard* card6 = new DevCard(DEVELOPMENT::ROAD_BUILDING, "Place 2 new roads as if you had just built them.");
    deck.push_back(card5);
    deck.push_back(card6);

    //shuffle this deck so that they are in a random order
    ShuffleDeck();
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------------
// Reset - Return all cards to the deck.
//------------------------------------------------------------------------------
void CardManager::Reset(void)
{
    int size;

    if ( talon->GetSize() > 0 )
        TransferCards(talon, deck, talon->GetSize());

    TransferCards(cpuDiscards,    deck, cpuDiscards->GetSize());
    TransferCards(playerDiscards, deck, playerDiscards->GetSize());

    if ( cpuTrick->GetSize() > 0 )
        TransferCards(cpuTrick, deck, cpuTrick->GetSize());

    if ( playerTrick->GetSize() > 0 )
        TransferCards(playerTrick, deck, playerTrick->GetSize());

    size = playerHand->GetSize();

    // Remove cards from the player hand.
    for ( int i = 0; i < size/3; i++ )
    {
        TransferCards(playerHand, deck, 3);
    }

    if ( playerHand->GetSize() > 0 )
        TransferCards(playerHand, deck, playerHand->GetSize());

    size = cpuHand->GetSize();

    // Remove cards from the cpu hand.
    for ( int i = 0; i < size/3; i++ )
    {
        TransferCards(cpuHand, deck, 3);
    }

    if ( cpuHand->GetSize() > 0 )
        TransferCards(cpuHand, deck, cpuHand->GetSize());

    size = previousTricks->GetSize();

    // Remove cards from the previous tricks.
    for ( int i = 0; i < size/3; i++ )
    {
        TransferCards(previousTricks, deck, 3);
    }

    if ( previousTricks->GetSize() > 0 )
        TransferCards(previousTricks, deck, previousTricks->GetSize());

    ShuffleDeck();
}
Ejemplo n.º 3
0
void Player::SetUpGame()
{
  //shuffle deck
  ShuffleDeck();

  //start hand contains 2 cards
  for (int i = 0; i < 2; ++i)
  {
    if(!p_card_deck->IsEmpty())
    {
      DrawCard();
    }
  }
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------------
// Initialize - Initialize the Cards and CardArrays held by this manager.
//------------------------------------------------------------------------------
void CardManager::Initialize(Scene* scene)
{
    // Get Rects for card array placement.
    QRectF* rect   = scene->GetTrickArea();

    // Initialize the CardArray member variables.
    deck           = new CardArray(CardArray::DECK,
                                   rect->x()+rect->width()/2,
                                   rect->y()+rect->height()/2);
    talon          = new CardArray(CardArray::TALON,
                                   0,
                                   rect->y()+rect->height()*0.25);
    playerHand     = new CardArray(CardArray::PLAYERHAND,
                                   (rect->x()+rect->width())*0.57,
                                   scene->GetHeight()-170);
    cpuHand        = new CardArray(CardArray::CPUHAND,
                                   (rect->x()+rect->width())*0.57,
                                   10);
    playerDiscards = new CardArray(CardArray::PLAYERDISCARDS,
                                   rect->x()+rect->width()+30,
                                   rect->y()+rect->height()*0.65);
    cpuDiscards    = new CardArray(CardArray::CPUDISCARDS,
                                   rect->x()+rect->width()+30,
                                   rect->y()*0.4);
    playerTrick    = new CardArray(CardArray::PLAYERTRICK,
                                   (rect->x()+rect->width())*0.6,
                                   (rect->y()+rect->height())*0.7);
    cpuTrick       = new CardArray(CardArray::CPUTRICK,
                                   (rect->x()+rect->width())*0.6,
                                   (rect->y()+rect->height())*0.4);
    previousTricks = new CardArray(CardArray::PREVIOUSTRICKS,
                                   rect->x()*0.45,
                                   10);

    // Initialize the timer to allow animation to finish before informing of
    // state changes.
    transitionTimer = new QTimer();
    transitionTimer->setSingleShot(true);

    // Initialize all the cards used in the game and add them to the deck.
    InitializeCards();

    // Shuffle the deck.
    ShuffleDeck();

    // Add the cards (initially in the deck) to the scene.
    AddCardsToScene(scene);
}
Ejemplo n.º 5
0
int main(int argc, const char * argv[])
{
    int game = 0;
    char ch,response;
    while(game==0)//continues until user choses not to continue anymore
    {
        printf("Do you want a new name? (Y or N)");
        scanf("%c",&ch);//scans for whether new name or not
        fflush(stdin);
        if(ch=='Y'||ch=='y')
        {
            printf("Enter new name: ");
            scanf("%s",username);//scans for new name
            fflush(stdin);
        }
        printf("\n\nGame begins between Computer and %s\n\n",username);
        srand((int)time(NULL));
        printf("Deck of Cards\n\n");
        CreateDeck();
        for(i=1;i<=4;i++)
        {
            for(j=1;j<=13;j++)
            {
                if(deck.suit[j+(i*13)] == 'C' && deck.face[j+(i*13)]== 12)//removes queen of clubs
                {
                    deck.suit[j+(i*13)] = NULL;
                    deck.face[j+(i*13)] = 0;
                }
            }
        }
        printf("Deck of Cards after one queen is removed\n\n");
        for(i=0;i<4;i++)
        {
            for( j=1;j<=13;j++)
            {
                if(deck.face[j+(i*13)]!=0)
                    printf("%c%d ",deck.suit[j+(i*13)],deck.face[j+(i*13)]);//prints new deck without C12
            }
        }
        printf("\n\n");
        ShuffleDeck();//calls shuffle deck function
        DealCards();//calls deal cards function
        RemovePairs();//calls remove pairs function
        PairSearch();//calls pair search function
        c=0;
        wins=fopen("wins.txt","w");//opens wins.txt for writing
        for(i=0;i<k;i++)
        {
            if(user.face[i]!=0)//if user has a card c updates
                c++;
        }
        if(c==0)
        {
            fprintf(wins,"%s\tWins\n",username);//prints name	 wins in wins.txt
            printf("Computer loses. %s Win!!!\n\n",username);//prints computer loses and player wins in program
        }
        else
        {
            fprintf(wins,"%s\tLoses\n",username);
            printf("%s loses. Computer Wins!!!\n\n",username);
        }
        fclose(wins);
        printf("Would you like to play again?(Y or N)");//asks if want to play again
        scanf("%c", &response);
        if(response== 'Y'||response=='y')//if yes stays in while loop
        {
            game=0;
        }
        else//if no exits while loop
        {
            game =1;
        }
        fflush(stdin);
    }
    return 0;
}
Ejemplo n.º 6
0
void StartGame(ArrayofPlayer *T)
{
	String opt,pesan,Card,nama;
	char c;
	Dataplayer Player;
	Deck D;
	Kartu C;
	int i,j,id,x,y,stat,g,ids,tmp,Rockfall_Counter;
	boolean End,alert,Sudah_Ambil,Keluar_Kartu,help;
	i = 0;
	AcakKarakterPlayer(T);
	End = false;
	alert = false;
	Sudah_Ambil = false;
	Keluar_Kartu = false;
	Rockfall_Counter = 2;
	help = false;
	CreateEmpty(&D);
	DefaultDeck(&D);
	ShuffleDeck(&D);
	DeckReady(&D);
	BagiKartu(T,&D);
	Board_Init(5,5);
	do {
		clrscr();
		canvas();
		if (help){
			GameHelp();
			help = false;
			clrscr();
			canvas();
		}
		Board_Print();
		id = i % NbPlayer(*T);
		Player = NamePlayer(*T,id);
		ShowKartuPlayer ((*T).Player[id]);
		DrawPile(!IsEmpty(D));
		ShowPlayerList(*T);
		if (IsEmpty(D)){
			Sudah_Ambil = true;
		}
		if (alert){
			gotoxy(5,35);
			printf("%s",pesan);
			alert = false;
		}
		x = 114;
		y = 1;
		for (j=0;j<27;j++){
			gotoxy(x+j,y);
			printf("=");
			gotoxy(x+j,y+3);
			printf("_");
			gotoxy(x+j,y+35);
			printf("=");
		}
		x = 139;
		y = 2;
		for (j=0;j<34;j++){
			gotoxy(x,y+j);
			printf("||");
		}
		gotoxy(5,34);
		printf("%s >> ",Player.Name);
		EmptyStr(opt);
		scanf("%s",opt);
		if (StrEq(opt,"putonboard")){
			do {
				scanf("%c",&c);
			} while(c == ' ');
			EmptyStr(Card);
			if (c != '\n'){
				scanf("%[^\"]s",Card);
				scanf("%c",&c);
			}
			scanf("%d %d",&x,&y);
			scanf("%d",&stat);
			if ((*T).Player[id].Condition == Disabled){
				alert = true;
				EmptyStr(pesan);
				CopyStr("Anda dalam kondisi Disabled",pesan);
			}else if (Keluar_Kartu){
					alert = true;
					EmptyStr(pesan);
					CopyStr("Anda sudah mengeluarkan kartu",pesan);
			}else{
				if (TakeKartufromPlayer(T,id,Card,&C)){
					if (C.ID <= 16){
						if (stat == 180){
							g = (((C.Guna>>2)&3)+((C.Guna&3)<<2) & 15) + (C.Guna & 16);
						}else{
							g = C.Guna;
						}
						tmp=Board_CekPut(x-1,y-1,g);
						if (tmp>0){
							Board_PutCard(x-1,y-1,g);
							if ((Board_Win==-1)&&(Rockfall_Counter)){
								Board_Win=0;
							}
							Keluar_Kartu = true;
						}else{
							FillKartuonPlayer(T,id,C);
							alert = true;
							EmptyStr(pesan);
							switch(tmp){
								case 0: CopyStr("Koordinat di luar papan permainan",pesan);
										break;
								case -1:CopyStr("Posisi target sudah ada kartu lain",pesan);
										break;
								case -2:CopyStr("Kartu tidak terhubung dengan kartu Start",pesan);
										break;
								case -3:CopyStr("Bentuk kartu salah",pesan);
										break;
							}
							//CopyStr("Posisi atau kartu path tidak valid",pesan);
						}
					}else{
						FillKartuonPlayer(T,id,C);
						alert = true;
						EmptyStr(pesan);
						CopyStr("Bukan kartu path",pesan);
					}
				}else{
					alert = true;
					EmptyStr(pesan);
					CopyStr("Kartu tidak ada",pesan);
				}
			}