C ++ 21 point card games

Source: Internet
Author: User

Recently, I have seldom asked questions, and I am dedicated to designing courses. I don't think I can do anything about it. Fortunately, I 've done it myself. No matter how you do it, you don't need to go to the Internet to find someone else's code.

After you paste the Code, it is a summary of this semester. You can fully understand C ++.

Games are divided into single-person and multi-person games. I divided it into two categories: one single player and one multi-player, and the class of single player is derived from multiple players.

Put the code in three files:

The code in the game_class.h file is as follows:

# Define N 10 using namespace STD; void startmenu (); // This file contains class declaration and function declaration. Int menu (); void exit (); Class game {protected: int color [N] [N]; int num [N] [N]; int currentodds [N]; char name [N] [20]; int money [N]; int score [N]; int visit [N]; int hands [N]; int e [N]; public: Game () {// constructor for (INT I = 0; I <n; I ++) {// initialize money [I] = 1000; score [I] = 0; E [I] = 0; hands [I] = 0; visit [I] = 0; currentodds [I] = 0 ;}}~ Game () {} void help (); // help void showpoke (char, char); // display a single poker function void show (INT ); // display function bool getcard (INT, INT); // The licensing function bool choice (); // The Information Filtering Function void setodds (INT ); // Add the void inituser () function; // initialize the input function void save (); // Save the record function int judge (INT); // judge the function void continue (); // continue the game function and read the file virtual void begin (INT); // restart the function and use the virtual function to implement void result (INT); // calculate the result function }; class game: Public game {public: boolcomputer (); Virtual void begin (INT); void save (); void continue (); game (): Game (){}};

The code in game_class.cpp is as follows:

# Include <iostream> # include <windows. h> # include <cstring> # include <time. h >#include <fstream >#include <iomanip> # include "game_class.h" using namespace STD; char pokecolor [4] = {3, 4, 5, 6 }; char pokenum [13] = {'2', '3', '4', '5', '6', '7', '8', '9 ', 'I', 'J', 'Q', 'k', 'A'}; int N, stake, H = 0, flag = 0; // total number of players // record the banker's name void startmenu () // game start interface, base class game {char load [] = "hyperlink ☆★☆☆Success "; cout <"\ t has been used when there are too many other than available \ t \ n "; cout <"\ t too many players welcome to the blackjack point card game startup success \ t \ n \ t"; for (INT I = 0; I <= strlen (load); ++ I) {cout <load [I];} cout <"\ n \ t has been used when there are too many pending errors \ n" <Endl; cout <"loading success! "<Endl;} int menu () // menu display {char ch [5]; while (1) {cout <"zookeeper \ n"; cout <SETW (15) <"" <"menu" <Endl; cout <SETW (25) <"0: continue the last game" <Endl; cout <SETW (22) <"1: single player \ n"; cout <SETW (22) <"2: multiplayer games \ n"; cout <SETW (18) <"3: Help \ n"; cout <SETW (18) <"4: Quit \ n "; cout <"zookeeper \ n"; cout <"select :"; while (CIN> CH) {If ('0' <= CH [0] & Ch [0] <= '4') break; the else cout <"option is invalid !, Enter ";} switch (CH [0]) {Case '0': Return 0; Case '1': return 1; Case '2': return 2; case '3': return 3; Case '4': Return-1 ;}} void game: Help () {// help function, base Class gamecout <"/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* /* \ n "; cout <"game origin \ n" <"game is a very interesting card game, \ n" <"first appeared in the 16th century, originated in France, in French, vingt-et-Un \ n "<" has been widely used in the UK, \ n "<" will be given an extra reward. The English name is Blackjack \ n "<" game rules: \ n "<" generally uses the 1-8 sub-card. The dealer sends two cards to each player, and the card faces toward the top; \ n "<" sends two cards to himself, one card faces up (called the card ), A card faces down (called a dark card ). \ N "<" the number of poker points in the hands of everyone is calculated as: A, K, Q, J, and 10 are counted as 10 points. \ N "<. The goal is to try to lean towards, and the closer the better, the better is. \ N "<" in the Process of cards to be played, if all the cards add up to more than 21 points, the player will lose) \ n "<" the game is over. If the player does not kill and decides to stop playing the cards, then the dealer will not take his \ n "<" generally at or above, but it is also possible that the cards will not be played at to or even \ n "<. From to, he continued to win the card. If the dealer broke down, he would lose. If he doesn't kill, \ n "<or you can compare the number of points with him, greatly winning. The same number of points is equal, you can get your bet \ n "<" back. If you have 5 cards in your hand and the total number is less than, this situation can hold all cards (\ n "<" of course, the total number of 5 cards is 21 points better ), however, this rule is not supported in some ways. \ N "; cout <"/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/* /* \ n ";} void game: showpoke (char I, char J) // display poker, base class game {cout <"── ┐" <Endl; cout <"│" <pokecolor [I] <""; if (j = 8) cout <10 <"│" <Endl; else cout <pokenum [J] <"│" <Endl; cout <"── ┘" <Endl;} void game: Show (int t) {for (INT I = 0; I <n; I ++) {If (visit [I]) continue; cout <name [I] <Endl; cout <"score:" <score [I] <Endl; For (Int J = 0; j 

The code in Main. cpp is as follows:

# Include <iostream> # include <cstdlib> // system color # include <fstream> # include "game_class.h" using namespace STD; extern int N, flag; // external variables. Int main (INT argc, char * argv []) {int F; game multi; game smpile; startmenu (); System ("color 5"); While (1) {f = menu (); If (F =-1) break; If (F = 2) {flag = 2; Multi. begin (2);} If (F = 1) {flag = 1; smpile. begin (1) ;}if (F = 0) {If (F = 0 &&! Flag) {ifstream infile ("poke_inf.txt", IOS: In); If (! Infile) {cerr <"Open error! "<Endl; exit (0) ;}infile >>n> flag; If (flag = 1) smpile. continue (); else multi. continue ();} If (F & flag = 1) smpile. begin (0); If (F & flag = 2) Multi. begin (0);} If (F = 3) Multi. help () ;}cout <"whether to save the game (Y | N):"; if (multi. choice () {If (flag = 1) smpile. save (); else multi. save (); cout <"file saved successfully! "<Endl ;}cout <" Thank you for using "<Endl; return 0 ;}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.