# Please total novice for battleships

This is a discussion on Please total novice for battleships within the C Programming forums, part of the General Programming Boards category; Good evening all, im really sorry for having to post my code like this however ive complete mucked up everything. ...

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. 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. 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. How utterly sad for you.

5. 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