Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Battleship Gameboard
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
apython1992




PostPosted: Fri May 27, 2011 8:58 am   Post subject: RE:Battleship Gameboard

That's better. Right now it has nothing to do with arrays, and everything to do with allowing the user to enter in a set of co-ordinates for ship placement. One of the first things you need is to ask for user input. Do you know how to do this?
Sponsor
Sponsor
Sponsor
sponsor
penny_k1994




PostPosted: Fri May 27, 2011 6:04 pm   Post subject: RE:Battleship Gameboard

no i dont can you please help me with that?
apython1992




PostPosted: Fri May 27, 2011 9:53 pm   Post subject: RE:Battleship Gameboard

http://www.beens.org/turing/Turing_018___Get.htm
penny_k1994




PostPosted: Fri May 27, 2011 11:29 pm   Post subject: RE:Battleship Gameboard

ok thank you but when i run it it says "string literal ends at end of line" how do i fix that?

var ship:string
var coordinates:string
var score:int:=0
var A:array 1..10 of int
var B:array 1..10 of int
var C:array 1..10 of int
var D:array 1..10 of int
var E:array 1..10 of int
var F:array 1..10 of int
var G:array 1..10 of int
var H:array 1..10 of int
var column:int
var row:int
put "Place your 5 ships on the board while the opponent is placing theirs"
get coordinates
get coordinates
get coordinates
get coordinates
get coordinates
put ""
put "the locations of your ships are",coordinates"
put "A is the same as A(1)"
loop
put "Where are you going to shoot your cannon? Choose a row and column betwen A1 and H10"
put ""
if ship="A1" then
put "Is Correct!!! Great Job"
score:=score+0
elsif ship="A2" then
put "Is Incorrect Sorry"
score:=score+0
elsif ship="A3" then
put "Is Incorrect Sorry"
score:=score+1
end if
end loop
Tony




PostPosted: Sat May 28, 2011 12:04 am   Post subject: RE:Battleship Gameboard

Quote:

put "the locations of your ships are",coordinates"
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
penny_k1994




PostPosted: Sat May 28, 2011 10:34 am   Post subject: RE:Battleship Gameboard

that's what i did before and it still says "string literal ends at end of line" how do i fix that?
apython1992




PostPosted: Sat May 28, 2011 11:54 am   Post subject: RE:Battleship Gameboard

He's quoting your code, where there is a mistake. All strings should be surrounded by quotation marks, right? Variable names are not strings, and so they don't need quotation marks. How many quotation marks do you have?
8749236




PostPosted: Sat May 28, 2011 7:04 pm   Post subject: Re: Battleship Gameboard

Tony @ Wed May 25, 2011 7:23 pm wrote:
penny_k1994 @ Wed May 25, 2011 7:12 pm wrote:
why isnt it running?

Because it highlights a line and says something along the lines of "syntax error". This is where you consult the documentation for the valid uses of that particular statement.

Also
Quote:

if ship="A1" then
put "You hit the ship go again "
elsif ship="A2" then
...

10x10 grid is 100 if statements, right? That does not seem like the right path to follow...


How about using "not ="
if it is not equal to the ship position then tell the player you didn't hit, and if is equal and tell the player you hit and you got next round of fire..
I think thats more better than using 100 if statement, that makes people crazy..
Sponsor
Sponsor
Sponsor
sponsor
tyuo9980




PostPosted: Sat May 28, 2011 11:06 pm   Post subject: Re: Battleship Gameboard

read up on 2d arrays.
penny_k1994




PostPosted: Tue May 31, 2011 5:09 pm   Post subject: RE:Battleship Gameboard

yes thats a good idea thank you this is what I have so far can you please help me get started on the board i read up on 2d arrays i just need help getting started:

var ship:string
var coordinates:string
var hit:string
var shipplacement:array 1..10,1..10 of int
var score:int:=0
var A:array 1..10 of int
var B:array 1..10 of int
var C:array 1..10 of int
var D:array 1..10 of int
var E:array 1..10 of int
var F:array 1..10 of int
var G:array 1..10 of int
var H:array 1..10 of int
var column:int
var row:int
put "Place your 5 ships on the board while the opponent is placing theirs"
get coordinates
put "Pick a direction that you want to place your ship North, South, East and West"
get coordinates
put "Pick a direction that you want to place your ship North, South, East and West"
get coordinates
put "Pick a direction that you want to place your ship North, South, East and West"
get coordinates
put "Pick a direction that you want to place your ship North, South, East and West"
get coordinates
put ""
put "The locations of your ships are,coordinates"
put "A is the same as A(1)"
loop
put "Where are you going to shoot your cannon? Choose a row and column betwen A1 and H10"
put ""
if ship= hit then
put "You hit the opponents ship, fire again Smile"
elsif ship not= hit then
put "You mised the opponents ship Sad"
end if
end loop
apython1992




PostPosted: Tue May 31, 2011 6:28 pm   Post subject: RE:Battleship Gameboard

You are trying to store all of your information within a single variable (coordinates). Every time you have the line "get coordinates", you are overwriting what was previously stored there.
Raknarg




PostPosted: Tue May 31, 2011 8:46 pm   Post subject: RE:Battleship Gameboard

As tyuo9980 said before, I would strongly recommend using a 2D array for this. It will save you a lot of pain in the future.
Turing:

var tile : array 1 .. 8, 1 .. 10 of int
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 27 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: