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 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
penny_k1994




PostPosted: Wed May 25, 2011 4:02 pm   Post subject: Battleship Gameboard

I am in grade 11 making a battleship board game for my Turing class.


The problem that I am having is that I wan't to make a game board to place the ships onto using arrays but I dont know how to. I want the user to be playing with the computer.


What I have so far is:
var ship
var cannon
array A1..A10
array B1..B10
array C1..C10
array D1..D10
array E1..E10
array F1..F10
array G1..G10
array H1..H10
put "Place your 5 ships on the gameboard while the opponent is placing theirs"
put""
put "Where are you going to shoot your cannon?"
loop
get ship
if ship="A1" then
put "You hit the ship go again Smile"
elsif ship="A2" then
put "Sorry you missed Sad"
elsif ship="A3" then
put "Sorry you missed Sad"
end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed May 25, 2011 4:41 pm   Post subject: RE:Battleship Gameboard

you could read more about using arrays in Turing's documentation -- array and tutorials we have linked to from The Turing Walkthrough
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
RandomLetters




PostPosted: Wed May 25, 2011 6:32 pm   Post subject: RE:Battleship Gameboard

protip: Letters are really numbers in disguise.
penny_k1994




PostPosted: Wed May 25, 2011 7:12 pm   Post subject: Re: Battleship Gameboard

why isnt it running?

var ship
var cannon
var shot: array A1..A10 of int
var shot: array B1..B10 of int
var shot: array C1..C10 of int
var shot: array D1..D10 of int
var shot: array E1..E10 of int
var shot: array F1..F10 of int
var shot: array G1..G10 of int
var shot: array H1..H10 of int
put "Place your 5 ships on the gameboard while the opponent is placing theirs"
put""
put "Where are you going to shoot your cannon?"
loop
get ship
if ship="A1" then
put "You hit the ship go again Smile"
elsif ship="A2" then
put "Sorry you missed Sad"
elsif ship="A3" then
put "Sorry you missed Sad"
end if
end loop
Raknarg




PostPosted: Wed May 25, 2011 7:15 pm   Post subject: RE:Battleship Gameboard

Arrays don't quite work like that. We could explain them here, but it would probably be most beneficial to you if you read the tutorial Tony's supplied you with.
Tony




PostPosted: Wed May 25, 2011 7:23 pm   Post subject: Re: Battleship Gameboard

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...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
penny_k1994




PostPosted: Wed May 25, 2011 7:31 pm   Post subject: Re: Battleship Gameboard

im sorry im an amateur how do i fix it?
Tony




PostPosted: Wed May 25, 2011 7:50 pm   Post subject: RE:Battleship Gameboard

fix what?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
penny_k1994




PostPosted: Wed May 25, 2011 8:01 pm   Post subject: RE:Battleship Gameboard

fix the arrays im an amateur at this and im really bad at it so can you keep it as simple as possible?
Tony




PostPosted: Wed May 25, 2011 9:20 pm   Post subject: RE:Battleship Gameboard

start by reading tutorials and documentation. That's how any of this ever makes sense.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
apython1992




PostPosted: Wed May 25, 2011 9:51 pm   Post subject: Re: RE:Battleship Gameboard

penny_k1994 @ Wed May 25, 2011 8:01 pm wrote:
fix the arrays im an amateur at this and im really bad at it so can you keep it as simple as possible?

Being an amateur is totally OK, everyone had to be at some point. Don't get discouraged by the fact that you aren't getting answers right away; one of the biggest challenges in learning how to program is developing good problem solving skills - figuring out what went wrong, and then why. Do as much as you can to look into the problem yourself (like why there might be a syntax error with your array declarations), and if you get it, that's great, but if not, then we're here to help.

Whenever you come across difficulties in getting programs to run, don't be afraid of the error message - it is actually telling you a whole lot! It's cryptic as all heck before you get used to it, but you'll soon become really good at debugging by following a read error message -> trace back to code -> read documentation/proofread erroneous code -> try again cycle. Of course, you'll also come across logic errors (much more frequently after you become familiar with the syntax of the language), but you'll get into a system for dealing with these as well.
penny_k1994




PostPosted: Wed May 25, 2011 10:00 pm   Post subject: RE:Battleship Gameboard

Thank you Smile ill try again and if i get stuck ill ask you
penny_k1994




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

i fixed up my program to run now i just need help on the arrays please

var ship: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"
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!!! Very Happy Great Job"
score:=score+0
elsif ship="A2" then
put "Is Incorrect Sad Sorry"
score:=score+0
elsif ship="A3" then
put "Is Incorrect Sad Sorry"
score:=score+1
end if
end loop
apython1992




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

Could you be a little more specific? What exactly about the arrays is causing you trouble?
penny_k1994




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

i dont know what the problem is im assuming its the arrays i guess its not i need help with being able to place the ships
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 1 of 2  [ 27 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: