0

Hie all

I am trying to make my game playabel over a network, Client/Server. I have managed to design the game, i have also managed to create a chat program whereby all clients connect to the server and messeges sent are all received and updated by the server to all clients.

I am trying to make the game work the same way as the chat client/server, whereby the game is at the server side and the clients can guess the letters for words, the server then updates all clients and the clients will be able to see what the server sees.

I made the chat server/client using the raknet library, the game is functioning perfectly although not fully complete which reuires just a couple of if statements which i will implement. i am using the uDP protocol but will not mind using TCP.

i have tried incorporating the game with the server, when i connect to the server with a client it connects perfectly but when i input data at the client side nothing seemd to happen on at the server and also the client does not see the game.

Please help, any input or suggestions will be greatly appreciated. I tried uploading all project files with libraries but the site keeps rejecting me if u want the full project files to take a look at send me ur email address. Thank You

Attachments
// hangman2.cpp : main project file.

#include "stdafx.h"
#include <iostream>
#include <fstream>


using namespace std;

inline void type_of_word(char f);


int main()
{   char c,h,ch,ch1,ch2;
    char word[25];
    char word2[25];

    int l,i,ng,n,k,x;

do{  do{//clrscr();
        c='\0';
        cout<<"\n\t\t    *********** H A N G M A N ***********\n\n\n";
        cout<<"(E) Enter a word\n\n(C) Computer chooses word\n\n(A) Add new word to list\n\n(Q) Quit\n\n\nEnter your choice (E - C - Q): ";
        cin>>ch2;
       }while (ch2!='C' && ch2!='c' && ch2!='E' && ch2!= 'e' && ch2!='Q' && ch2!= 'q'&& ch2!='A' && ch2!= 'a');
    if (ch2 == 'Q' || ch2=='q')  exit (0);

    if (ch2 == 'C' || ch2=='c')

    {
        ifstream fin("hangword.txt");
        if(!fin) { //clrscr();
        cout<<"File missing, aborting.\n\nYou are missing a file of name **hangword.txt**\n\nLocate it, then place it next to the program file.\n\n"; system("pause"); return 0;}
        for (i=0;!fin.eof();i++)   fin.getline(word,25);
        fin.close();

        do {
        x=rand();
        }while(x>i || x<0);

        ifstream finn("hangword.txt");
        for (i=0;!finn.eof();i++)
        {finn>>c; finn.getline(word,25); if (x==i) break;}
        finn.close();
    }

  if (ch2 == 'A' || ch2=='a')

    {
       
        ofstream fout("hangword.txt",ios::app);
        if(!fout) {
        cout<<"File missing, aborting.\n\nYou are missing a file of name **hangword.txt**\n\nLocate it, then place it next to the program file.\n\n"; system("pause"); return 0;}
        cin.get();
        cout<<"Choose the topic of your word\n\n(M) Movie\n\n(A) Animal\n\n(P) Sport\n\n(S) Song\n\nEnter your choice (A-P-S-M) : ";
        cin>>h;
        cin.get();
       
        cout<<"\n\nThe word should not exceed 25 letters\n\nEnter the word : ";
        cin.getline(word,25);
        fout<<h<<word<<endl;
        fout.close();

    }


   if (ch2 == 'E' || ch2=='e')
     {
       cin.get();
       cout<<"\t\t\t Type the word :  ";
       cin.getline (word, 25);
     }
 if (ch2 == 'E' || ch2=='e' || ch2 == 'C' || ch2=='c')
{
l=strlen(word);
char choosen[25]="\0";
n=0;k=0;



 for(i=0;i<=24;i++)
   {
    if (word[i]=='\0') {word2[i]='\0';break;}
    if (word[i]==' ')  {word2[i]=' ';  n++;}
    if (word[i]!=' ')  word2[i]='-';
   }
ng=l+2-n;     //only 2 guesses extra
   do{
   there:  type_of_word(c);
     if (k!=0)  cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
     cout<<"\n\n\n\t\t\t      "<<word2<<"\n\n\nYou have "<<ng<< " guesses left, choose a letter : ";
     cin>>ch; cin.get();
     for (i=0;i<25;i++) if (choosen[i]==ch) {//clrscr();
     cout<<"\a\t\t     !!You have choosen "<<ch<<" already!!\n";goto there;}
     ng--; choosen [k]=ch; choosen [k+1]=',';k+=2;



     for (i=0;i<=24;i++)    if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word2[i]=ch;
     if (!strcmpi (word2,word)) {cout<<"\n\t\t\t      "<<strupr(word)<<"\n\n\t\t\tCongratulations  :-()\n"; break;}

    }while(ng>0 || !strcmpi (word2,word));


if (strcmpi (word2,word))  cout<<"\nSorry, maybe next time.\n\nThe word was : "<<strupr(word)<<endl;
}

cout<<"\nWould you like to play again??? (Y - N) : ";
cin>>ch1;  cin.get();

}

while (ch1=='y' || ch1=='Y');
      system("PAUSE");
      return 0;
}




