C ++ game, DOS

Source: Internet
Author: User

It is said that there is an undefeated algorithm. I will write another version of PVC tomorrow.

The topic is that today I am bored with writing a game of well-known chess. By the way, I gradually get used to good code styles and learn from them.

Jzq2.cpp

/* For the PVP version of the N-character chess game, the DOS version board can be expanded, you only need to adjust the detection conditions, other interfaces do not need to change. Non-man-machine combat type, PVP type; @ author: unparalleled in the world @ date: 2014-5-25 @ version: 1.0 */# include
 
  
# Include
  
   
# Define INVALIDINDEX-1 # define FULL-2 # define OK 0 # define WIN 1 # define ISIN-3 using namespace std; struct box {// use box to represent the int chess of each lattice on the Board; // use a color to represent the pawns, black and whiteint status; // 0 to indicate that the lattice has no pawns, 1 indicates that a pawn has been obtained}; enum COLOR {black, white}; class chessBoard {private: static const int MAXROW = 10; static const int MAXCOLUMN = 10; int row; int column; int blackBox; // The number of remaining checkerboard grids. You can click box arr [MAXROW] [MAXCOLUMN]; void setRow (int r) {row = r ;}; void setCol (int c) {column = c ;}; int GetRow () const {return row ;}; int GetCol () const {return column ;}; public: chessBoard (int r, int col) {if (r> MAXROW | col> MAXCOLUMN) {cerr <"The board size exceeds the range" <
   
    
= R | j> = col) return INVALIDINDEX; // if (c! = Black & c! = White) // return INVALIDINDEX; if (arr [I] [j]. status = 0) {// drop the pawn into the checker arr [I] [j]. chess = c; arr [I] [j]. status = 1; // identify the flush (); // refresh blackBox --; if (isGameOver () return WIN; if (isFull () return FULL; return OK;} return ISIN;} protected: void creat () {// initialize the checkboard int r = chessBoard: GetRow (); int col = chessBoard: GetCol (); for (int I = 0; I
    
     
= 0 & j
     
      
Main. cpp
      

# Include
       
        
# Include "jzq2.cpp" using namespace std; int main () {// 3 indicates that the chessboard is 3*3, and the three rows are the same as the victory, 5, 5 represents 5-character chess, but the size of the Board is also 5*5 // The expansion board will be launched in the next version chessBoard cb (); int status; COLOR c = black; // record who is going to take the next step int x, y; bool falg = false; // used to record whether the game is successful. bool isExit = false; // used to record whether the game is over while (! IsExit) {cout <"\ n \" 0 \ "represents white, \" * \ "represents black" <
        
         
> X> y;/* if (falg) c = black? White: black; // enter */status = cb. insertChess (x, y, c); switch (status) {// out of the range. If INVALIDINDEX-1 is returned, the system returns WIN 1. // if the Board is full, return FULL-2 // if the player is playing normally, OK 0 case 0: falg = true; c = black? White: black; // if the game is successfully played, change to break. case-1: cout <"\ n the input coordinate is incorrect. It is out of range" <
         
          
If you have tested 3*3 without a BUG, you must enter a number. If you enter a letter, it will crash!

Put it in PVP for fun, hahaha.

Today, I ran to the duoyi network to test the problem. On the way back, I thought of the last question and wrote less judgment. I was depressed.

I thought about it on the way back.

Depressing ing ......

Okay, you're asleep. Good night.

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.