Thread: Please total novice for battleships

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

    Please total novice for battleships

    Good evening all,

    im really sorry for having to post my code like this however ive complete mucked up everything. i got a few snippets of code and need some help piecing them together. however i think part of its in java. what i would like to a decent game of battleships. using mutliplayer as well as a computer on a grid 10 by 10.

    var map : array 1 .. 10, 1 .. 10 of int

    var r, r2 : int

    loop
    for c : 1 .. 10
    for d : 1 .. 10
    map (c, d) := 0
    end for
    end for

    for i : 1 .. 4
    randint (r, 1, 10)
    randint (r2, 1, 10)
    map (r, r2) := 1
    end for

    var dir : int

    for i : 1 .. 3
    randint (r, 1, 10)
    randint (r2, 1, 10)
    randint (dir, 1, 10)
    map (r, r2) := 2
    if dir = 1 then
    if r < 10 and r2 < 10 then
    map (r + 1, r2) := 2
    end if
    else
    if r < 10 and r2 < 10 then
    map (r, r2 + 1) := 2
    end if
    end if
    end for

    for i : 1 .. 2
    randint (r, 1, 10)
    randint (r2, 1, 10)
    randint (dir, 1, 10)
    map (r, r2) := 3
    if dir = 1 then
    if r < 9 and r2 < 10 then
    map (r + 1, r2) := 3
    map (r + 2, r2) := 3
    end if
    else
    if r < 10 and r2 < 9 then
    map (r, r2 + 1) := 3
    map (r, r2 + 2) := 3
    end if
    end if
    end for

    for i : 1 .. 1
    randint (r, 1, 10)
    randint (r2, 1, 10)
    randint (dir, 1, 10)
    map (r, r2) := 4
    if dir = 1 then
    if r < 8 and r2 < 10 then
    map (r + 1, r2) := 4
    map (r + 2, r2) := 4
    map (r + 3, r2) := 4
    end if
    else
    if r < 10 and r2 < 8 then
    map (r, r2 + 1) := 4
    map (r, r2 + 2) := 4
    map (r, r2 + 3) := 4
    end if
    end if
    end for


    var count : int := 0

    for c : 1 .. 10
    for d : 1 .. 10
    if map (c, d) = 1 or map (c, d) = 2 or map (c, d) = 3 or map (c, d) = 4 then
    count := count + 1
    end if
    end for
    end for

    if count = 20 then
    exit
    end if
    end loop


    for c : 1 .. 10
    for d : 1 .. 10
    put map (c, d) ..
    end for
    put ""
    end for

    if there might be any help i look forward to your replies

    regards

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Announcements - C Programming
    Announcements - General Programming Boards

    If that were C code, nobody would help you without code tags and proper indentation. It also helps if you post C code, since we deal in C around here. It's definitely not C or Java. Looks like it might be TI-Basic. You need to find an appropriate forum and not just borrow chunks of code you don't understand or know what language it is. Pick a language, learn it and write your own code.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, Reeves_Monster!

    I'm sorry to say, that code is not C.

    If you want someone to study your code, you have to edit your post, like this:

    click on "Edit Post", and then on "Go Advanced"

    Highlight all your code, and click on the # icon, in the top of the editor window. DON'T HIT ANY OTHER KEY RIGHT NOW, OR YOUR CODE WILL DISAPPEAR! (It will be seen as an edit (cut) of your post).

    Then click on "Save".

    Now your code will at least look like code, a little.

    Right now, you need to study the basics of C (clearly), before you try and "piece together a battleship game".

    But study up, and feel free to ask questions about the functions you'll want for this game. If you don't know how to code a for loop, you aren't ready to write a battleship game just yet.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    How utterly sad for you.

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    i got a few snippets of code and need some help piecing them together. however i think part of its in java. what i would like to a decent game of battleships. using mutliplayer as well as a computer on a grid 10 by 10.
    Gee... here's a thought... Instead of doing Scoop and Poop (i.e. stealing code) why don't you actually learn how to write a program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems in creating a Battleships board
    By TheYeIIowDucK in forum Game Programming
    Replies: 2
    Last Post: 08-27-2010, 05:49 AM
  2. C++ Novice
    By AaronHall in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2008, 05:48 PM
  3. Battleships
    By sucram in forum Game Programming
    Replies: 4
    Last Post: 02-28-2008, 01:30 PM
  4. Replies: 10
    Last Post: 06-17-2005, 10:00 PM
  5. Novice C'er Needs Help
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 05-03-2002, 09:32 AM