inline void type_of_word(char f)

{    if (f=='m') cout<<"\t\t\t\tMOVIE";
     if (f=='a') cout<<"\t\t\t\tANIMAL";
     if (f=='p') cout<<"\t\t\t\tSPORT";
     if (f=='s') cout<<"\t\t\t\tSONG";
}
#include <stdafx.h>
#include "PacketEnumerations.h"
#include "RakNetworkFactory.h"
#include "RakClientInterface.h"
#include "NetworkTypes.h"
#include "BitStream.h"
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#ifdef _WIN32
#include <conio.h>
#include <windows.h> // Sleep
#else
#include "../Unix/kbhit.h"
#include <unistd.h> // usleep
#endif


// We copy this from Multiplayer.cpp to keep things all in one file for this example
unsigned char GetPacketIdentifier(Packet *p);

// Holds enumeration data
//const int MOTD_MAXIMUM_LENGTH=50; // Characters allocated for the message of the day, used for enumerations
const int SERVER_NAME_MAXIMUM_LENGTH=40; // Characters allocated for the server name

struct EnumerationDataStruct
{
	//char MOTD[MOTD_MAXIMUM_LENGTH];  // (Message of the day) Optional, replace with whatever and/or add more fields
	char serverName[SERVER_NAME_MAXIMUM_LENGTH];
};

const int SCDS_MAXIMUM_NAME_LENGTH=40;

struct StaticClientDataStruct
{
	char name[SCDS_MAXIMUM_NAME_LENGTH];
};

