This is my first time to make a game.can someone help me ?

This is a discussion on This is my first time to make a game.can someone help me ? within the C++ Programming forums, part of the General Programming Boards category; this is a battleship game..can some one help me to check it...n also i want to ask how can i ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    This is my first time to make a game.can someone help me ?

    this is a battleship game..can some one help me to check it...n also i want to ask how can i put the ship become a star when the player hit the right ship....
    if the player hit the right ship n then the player cld hit one more time...
    if the player missed..then goto the Computer turn...
    one more quesyion ,,,can someone show me how to make the ship become vertical or horizontal when i choose a random number to put the ship....!!!
    this game has lots of problem...i havnt finish the code yet
    i just want someone to help me....




    Code:
    #include "stdafx.h"
    #include <iostream> 
    using namespace std; 
    void printArray( const int z[][ 10 ] );
    void ShowMessage()
    {
    	cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
    	cout<<"<<   Welcome to my BattleShip Game            <<"<<endl;
    	cout<<"<<   Student ID:                                             <<"<<endl;
    	cout<<"<<   Student :                                                <<"<<endl;
    	cout<<"<<   C++ programming                                  <<"<<endl;
    	cout<<"<<   First ,i need to ........ c programming      <<"<<endl;
    	cout<<"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;
    	cout<<endl;
    }
    void printArray( const int z[][ 10 ] )
    {
       int i; /* row counter */
       int j; /* column counter */
     
       /* loop through rows */
       for ( i = 0; i <= 9; i++ ) {
     
               if( i < 4)
               {
                       printf("      %d  ", i);
               }
               if( i > 4 )
               {
                       printf("      %d  ", i);
               }
               if(i == 4)
               {
                       printf("  4  ");
               }
    		/* output column values */
    		for ( j = 0; j <= 9; j++ ) 
    		{
    		printf( "%d ", z[ i ][ j ] );
    		}
            /* end inner for */
     
          printf( "\n" ); /* start new line of output */
     
              if( i == 3 )
              {
                      printf("   A");
     
              }
       } /* end outer for */
     
    } /* end function printArray */
    void Player()/*This is Player turn */
    {
    	int Ptable[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    	int Testtable[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    	int ship=1;
    	for(ship=1;ship<10;ship++)/*5 time loop for 5 ship*/
    	{
    		int i=rand() % 10;
    		int j=rand() % 10;
    		Testtable[i][j]=1;
    	}
        int playagain=1;
    //playagain:
    	while(playagain)
    	{
    		printf("\n------------Player Turn------------\n\n"); 
    
    		printf("\t          B\n\n");
    		printf("         0 1 2 3 4 5 6 7 8 9\n\n");
    		printArray(Ptable);
    		printf("\nPlease Enter the Number of the Coordinates: \n\n");
    		int lnput1,lnput2;
    		cout<<"      A is:";
    			cin>>lnput1;/*input the first value*/
    		cout<<"      B is:";
    			cin>>lnput2;/*input the second value*/
    		if(lnput1<10,lnput2<10)
    		{
    			if(Testtable[lnput1][lnput2]==1)
    			{
    				Ptable[lnput1][lnput2]=Testtable[lnput1][lnput2];
    				cout<<"      you just hit ("<<lnput1<<","<<lnput2<<")="<<Testtable[lnput1][lnput2]<<endl;
    				cout<<"      ====================="<<endl;
    				cout<<"      ==Very Good, Hit!!!=="<<endl;
    				cout<<"      ====================="<<endl;
    				/*this show me where are the ship..!!*/
    				/*
    				for (int time = 0; time < 10; time++)
    				{
    					for (int time2 = 0; time2 < 10; time2++)
    					cout <<Testtable[time][time2];
    					cout << '\n';
    				}
    				*/
    				//goto playagain;
    			}
    			else
    			{
    				cout<<"      you just putted ("<<lnput1<<","<<lnput2<<")="<<Ptable[lnput1][lnput2]<<endl;
    				cout<<"      ======================"<<endl;
    				cout<<"      ==Sorry, u Missed!!!=="<<endl;
    				cout<<"      ======================"<<endl;
    
    				/*
    				for (int time = 0; time < 10; time++)
    				{
    					for (int time2 = 0; time2 < 10; time2++)
    					cout <<Testtable[time][time2];
    					cout << '\n';
    				}
    				*/
    				playagain=0;
    				//when i didnt hit the right ship,goto computer turn;
    			}
    		}
    		else 
    		{
    			cout<<"This is wrong Coordinates"<<endl;
    			playagain=0;
    			//goto playagain;
    		}
    	}
    }
    
    /*
    
    this is a comment
    
    */
    
    void Computer()
    {
    	int Ctable[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    	int Testtable2[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    	printf("\n\n------------Computer Turn------------\n\n");
    	printf("\t          B\n\n");
    	printf("         0 1 2 3 4 5 6 7 8 9\n\n");
    	printArray(Ctable);
    	printf("\nComputer is playing with you: \n\n");
    	int comship;
    	for(comship=1;comship<6;comship++)/*5 time loop for 5 ship*/
    	{
    		int p=rand() % 10;
    		int k=rand() % 10;
    		Testtable2[p][k]=1;
    	}
    	int p2=rand() % 10;
    	int k2=rand() % 10;
    	if(Ctable[p2][k2]=1)
    	{
    		cout<<"Computer choose : ("<<p2<<","<<k2<<")"<<endl;
    		cout<<"========Sorry, Com hit your ship!!!========"<<endl;
    	}
    	else
    	{
    		cout<<"========Good, Computer missed!!!==============="<<endl;
    	}
    
    	cout<<endl;
    }
    int main()
    {
    	{
    		ShowMessage();
    	} 
    	int Ptable[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    	int Ctable[ 10 ][ 10 ] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
    /*Player-put a random ship to the table*/
    
    	{
    		Player();
    	}
    /*Computer*/
    	int p=rand() % 10;
    	int k=rand() % 10;
    	Ctable[p][k]=1;
    /*結果*/
    	{
    	Computer();
    	}
    	return 0; 
    }
    Attached Files Attached Files
    Last edited by viecas; 03-18-2011 at 01:04 PM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    You need to decide if you want or use C or C++.
    printf is simply not a good thing to have in a C++ program.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time synchronization problem
    By freeindy in forum C Programming
    Replies: 1
    Last Post: 04-19-2007, 06:25 AM
  2. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 01:43 PM
  3. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 03:44 AM
  4. sorry I didn't make my self clear last time
    By negevy in forum C Programming
    Replies: 1
    Last Post: 09-03-2005, 04:14 AM
  5. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21