Small game developed with C language

zhaozj2021-02-16  51

/ ********************************************* CopyRight (c) 2004-2005 Vision, Math, NJU .File name: guest_card.cppauthor: Vision Version: 1.0 Data: 23-2-2004description: Give you 9 cards, then let you remember the card in your heart, then the computer group let you guess your card in the first Several groups, then guess the card you remember. Her: a small magic history from children: modification history ********************** *************** /

#include #include #include #include #include

#define cardsize 52 / * total number of cards * / # define suitsize 13 / * One color card number * /

/ * Poker Structure * / TypeDef struct card {char val; / * Size * / int Kind: 4; / * Poker's color * /} Card;

/ ************************************************** Function: // riffle description: // Slip, then randomly get 9 cards, require nine cards that can't be repeated. Calls: // caled by: // main () Table access: // Modified table ( This item only involves the database that involves database operations) Table updated: // (this item only involves the database operation) input: // card card [], the INT Size structure array size Output : // RETURN: // void Others: // This function modifies the value of Card [], I hope that nine random BUG: // This function has bug, sometimes two identical cards, waiting to be revised *** ****************************************************** / VOID RIFFLE Card * cards, int size);

/ ************************************************** Function: // show description: // Displays the contents of the array calls: // called by: // MAIN () Table access: // Modified table (This item only involves the database operation) Table Updated: / / Modified table (this only for programs involved in the database) INPUT: // card * card structure pointer, the size of the INT Size structure array Output: // return: // void Others: // *** ***************************************************************** / VOID SHOW Const Card * Cards, int size);

/ ************************************************** Function: // grouping description: // Put 9 cards in 3 arrays, 3 in each group, AE group calls: // called by: // main () table access: // modified table ( This item only involves the program that involves database operations) Table updated: // (This item only involves a program that involves the database operation) Input: // card * card structure pointer, the size of the int size structure array OUTPUT : // This function modifies * carr1, * carr2, * carr3 value ********************************** ********************************* / VOID GROUPING (Const Card * Cards, Card * Carr1, Card * Carr2, Card * Carr3); / *** ************************************************************** FUNCTION: // Result_Process Description: // Calculated with recursive calculation, the selected brand calls: // rshift called by: // modified table (this item only involved in the database) Table Updated: // The modified table (this item only involves the database operation) INPUT: // Card * Carr1, Card * Carr2, Card * Carr3 Output: // Return: // Void Others: // This function modification * CARR1, * Carr2, * Carr3 value ********************************** ********************* / CARD * RESULT_PROCESS (Card * Carr1, Card * Carr2, Card * Carr3, Int Counter);

/ ************************************************** Function: // rshift description: // Right shift Calls: // called by: // result_process Table Accessed: // Modified table (This item only involves procedures that involve database operation) Table Updated: // is modified Table (This item only involves the database operation) INPUT: // card * carr1, card * carr2, card * carr3, int counter output: // Return: // card * tahers: // This function modification * Carr1, * carr2, * carr3 value ************************************************************ ******** / VOID RSHIFT (Card * Carr1, Card * Carr2, Card * Carr3, Int Counter);

Void main () {card cards [9]; / * Store nine cards * / card carr1 [3]; / * First group card, cards array 1 * / card carr2 [3]; / * The second group card, Cards Array 2 * / Card Carr3 [3]; / * Third group card, cards array 3 * / int select = 0; / * Player selection * / card * selected_card; / * Store players remember (optional) Brand * / int counter = 0;

Riffle (Cards, 9); / * Ship, get nine cards * /

Puts ("Please remember a card, don't tell me! Up to the following three times, I will know the card you remember!"); PUTS ("If you want to continue play, please accurate Answer, I ask your question, answer it according to the prompt! "); PUTS (" Please rest assured, I will not ask you where you choose which card! ");"); ");

Grouping (Cards, Carr1, Carr2, Carr3); / * Put 9 cards in 3 arrays, 3 each group, A.E group * /

Show (Carr1, 3); Show (Carr2, 3); SHOW (Carr3, 3);

PUTS ("Please tell me the number of the card you remember"); select = getchar ();

Switch (SELECT) / * Branch guess your player remember the brand * / {case '1': selected_card = result_process (Carr1, Carr2, Carr3, Counter); Break; Case '2': SELECTED_CARD = Result_Process (Carr2, Carr3, Carr1, counter; brelected_card = result_process (Carr3, Carr1, Carr2, Counter); Break; default: Puts ("You are lying! Don't play with you!"); fflush (stdin); GetChar (); exit (0);} if (SELECTED_CARD == Null) {fflush (stdin); getchar ();

exit (0);

Puts ("You guess the card is:"); show (SELECTED_CARD, 1); PUTS ("I guess right, haha ​​~~~~");

Fflush (stdin); getchar ();

/ * Riffle's original code * / void riffe (card * cards, int size) {char deck [cardsize]; / * Temporary array, used for storage cards * / unsigned int seed; / * The most produced number of random numbers * / Int debkp = 0; / * Play in the production of the card * /

SEED = (unsigned int) Time (null); SRAND (SEED); / * Ship * / while (deck

Cards [deckp] .val = "A23456789TJQK" [card.rem]; / * Put the remainder to card.val * / cards [deckp] .kind = "3456" [card.quot]; / * Give business to card.kind * /}} / * SHOW will automatically wrap * / void show (int size) {for (int i = 0; i

/ * GROUPING original code * / void grouping (const card * cards, card * carr1, card * carr2, card * carr3) {int i = 0; / * cycle parameter * / / * is given to Carr1 three numbers * / While (i <3) {carr1 [i] .val = cards [i] .val; carr1 [i] .kind = cards [i] .kind; i ;

/ * Separate three numbers of carr2 * / while (i <6) {carr2 [i-3] .val = cards [i] .val; carr2 [i-3] .kind = cards [i]. Kind; i ;

/ * Leave the three numbers of CARR3 * / while (i <9) {carr3 [i-6] .val = cards [i] .val; carr3 [i-6] .kind = cards [i]. Kind; i ;}}

/ * RSHIFT's implementation * / void Rshift (Card * Carr1, Card * Carr2, Card * Carr3, Int counter) {Card Temp2; / * Used to store Carr2 [counter] * / card temp3; / * Used to store Carr3 [ Counter] * /

/ * Temp = carr2 * / temp2.val = carr2 [counter] .val; temp2.kind = carr2 [counter] .kind; / * carr2 = carr1 * / carr2 [counter] .val = carr1 [counter] .val; Carr2 [counter] .kind = carr1 [counter] .kind; / * temp3 = carr3 * / temp3.val = carr3 [counter] .val; temp3.kind = carr3 [counter] .kind;

/ * carr3 = carr2 * / carr3 [counter] .val = temp2.val; carr3 [counter] .kind = Temp2.kind;

/ * carr1 = carr3 * / carr1 [counter] .val = Temp3.val; carr1 [counter] .kind = temp3.kind;

Card * Result_Process (Card * Carr1, Card * Carr2, Card * Carr3, Int Counter) {Rshift (Carr1, Carr2, Carr3, Counter); / * Put the first element of the array to right * / if (counter == 2) {RETURN (& Carr2 [2]);} show (carr1, 3); show (carr2, 3); show (carr3, 3);

PUTS ("Please give the number of lines you remember:"); fflush (stdin); int input = 1; input = getchar (); / * Get your group * /

Switch (Input) {CASE '1': Return (RESULT_PROCESS (Carr1, Carr2, Carr3, ); Break; Case '2': Return (& Carr2 [counter]); Break; default: Puts ("you are Lie! Don't play with you! "); Return null;}}

转载请注明原文地址:https://www.9cbs.com/read-23158.html

New Post(0)