int main(void)
{
	RakNetStatisticsStruct *rss;
	// Pointers to the interfaces of our server and client.
	// Note we can easily have both in the same program
	RakClientInterface *client=RakNetworkFactory::GetRakClientInterface();
	client->InitializeSecurity(0,0);
	client->SetPassword("Rumpelstiltskin");
	
	// Holds packets
	Packet* p;

	// GetPacketIdentifier returns this
	unsigned char packetIdentifier;

	// Just so we can remember where the packet came from
	bool isServer;

	// Record the first client that connects to us so we can pass it to the ping function
	PlayerID clientID=UNASSIGNED_PLAYER_ID;

	// Crude interface

	// Holds user data
	char ip[30], serverPort[30], clientPort[30];
	StaticClientDataStruct staticClientData;

	// A client
	isServer=false;

	printf("WELCOME TO THE HANGMAN CHAT CLIENT.\n");
	printf("Connect to the 'HANGMAN CHAT SERVER'.\n");
	
	// Get our input
	puts("Enter the client port to listen on");
	gets_s(clientPort);
	if (clientPort[0]==0)
		strcpy_s(clientPort, "5000");
	puts("Enter your name (up to 40 characters)");
	gets_s(staticClientData.name);
	if (staticClientData.name[0]==0)
		strcpy_s(staticClientData.name, "Default client name");
	// Note this passes by value, because otherwise people could
	// get access to and damage our internal data
	// UNASSIGNED_PLAYER_ID is to specify changing our own data, rather than our copy of another clients data
	client->SetStaticClientData(UNASSIGNED_PLAYER_ID, (char*)&staticClientData, sizeof(StaticClientDataStruct));
	puts("Enter IP to connect to");
	gets_s(ip);
	client->AllowConnectionResponseIPMigration(false);
	if (ip[0]==0)
		strcpy_s(ip, "127.0.01");
	
		
	puts("Enter the port to connect to");
	gets_s(serverPort);
	if (serverPort[0]==0)
		strcpy_s(serverPort, "10000");

	// Connecting the client is very simple.  0 means we don't care about
	// a connectionValidationInteger, and false for low priority threads
	bool b = client->Connect(ip, atoi(serverPort), atoi(clientPort), 0, 30);
	
	if (b)
		puts("Attempting connection");
	else
	{
		puts("Bad connection attempt.  Terminating.");
		exit(1);
	}

	puts("'quit' to quit. Type to talk.");
	char message[2048];

	// Loop for input
	while (1)
	{
		// This sleep keeps RakNet responsive
#ifdef _WIN32
		Sleep(30);
#else
		usleep(30 * 1000);
#endif


		if (_kbhit())
		{
			// Notice what is not here: something to keep our network running.  It's
			// fine to block on gets or anything we want
			// Because the network engine was painstakingly written using threads.
			gets_s(message);

			if (strcmp(message, "quit")==0)
			{
				puts("Quitting.");
				break;
			}

			//if (strcmp(message, "stat")==0)
		//	{
				
			//	rss=client->GetStatistics();
			//	StatisticsToString(rss, message, 2);
			//	printf("%s", message);
			//	printf("Ping=%i\n", client->GetAveragePing());
			

			//	continue;
		//	}

			//if (strcmp(message, "ping")==0)
			//{
			//	if (client->IsConnected())
			//	client->PingServer();

			//	continue;
		//	}

			// message is the data to send
			// strlen(message)+1 is to send the null terminator
			// HIGH_PRIORITY doesn't actually matter here because we don't use any other priority
			// RELIABLE_ORDERED means make sure the message arrives in the right order
			client->Send(message, (int) strlen(message)+1, HIGH_PRIORITY, RELIABLE_ORDERED, 0);
		}

		// Get a packet from either the server or the client

		p = client->Receive();

	
		if (p==0)
			continue; // Didn't get any packets

		// We got a packet, get the identifier with our handy function
		packetIdentifier = GetPacketIdentifier(p);

		// Check if this is a network message packet
		switch (packetIdentifier)
		{
			case ID_DISCONNECTION_NOTIFICATION:
				  // Connection lost normally
				printf("ID_DISCONNECTION_NOTIFICATION\n");
				break;
			case ID_REMOTE_DISCONNECTION_NOTIFICATION: // Server telling the clients of another client disconnecting gracefully.  You can manually broadcast this in a peer to peer enviroment if you want.
				printf("ID_REMOTE_DISCONNECTION_NOTIFICATION\n");
				break;
			case ID_REMOTE_CONNECTION_LOST: // Server telling the clients of another client disconnecting forcefully.  You can manually broadcast this in a peer to peer enviroment if you want.
				printf("ID_REMOTE_CONNECTION_LOST\n");
				break;
			case ID_REMOTE_NEW_INCOMING_CONNECTION: // Server telling the clients of another client connecting.  You can manually broadcast this in a peer to peer enviroment if you want.
				printf("ID_REMOTE_NEW_INCOMING_CONNECTION\n");
				break;
			case ID_REMOTE_EXISTING_CONNECTION: // Server telling you of an existing connection that was there before you connected
				printf("ID_REMOTE_EXISTING_CONNECTION\n");
				break;
			case ID_CONNECTION_BANNED: // Banned from this server
				printf("We are banned from this server.\n");
				break;			
			case ID_RECEIVED_STATIC_DATA:
				 // Got static data
				printf("ID_RECEIVED_STATIC_DATA\n");
	
				if (client->GetStaticServerData())
				{
					printf("Server name: %s\n", ((EnumerationDataStruct*)(client->GetStaticServerData())->GetData())->serverName);
					//printf("Server MOTD: %s\n", ((EnumerationDataStruct*)(client->GetStaticServerData())->GetData())->MOTD);
				}				
				break;
			case ID_CONNECTION_ATTEMPT_FAILED:
				printf("Connection attempt failed\n");
				break;
			case ID_NO_FREE_INCOMING_CONNECTIONS:
				 // Sorry, the server is full.  I don't do anything here but
				// A real app should tell the user
				printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
				break;
			case ID_MODIFIED_PACKET:
				// Cheater!
				printf("ID_MODIFIED_PACKET\n");
				break;

			case ID_INVALID_PASSWORD:
				printf("ID_INVALID_PASSWORD\n");
				break;

			case ID_CONNECTION_LOST:
				// Couldn't deliver a reliable packet - i.e. the other system was abnormally
				// terminated
				printf("ID_CONNECTION_LOST\n");
				break;

			case ID_CONNECTION_REQUEST_ACCEPTED:
				// This tells the client they have connected
				printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
				break;
			default:
					// It's a client, so just show the message
					printf("%s\n", p->data);
				break;
		}


		// We're done with the packet
		client->DeallocatePacket(p);
	}

	// Be nice and let the server know we quit.
	client->Disconnect(300);

	// We're done with the network
	RakNetworkFactory::DestroyRakClientInterface(client);

	return 0;
}

// Copied from Multiplayer.cpp
// If the first byte is ID_TIMESTAMP, then we want the 5th byte
// Otherwise we want the 1st byte
unsigned char GetPacketIdentifier(Packet *p)
{
	if (p==0)
		return 255;

	if ((unsigned char)p->data[0] == ID_TIMESTAMP)
	{
		assert(p->length > sizeof(unsigned char) + sizeof(unsigned long));
		return (unsigned char) p->data[sizeof(unsigned char) + sizeof(unsigned long)];
	}
	else
		return (unsigned char) p->data[0];
}
//#include <stdafx.h>
#include "PacketEnumerations.h"
#include "RakNetworkFactory.h"
#include "RakServerInterface.h"
#include "NetworkTypes.h"
#include "BitStream.h"
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <conio.h>
#include <windows.h> // Sleep

// We copy this from Multiplayer.cpp to keep things all in one file for this example
unsigned char GetPacketIdentifier(Packet *p);

// Holds enumeration data
const int MOTD_MAXIMUM_LENGTH=50; // Characters allocated for the message of the day, used for enumerations
const int SERVER_NAME_MAXIMUM_LENGTH=40; // Characters allocated for the server name

struct EnumerationDataStruct
{
	//char server name
	char serverName[SERVER_NAME_MAXIMUM_LENGTH];
};

const int SCDS_MAXIMUM_NAME_LENGTH=40;

struct StaticClientDataStruct
{
	char name[SCDS_MAXIMUM_NAME_LENGTH];
};

