battleship game help me plaaaaaaese:(

This is a discussion on battleship game help me plaaaaaaese:( within the C Programming forums, part of the General Programming Boards category; hello I am a new member here I need your help I have to write battleship game in c langauge ...

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

    Unhappy battleship game help me plaaaaaaese:(

    hello I am a new member here
    I need your help
    I have to write battleship game in c langauge ??
    I have been write just the biginning and i can not complet the rest can you help me ??



    this my code
    Code:
    #include<stdio.h>
    #include<stdlib.h>
     
    void print2DArray(char array2D[][10])
     
    {
                    int row, col;
                    for(row=0; row<10; row++) {
                                    for(col=0; col<10; col++)
                                                    printf("%c", array2D[row][col]);
                                    printf("\n");
                    }
    }
                    
                    
    int main()
    {
                    char battleship[10][10];
                    int row, column;
                    char ch;
                    char rowArray[10] = "12345678910";  // Changed it so that it is not the same identifier with the int row
                    char columnArray[10] = "ABCDEFGHIJKL";  // Changed it so that it is not the same identifier with the int column
     
                    for(row=0; row<10; row++)
                                    for(column=0; column<10; column++)
                                                    battleship[row][column] = '~';
     
                    print2DArray(battleship);
                    return 0;
    }
    thank you

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Shouldn't you have 2 boards, for 2 players? What specifically do you need help with?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    One thing you need, and don't have, is a game loop. That's the loop that your program makes with every turn or two, until the game ends. You can use a do while loop, or just a while loop, and inside that loop, you need to check if the game is over, switch sides for who's turn it is to play, show the current screen. (You can use one array if your display is smart and knows to only show the player whose turn it is, his own ships, and not the opponents.)

    You have a way to go here.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    4
    i have to this game that player play against the computer
    can you help me to get the game loop??????

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Alright. We need to test to see if the game is won, after marking the last players move on the game grid (the array).

    Some things you need to have:
    Code:
    int won = 0;
    
    while(!won) {  //this is the big game loop
      show the game grid. For now, show both computer and human ships.
      determine who has the move (however you want).  
      ask the player who has the move, to enter a row and column
      print the result - hit or miss
      check if the game is won or not. If it's won, give appropriate message, show the game grid, and set won = 1.
    
    }
    You have a print grid function, does it work OK?
    Who's going to move first, human or computer?

    Try putting that into your program, in main.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    4
    thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  2. C# - Building a SCUMM-like game.. questions
    By Iyouboushi in forum Game Programming
    Replies: 0
    Last Post: 05-24-2008, 10:54 PM
  3. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM
  5. here is my battleship game so far...come try it out
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 04-17-2002, 12:31 PM

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