Thread: Errors with my battelship game

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

    Unhappy Errors with my battelship game

    Heloow every one I have many errors with my game
    can you help me??
    really I can not solve them
    this is my game
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    void print2DArray(char array2D[][10]);
    void GameIniti, DisplayBoard, PlayerPlaceShip;
    {
                    int row, col;
                    for(row=0; row<10; row++) \
                            for(col=0; col<10; col++)
                                                    printf("%c", array2D[row][col]);
                                    printf("\n");
    
    }
    
    void GameIniti(char array2D[10][10]);
    void DisplayBoard(char array2D[10][10]);
    void PlayerPlaceShip(char array2D[10][10], char ship[50], int size);
    
    int main()
    {
                    char battleship[10][10];
                    int 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
                    int A, B, C, D, E, F, G, H, I, J, K, L;
                    char ch;
                    char row[10] = "12345678910";
                    char column[10] = "ABCDEFGHIJKL";
    
                    for(row=0; row<10; row++)
                                    for(column=0; column<10; column++)
                                                    battleship[row][column] = 'x';
    
                    print2DArray(battleship);
    
                    while
                    {
                                    printf("please type <row> <column> <character> eg 0 1 x;");
                                    scanf("%d %d",&row, &column);  // this was wrong
                                    battleship[row][column] = 'x';
    
                                    print2DArray(battleship);
                    }
    
    {
    char array2D[10][10];
    int score;
    int i, j, score = 0;
    for(i=0; i<10; i++) { /* rows */
        printf("%c|", row_letters[i]);
    
        for(j=0; j<10; j++) { /* columns */
            printf("%c", array2D[i*10+j]);
        }
    
        printf("|\n");
    GameIniti(array2D);
                    DisplayBoard(array2D);
                    PlayerPlaceShip(array2D, "carrier", 5);
                    DisplayBoard(array2D);
                    PlayerPlaceShip(array2D, "battleship", 4);
                    DisplayBoard(array2D);
        PlayerPlaceShip(array2D, "cruiser", 4);
                    DisplayBoard(array2D);
                    PlayerPlaceShip(array2D, "submarine", 3);
                    DisplayBoard(array2D);
                    PlayerPlaceShip(array2D, "destroyer", 2);
        DisplayBoard(array2D);
        return 0;
    }
    
    void GameIniti(char array2D[10][10])
    {
    for(i=0; i<10; i++)
    {
                    for(j=0; j<10; j++)
                    {
                                  array2D[i][j]='x';
                     }
      }
    }
    
    void DisplayBoard(char array2D[10][10])
    {
                    printf("1 2 3 4 5 6 7 8 9 10/n");
    
                    for(int i=1;i<=10;i++)
                    {
                                    if(i<10)
                                    {
                                                    printf(i,"   ");
                                    }
                                    else if(i=10)
                                    {
                                                    printf(i,"   ");
                                    }
    
                                    for(int j=1;j<=10;j++)
                                    {
                                                    printf(array2D[i][j]," /n");
                                    }
    
                    }
                    }
    
    
    void PlayerPlaceShip(char array2D[10][10], char ship[50], int size)
    {
                    int row=0;
                    int col=0;
                    int go;
                    go=1;
                    char dir;
                    int test;
    
                    do
                    {
                                    if(go==0) printf("Invalid move, please re-enter your choice./n");
                                    go=1;
                                    printf("/n Choose what coordinate for your "ship" to start in:"/n "Row: ";
    
                                    char c, row;
    
                                    printf("Column: ");
                                    char c, col;
    
                                    if(row>10 || row<1 || col<1 || col>10)
                                    {
                                                    go=0;
                                                    continue;
                                    }
                                    if(array2D[row][col]!='x')
                                    {
                                                    go=0;
                                                    continue;
                                    }
                    }while(go==0);
    
    
        do
                    {
    
    if(test==0) printf("Invalid direction, please re-enter the info."/n);
    	test=1;
    				printf("Now choose which direction to finish the ship in (l,r,u,d): ");
    	char c, dir;
    
    	switch(dir)
    				{
    	case 'l':
    								if(col-size>=1)
    								{
    									for(int i=0;i<=size-1;i++)
    												{
    													if(array2D[row][col-i]!='x')
    																{
    																	test=0;
    																	continue;
    																}
    												}
    								}
    					else
    								{
    									test=0;
    												continue;
    								}
    								if(test=1)
    								{
    												for(int x=0;x<=size-1;x++)
    												{
    																array2D[row][col-x]=ship[0];
    												}
    								}
    								break;
    
    
    				case 'r':
    								if(col+size<=10)
    								{
    									for(int i=0;i<=size-1;i++)
    												{
    													if(array2D[row][col+i]!='~')
    																{
    																	test=0;
    																	continue;
    																}
    												}
    								}
    								else
    								{
    									test=0;
    												continue;
    								}
    								if(test=1)
    								{
    									for(int x=0;x<=size-1;x++)
    												{
    																array2D[row][col+x]=ship[0];
    												}
    								}
    								break;
    
    				case 'u':
    								if(row-size>=1)
    								{
    									for(int i=0;i<=size-1;i++)
    												{
    													if(array2D[row-i][col]!='~')
    																{
    																	test=0;
    																	continue;
    																}
    												}
    								}
    					else
    								{
    									test=0;
    												continue;
    								}
    								if(test=1)
    								{
    												for(int x=0;x<=size-1;x++)
    												{
    																array2D[row-x][col]=ship[0];
    												}
    								}
    								break;
    
    				case 'd':
    								if(row+size<=10)
    								{
    									for(int i=0;i<=size-1;i++)
    												{
    													if(array2D[row+i][col]!='~')
    																{
    																	test=0;
    																	continue;
    																}
    												}
    								}
    					else
    								{
    									test=0;
    												continue;
    								}
    								if(test=1)
    								{
    									for(int x=0;x<=size-1;x++)
    												{
    																array2D[row+x][col]=ship[0];
    												}
    								}
    				}
    
    }while(test==0);
    
    
    }
    printf(" Current Score:%d\n", score);
    fgetc("%d",&input);
    array2D[input] ='X';
    }

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Next time, please be more specific about what errors you're getting. Considering I can't even come close to compiling your code, I'm assuming you're getting lots of compile errors. For starters, on line 6:
    Code:
    void GameIniti, DisplayBoard, PlayerPlaceShip;
    {
        ...
    What are you trying to do? Is that supposed to be a function declaration? If so, you need a parameter list. Are those supposed to be variables? You can't have void variables, and also, you can't just have code inside { } unless it's inside a function.

    On line 24:
    Code:
        int 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
    This line is declaring variables of type integer, with names 1, 2, 3, etc. You can't have a name that begins with a digit. I think you don't want to declare these anyways, just use the number 7 when you want a 7.

    I'm going to stop there and suggest you do some serious tutorial reading (we have some here). Google will also help you out with this. Then, write some small example programs and make sure you understand the basic concepts and rules of programming.

    When you have all that down pat, start working on your battleship program in small chunks, and test as you go. Then you will only have to tackle a few problems at a time instead of a few hundred.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my upcoming UNO card game :)
    By Hussain Hani in forum Game Programming
    Replies: 5
    Last Post: 01-24-2008, 01:19 AM
  2. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 11:03 AM
  3. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  4. Engine <=> DX/OGL | c++ ?
    By darkcloud in forum Game Programming
    Replies: 6
    Last Post: 05-13-2005, 12:19 AM
  5. Game Designer vs Game Programmer
    By the dead tree in forum Game Programming
    Replies: 8
    Last Post: 04-28-2005, 09:17 PM