int main(void)
{
	// Pointers to the interfaces of our server and client.
	// Note we can easily have both in the same program
	RakServerInterface *server=RakNetworkFactory::GetRakServerInterface();
	RakNetStatisticsStruct *rss;
	server->InitializeSecurity(0,0);
	int i = server->GetNumberOfAddresses();
	server->SetPassword("Rumpelstiltskin");

	// Holds packets
	Packet* p;

	// GetPacketIdentifier returns this
	unsigned char packetIdentifier;

	// Record the first client that connects to us so we can pass it to the ping function
	PlayerID clientID=UNASSIGNED_PLAYER_ID;

	// Holds user data
	char portstring[30];
	EnumerationDataStruct enumerationDataStruct;

	printf("HANGMAN CHAT CLIENT.\n");
	printf("Connect to the 'Hangman Chat Server'\n");
	

	// A server
	puts("\nEnter the server port to listen on:");
	gets_s(portstring);
	if (portstring[0]==0)
		strcpy_s(portstring, "10000");
	puts("Enter the server name  (up to 40 characters)");
	gets_s(enumerationDataStruct.serverName);
	if (enumerationDataStruct.serverName[0]==0)
		strcpy_s(enumerationDataStruct.serverName, "Default server name");
	
	// Note this passes by value, because otherwise people could get access
	// to and damage our internal data
	server->SetStaticServerData((char*)&enumerationDataStruct, sizeof(EnumerationDataStruct));
	puts("Starting server.");

	// Starting the server is very simple.  2 players allowed.
	// 0 means we don't care about a connectionValidationInteger, and false
	// for low priority threads
	bool b = server->Start(32, 0, 30, atoi(portstring));
	if (b)
		puts("Server started, waiting for connections.");
	else
	{ 
		puts("Server failed to start.  Terminating.");
		exit(1);
	}


	puts("'quit' to quit.\n\nType to talk.\n");
	char message[2048];

	// Loop for input
	while (1)
	{

// This sleep keeps RakNet responsive
#ifdef _WIN32
		Sleep(30);
#else
		usleep(30 * 1000);
#endif


		if (_kbhit())
		{
			// Notice what is not here: something to keep our network running.  It's
			// fine to block on gets or anything we want
			// Because the network engine was painstakingly written using threads.
			gets_s(message);

			if (strcmp(message, "quit")==0)
			{
				puts("Quitting.");
				break;
			}

	
			// Message now holds what we want to broadcast
			char message2[420];
			// Append Server: to the message so clients know that it ORIGINATED from the server
			// All messages to all clients come from the server either directly or by being
			// relayed from other clients
			message2[0]=0;
			strcpy_s(message2, "Server: ");
			strcat_s(message2, message);
		
			// message2 is the data to send
			// strlen(message2)+1 is to send the null terminator
			// HIGH_PRIORITY doesn't actually matter here because we don't use any other priority
			// RELIABLE_ORDERED means make sure the message arrives in the right order
			// We arbitrarily pick 0 for the ordering stream
			// UNASSIGNED_PLAYER_ID means don't exclude anyone from the broadcast
			// true means broadcast the message to everyone connected
			server->Send(message2, (const int) strlen(message2)+1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, UNASSIGNED_PLAYER_ID, true);
		}

		// Get a packet from either the server or the client

		p = server->Receive();
		
		if (p==0)
			continue; // Didn't get any packets

		// We got a packet, get the identifier with our handy function
		packetIdentifier = GetPacketIdentifier(p);

		// Check if this is a network message packet
		switch (packetIdentifier)
		{
			case ID_DISCONNECTION_NOTIFICATION:
				  // Connection lost normally
				printf("ID_DISCONNECTION_NOTIFICATION\n");
				break;

		
			case ID_NEW_INCOMING_CONNECTION:
				 // Somebody connected.  We have their IP now
				printf("ID_NEW_INCOMING_CONNECTION\n");
				clientID=p->playerId; // Record the player ID of the client
				break;

			case ID_RECEIVED_STATIC_DATA:
				 // Got static data
				if (server->GetStaticClientData(p->playerId))
				{
					printf("ID_RECEIVED_STATIC_DATA\n");
					printf("%s has connected\n", ((StaticClientDataStruct*)(server->GetStaticClientData(p->playerId))->GetData())->name);
				}
				
				break;

			case ID_MODIFIED_PACKET:
				// Cheater!
				printf("ID_MODIFIED_PACKET\n");
				break;

			case ID_CONNECTION_LOST:
				// Couldn't deliver a reliable packet - i.e. the other system was abnormally
				// terminated
				printf("ID_CONNECTION_LOST\n");
				break;

			default:
				// The server knows the static data of all clients, so we can prefix the message
				// With the name data
				printf("%s: %s\n", ((StaticClientDataStruct*)(server->GetStaticClientData(p->playerId))->GetData())->name, p->data);

				// Relay the message.  We prefix the name for other clients.  This demonstrates
				// That messages can be changed on the server before being broadcast
				// Sending is the same as before
				sprintf_s(message, "%s: %s", ((StaticClientDataStruct*)(server->GetStaticClientData(p->playerId))->GetData())->name, p->data);
				server->Send(message, (const int) strlen(message)+1, HIGH_PRIORITY, RELIABLE_ORDERED, 0, p->playerId, true);
			
				break;
		}

		// We're done with the packet
		server->DeallocatePacket(p);
	}

	server->Disconnect(300);
	// We're done with the network
	RakNetworkFactory::DestroyRakServerInterface(server);

	return 0;
}

