Top three cards, use two classes, a "play card", a "card", very convenient to simulate three games, can set the number of people playing, or set the number of players, On this basis, it is very convenient to make a variety of playing games!
Two categories of source code:
#pragma overce # include "Vector" Using Namespace Std; Typedef Vector
Int paiououne; vector
Pukepai (void); ~ pukepai (void);
// "Brand" member function
#include "stdafx.h"
#include "Time.h" #include "./pukepai.h"
Pukepai :: pukepai (void) // Initialize a plate {paizhi = -1; Paicount = 52;
// sort (vectestscore.begin (), vectestscore.end ()); // & vectestscore.Size = 9; puke.assign (52, 1); for (vi = puke.begin () 1; vi! = puke .end (); vi )
* vi = * (vi-1) 1;
} void pukepai :: shuzhi () // Assign the value to the card, then delete the card {
Paicount -;
Paizhi = * vi; puke.ed (vi);
}
Void Pukepai :: Paixianshi (Char * PAIMIAN) // Returns a brand color and card with a day you see.
Char BUF [32] = "黑"; if (Paizhi> 13 && Paizhi <27) {Paizhi = Paizhi-13; strcpy (buf, "red peach");
} IF (Paizhi> 26 && Paizhi <40) {Paizhi = PaizHI-26; STRCPY (BUF, "Square");} IF (Paizhi> 39 && PaizHi <53) {Paizhi = PaizHi-39; Strcpy (BUF, "Grass Flower"); }
IF (Paizhi> 10 || PaizHI == 1) {IF (PaizHi == 11) STRCAT (BUF, "J"); if (PaizHi == 12) STRCAT (BUF, "Q"); if (paizhi == 13) STRCAT (BUF, "K"); if (paizhi == 1) STRCAT (BUF, "A");} else {Itoa (Paizhi, xianshizifu, 10); strcat (buf, xianshizifu);} if (PAIMIAN ! = NULL) STRCPY (PAIMIAN, BUF);
} int pukepai :: chupai (char * paimian) // Make a draw {IF (paicount == 0) // If a panel has already finished {RETURN-1;} vi = puke.begin (); vi = rand ()% Paicount; // randomly touched shuzhi (); // Which one is in, and deletes the card paixianshi (PAIMIAN); // Return the color and cards in touch
Return Paizhi;}
Pukepai :: ~ pukepai (void) {}
// "Player" header file
#pragma overce
Class mopai {
PUBLIC: INT PAI1; Char BUF1 [8]; int Pai2; Char BUF2 [8]; int Pai3; Char BUF3 [8];
INT leixing ();
}
// "Player" member function
#include "stdafx.h" #include "./mopai.h"
INT MOPAI :: Leixing () {Int tonghuaflag = 0;
Char buftemp1 [8] = ""; char buftemp2 [8] = ""; char buftemp3 [8] = ""; int TEMP = 0, TEMP1 = 0, TEMP2 = 0, TEMP3 = 0; TEMP1 = PAI1; // Assign the three cards to three temporary variables TEMP2 = PAI2; TEMP3 = PAI3;
IF (Temp1 IF (Temp1 IF (Temp2 STRNCPY (BUFTEMP1, BUF1, STRLEN ("黑")); Strncpy (buftemp2, buf2, strlen); strncpy (buftemp3, buf3, strlen); if (strCMP (buftemp1) , buftemp2) == 0 && strCMP (buftemp2, buftemp3) == 0) {tonghuaflag = 1;} // Touching the same flower, does not return, continue to judge, see if it belongs to the same flush IF ((Temp1-Temp2 == 1) && Temp2-Temp3 == 1)) // If the three cards are decremented in turn, the basic rules that conform to the flush { IF (tonghuaflag == 1) {return 1; // Touched with flush} else {return 2; // } if (tonghuaflag == 1) // If the above is not returned, then it returns to the same flower return 3; if (Temp1 == Temp2 && temp2 == TEMP3) // If the three cards are finished, different colors, belong to three head Return 0; if (Temp1 == Temp2 || Temp2 == Temp3 || TEMP1 == Temp3) Return 4; // Touching a pair Return -1; // neither belongs to the same flush, nor does it belong to three heads } // Complete code download: