0

can anyone please help me in to creating a client-server using this game?

#include <iostream>

#include <iomanip>

#include <map>

#include <time.h>

#include <cstdlib>

using namespace std;



//displays the instruction of the game

void displayInst(){

    for ( int b = 0; b < 28; b++ )

    cout << "* ";



    cout << "\n* Game Title: NUM-BERS                                 *";

    cout << "\n*                                                      *";

    cout << "\n* Players : 2                                          *";

    cout << "\n*                                                      *";

    cout << "\n* How-to-play: The game is basically                   *";

    cout << "\n*              based on \"tic-tac-toe\" but with a       *";

    cout << "\n*              twist. Instead of Using X's and O's     *";

    cout << "\n*              the player is going to use numbers,     *";

    cout << "\n*              ODD for PLAYER 1 and EVEN for PLAYER 2. *";

    cout << "\n*              The goal is to make a \"in a row\";       *";

    cout << "\n*              (diagonally, vertically,horizontally)   *";

    cout << "\n*              but the catch is, the total of the row  *";

    cout << "\n*              will be equal to the \"goal total\"       *";

    cout << "\n*              generated by the program.               *\n";

    for ( int b = 0; b < 28; b++ )

        cout << "* ";

}//end displayInst





int main(){

    

   char choice;     

   

   do{

        

        map<char,char> box;

        box['a'] = 'a';

        box['b'] = 'b';

        box['c'] = 'c';

        box['d'] = 'd';

        box['e'] = 'e';

        box['f'] = 'f';

        box['g'] = 'g';

        box['h'] = 'h';

        box['i'] = 'i';



        char letter,value;   

        int goalTotal;

        bool win = false;

       	int a[8];

       	int player1[5] = {1,3,5,7,9};

       	int player2[5] = {2,4,6,8,10};

        

        //generates a random number for the total goal

        srand( time(NULL) );

        goalTotal = (5 + rand() % 15);



        int c = 0;



      	

        do{



		    displayInst();//displays the instructions



            //display's the main board

            cout << endl << endl << setw(6) << box['a']<<" | "<<box['b']<<" | "<<box['c'];

            cout << "\n     ---------\n";

            cout << setw(6) << box['d'] << " | " << box['e'] << " | " << box['f'];

            cout << "\n     ---------\n";

            cout << setw(6) << box['g'] << " | " << box['h'] << " | " << box['i'] << endl;

        

        	if ( c % 2 == 0)

                cout << "\nPlayer 1's Turn : enter ODD numbers only!\n";

            else

                cout << "\nPlayer 2's Turn : enter EVEN numbers only!\n";

            	

             cout << setw(6) << "\nGoal Total to Win: " << goalTotal;//displays the total goal for the game

             //lets the user input their move

             cout << endl << setw(6) << "\nEnter a letter: ";

             cin >> letter;

             cout << endl << setw(6) << "Enter a value: ";

             cin >> value;

       

             box[letter] = value;

        	 c++;

        	 

        	 

             //check if player wins

             a[0] = int(box['a'] - 48) + int(box['b'] - 48)  + int(box['c'] - 48);

             a[1] = int(box['d'] - 48) + int(box['e'] - 48)  + int(box['f'] - 48);

    		 a[2] = int(box['g'] - 48) + int(box['h'] - 48)  + int(box['i'] - 48);

    	  	 a[3] = int(box['a'] - 48) + int(box['d'] - 48)  + int(box['g'] - 48);

    		 a[4] = int(box['b'] - 48) + int(box['e'] - 48)  + int(box['h'] - 48);

    		 a[5] = int(box['c'] - 48) + int(box['f'] - 48)  + int(box['i'] - 48);

    		 a[6] = int(box['g'] - 48) + int(box['e'] - 48)  + int(box['c'] - 48);

    		 a[7] = int(box['a'] - 48) + int(box['e'] - 48)  + int(box['i'] - 48);

		

             system("cls");

                    

             for (int i = 0; i < 8; i++) {

              if (a[i] == goalTotal) {

                    if(c % 2 == 0)

                        cout << endl << "Player 2 Wins" << endl;

                    else

                        cout << endl << "Player 1 Wins" << endl;

                 win = true;

                 break;

              }//end if

             }//end for

		

        }while(!win);

        

	cout << "\n\aPlay again? (Y/N): ";

	cin >> choice;

	

	}while( toupper(choice) == 'Y');



return 0;

}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by vijayan121
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.