// Copied from Multiplayer.cpp
// If the first byte is ID_TIMESTAMP, then we want the 5th byte
// Otherwise we want the 1st byte
unsigned char GetPacketIdentifier(Packet *p)
{
	if (p==0)
		return 255;

	if ((unsigned char)p->data[0] == ID_TIMESTAMP)
	{
		assert(p->length > sizeof(unsigned char) + sizeof(unsigned long));
		return (unsigned char) p->data[sizeof(unsigned char) + sizeof(unsigned long)];
	}
	else
		return (unsigned char) p->data[0];
}
#include <stdafx.h>
#include "PacketEnumerations.h"
#include "RakNetworkFactory.h"
#include "RakServerInterface.h"
#include "NetworkTypes.h"
#include "BitStream.h"
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <conio.h>
#include <windows.h> // Sleep
#include "stdafx.h"
#include <iostream>
#include <fstream>


using namespace std;

inline void type_of_word(char f);

// We copy this from Multiplayer.cpp to keep things all in one file for this example
unsigned char GetPacketIdentifier(Packet *p);

// Holds enumeration data
const int MOTD_MAXIMUM_LENGTH=50; // Characters allocated for the message of the day, used for enumerations
const int SERVER_NAME_MAXIMUM_LENGTH=40; // Characters allocated for the server name

struct EnumerationDataStruct
{
	//char server name
	char serverName[SERVER_NAME_MAXIMUM_LENGTH];
};

const int SCDS_MAXIMUM_NAME_LENGTH=40;

struct StaticClientDataStruct
{
	char name[SCDS_MAXIMUM_NAME_LENGTH];
};

int main(void)
{
	// Pointers to the interfaces of our server and client.
	// Note we can easily have both in the same program
	RakServerInterface *server=RakNetworkFactory::GetRakServerInterface();
	RakNetStatisticsStruct *rss;
	server->InitializeSecurity(0,0);
	int i = server->GetNumberOfAddresses();
	server->SetPassword("Rumpelstiltskin");

	// Holds packets
	Packet* p;

	// GetPacketIdentifier returns this
	unsigned char packetIdentifier;

	// Record the first client that connects to us so we can pass it to the ping function
	PlayerID clientID=UNASSIGNED_PLAYER_ID;

	// Holds user data
	char portstring[30];
	EnumerationDataStruct enumerationDataStruct;

	printf("HANGMAN CHAT CLIENT.\n");
	printf("Connect to the 'Hangman Chat Server'\n");
	

	// A server
	puts("\nEnter the server port to listen on:");
	gets_s(portstring);
	if (portstring[0]==0)
		strcpy_s(portstring, "10000");
	puts("Enter the server name  (up to 40 characters)");
	gets_s(enumerationDataStruct.serverName);
	if (enumerationDataStruct.serverName[0]==0)
		strcpy_s(enumerationDataStruct.serverName, "Default server name");
	
	// Note this passes by value, because otherwise people could get access
	// to and damage our internal data
	server->SetStaticServerData((char*)&enumerationDataStruct, sizeof(EnumerationDataStruct));
	puts("Starting server.");

	// Starting the server is very simple.  2 players allowed.
	// 0 means we don't care about a connectionValidationInteger, and false
	// for low priority threads
	bool b = server->Start(32, 0, 30, atoi(portstring));
	if (b)
	puts("Server started, waiting for connections.");
	else
	{ 
		puts("Server failed to start.  Terminating.");
		exit(1);
	}

	char message[2048];

//DELAY FOR CONNECTIONS
//while (1)
//	{

 //This sleep keeps RakNet responsive
//#ifdef _WIN32
//		Sleep(30);
//#else
		//usleep(30 * 1000);
//#endif

//}

	char c,h,ch,ch1,ch2;
    char word[25];
    char word2[25];

   int l,ng,n,k,x;

do{  do{//clrscr();
        c='\0';
        cout<<"\n\t\t    *********** H A N G M A N ***********\n\n\n";
        cout<<"(E) Enter a word\n\n(C) Computer chooses word\n\n(A) Add new word to list\n\n(Q) Quit\n\n\nEnter your choice (E - C - Q): ";
        cin>>ch2;
       }while (ch2!='C' && ch2!='c' && ch2!='E' && ch2!= 'e' && ch2!='Q' && ch2!= 'q'&& ch2!='A' && ch2!= 'a');
    if (ch2 == 'Q' || ch2=='q')  exit (0);

    if (ch2 == 'C' || ch2=='c')

    {
        ifstream fin("hangword.txt");
        if(!fin) { //clrscr();
        cout<<"File missing, aborting.\n\nYou are missing a file of name **hangword.txt**\n\nLocate it, then place it next to the program file.\n\n"; system("pause"); return 0;}
        for (i=0;!fin.eof();i++)   fin.getline(word,25);
        fin.close();

        do {
        x=rand();
        }while(x>i || x<0);

        ifstream finn("hangword.txt");
        for (i=0;!finn.eof();i++)
        {finn>>c; finn.getline(word,25); if (x==i) break;}
        finn.close();
    }

  if (ch2 == 'A' || ch2=='a')

    {
       
        ofstream fout("hangword.txt",ios::app);
        if(!fout) {
        cout<<"File missing, aborting.\n\nYou are missing a file of name **hangword.txt**\n\nLocate it, then place it next to the program file.\n\n"; system("pause"); return 0;}
        cin.get();
        cout<<"Choose the topic of your word\n\n(M) Movie\n\n(A) Animal\n\n(P) Sport\n\n(S) Song\n\nEnter your choice (A-P-S-M) : ";
        cin>>h;
        cin.get();
       
        cout<<"\n\nThe word should not exceed 25 letters\n\nEnter the word : ";
        cin.getline(word,25);
        fout<<h<<word<<endl;
        fout.close();

    }


   if (ch2 == 'E' || ch2=='e')
     {
       cin.get();
       cout<<"\t\t\t Type the word :  ";
       cin.getline (word, 25);
     }
 if (ch2 == 'E' || ch2=='e' || ch2 == 'C' || ch2=='c')
{
l=strlen(word);
char choosen[25]="\0";
n=0;k=0;



 for(i=0;i<=24;i++)
   {
    if (word[i]=='\0') {word2[i]='\0';break;}
    if (word[i]==' ')  {word2[i]=' ';  n++;}
    if (word[i]!=' ')  word2[i]='-';
   }
ng=l+2-n;     //only 2 guesses extra
   do{
   there:  type_of_word(c);
     if (k!=0)  cout<<"\n\n\t\t\tChoosen letters : "<<choosen<<"\n";
     cout<<"\n\n\n\t\t\t      "<<word2<<"\n\n\nYou have "<<ng<< " guesses left, choose a letter : ";
     cin>>ch; cin.get();
     for (i=0;i<25;i++) if (choosen[i]==ch) {//clrscr();
     cout<<"\a\t\t     !!You have choosen "<<ch<<" already!!\n";goto there;}
     ng--; choosen [k]=ch; choosen [k+1]=',';k+=2;



     for (i=0;i<=24;i++)    if (word[i]==ch || word[i]==ch+32 || word[i]==ch-32) word2[i]=ch;
     if (!_strcmpi (word2,word)) {cout<<"\n\t\t\t      "<<_strupr_s(word)<<"\n\n\t\t\tCongratulations  :-()\n"; break;}

    }while(ng>0 || !_strcmpi (word2,word));


if (_strcmpi (word2,word))  cout<<"\nSorry, maybe next time.\n\nThe word was : "<<_strupr_s(word)<<endl;
}

cout<<"\nWould you like to play again??? (Y - N) : ";
cin>>ch1;  cin.get();

}

while (ch1=='y' || ch1=='Y');
      system("PAUSE");
      return 0;
}



inline void type_of_word(char f)

{    if (f=='m') cout<<"\t\t\t\tMOVIE";
     if (f=='a') cout<<"\t\t\t\tANIMAL";
     if (f=='p') cout<<"\t\t\t\tSPORT";
     if (f=='s') cout<<"\t\t\t\tSONG";
}
3
Contributors
2
Replies
4
Views
10 Years
Discussion Span
Last Post by sybarite29
0

well i havent done any network programming in C++ but yes i have made stuff in Java which encorparates networking i will see what i can do

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.