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

Username:   Password: 
 RegisterRegister   
 Battleship Game
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheXploder




PostPosted: Tue Jan 20, 2004 9:40 pm   Post subject: Battleship Game

Here is the soure code to the Battleship Game I made.
Notes:
* do not drag when holding the left-mouse-button, and don't verlap the ships. Sad

I'll add a check later... Smile

** the AI could be better. Sad

*** Write only capital letters.

How to play?

mouse left-click - places ship.
mouse right-click - increases size of ship placed.
key arrow right, or left - spins the ship.

But anyway here it is, enjoy Razz :



BattleShipV1.0.zip
 Description:

Download
 Filename:  BattleShipV1.0.zip
 Filesize:  4.27 KB
 Downloaded:  932 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
poly




PostPosted: Tue Jan 20, 2004 10:38 pm   Post subject: (No subject)

bravo!!!! That is very well done, for not using any graphics (like drawn graphics using paint etc). If thats your final project you will get a pretty damn good mark!
TheXploder




PostPosted: Thu Jan 22, 2004 10:10 am   Post subject: (No subject)

thanx, any more comments or suggestions?
Smile
we64




PostPosted: Tue Jan 27, 2004 6:36 pm   Post subject: (No subject)

great program, well done...
I would like to see it with graphics, that will be so cool...
shorthair




PostPosted: Thu Jan 29, 2004 12:07 pm   Post subject: (No subject)

Awsome job , get the graphics and i throw in some BITS , keep up hte good code , reminds me of my battleship game , my was alot messier than yours Shocked
sport




PostPosted: Thu Jan 29, 2004 12:23 pm   Post subject: (No subject)

Great Program.
Paul




PostPosted: Thu Jan 29, 2004 12:26 pm   Post subject: (No subject)

And to think... I was a part of it...
*gets glares from everyone*
I WAS part of the testing!!!
TheXploder




PostPosted: Thu Jan 29, 2004 12:36 pm   Post subject: (No subject)

But don't you think the AI is well how do you put it in the right words, STUPID, Laughing, Gotta fix that I guess.

so lets say the 2 place sip is located here as a '1':
|0|0|0|0|
|0|1|1|0|
|0|0|0|0|

and then the computer hits it and then the '1' is replaced by an 'x':

|0|0|0|0|
|0|x|1|0|
|0|0|0|0|

*so now the next random procces should only randomly choose to go up, left, right, or down...

when it misses the next turn and chooses wrong, the old cordinate should be retreated and randomly choose again...

Thats my problem right now... And imagine 3 place ships..
Graphics are easy game... (Just need to draw them)
Paul




PostPosted: Thu Jan 29, 2004 1:02 pm   Post subject: (No subject)

So once it hits something, it has to store that co-ordinate and hit next to it?
TheXploder




PostPosted: Thu Jan 29, 2004 1:28 pm   Post subject: (No subject)

yes something like that, ohh, let's make a quick program to simulate the placement.. here..:
code:

var lengthOfArray : int := 10

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

for row : 1 .. lengthOfArray
    for col : 1 .. lengthOfArray
        map (row, col) := 0
    end for
end for

var x : int := Rand.Int (1, 5)
var y : int := Rand.Int (1, 5)
var sizeOfShip : int := Rand.Int (1, 4)
var direction : int := Rand.Int (0, 1)

proc ship (x, y, size, dir : int)
    if dir = 1 and size = 1 then
        map (x, y) := 1
        elsif dir = 0 and size = 1 then
    end if

    if dir = 1 and size = 2 then
        map (x, y) := 1
        map (x, y + 1) := 1
    elsif dir = 0 and size = 2 then
        map (x, y) := 1
        map (x + 1, y) := 1
    end if

    if dir = 1 and size = 3 then
        map (x, y) := 1
        map (x, y + 1) := 1
        map (x, y + 2) := 1
    elsif dir = 0 and size = 3 then
        map (x, y) := 1
        map (x + 1, y) := 1
        map (x + 2, y) := 1
    end if

    if dir = 1 and size = 4 then
        map (x, y) := 1
        map (x, y + 1) := 1
        map (x, y + 2) := 1
        map (x, y + 3) := 1
    elsif dir = 0 and size = 4 then
        map (x, y) := 1
        map (x + 1, y) := 1
        map (x + 2, y) := 1
        map (x + 3, y) := 1
    end if
end ship

ship (x, y, sizeOfShip, direction)

for row : 1 .. lengthOfArray
    for col : 1 .. lengthOfArray
        put map (row, col)..
    end for
    put ""
end for
TheXploder




PostPosted: Thu Jan 29, 2004 6:37 pm   Post subject: (No subject)

ohh, I updated it...:
code:

%Variables/Declearation of Variables

View.Set ("offscreenonly")

var lengthOfArray : int := 10

var map : array 1 .. lengthOfArray, 1 .. lengthOfArray of string

for row : 1 .. lengthOfArray
    for col : 1 .. lengthOfArray
        map (row, col) := "0"
    end for
end for

% Computer AI attacking Variables..
var xattack, yattack : int

var AIrandXArea, AIrandYArea : int := 4
var AIShootDir : int

var computerHits : boolean
var saveCoordinate : string := ""

computerHits := false

var sizeOfShip : int := Rand.Int (1, 4)
var direction : int := Rand.Int (0, 1)

proc ship (x, y, size, dir : int)
    if dir = 1 and size = 1 then
        map (x, y) := "1"
    elsif dir = 0 and size = 1 then
    end if

    if dir = 1 and size = 2 then
        map (x, y) := "1"
        map (x, y + 1) := "1"
    elsif dir = 0 and size = 2 then
        map (x, y) := "1"
        map (x + 1, y) := "1"
    end if

    if dir = 1 and size = 3 then
        map (x, y) := "1"
        map (x, y + 1) := "1"
        map (x, y + 2) := "1"
    elsif dir = 0 and size = 3 then
        map (x, y) := "1"
        map (x + 1, y) := "1"
        map (x + 2, y) := "1"
    end if

    if dir = 1 and size = 4 then
        map (x, y) := "1"
        map (x, y + 1) := "1"
        map (x, y + 2) := "1"
        map (x, y + 3) := "1"
    elsif dir = 0 and size = 4 then
        map (x, y) := "1"
        map (x + 1, y) := "1"
        map (x + 2, y) := "1"
        map (x + 3, y) := "1"
    end if
end ship

proc Shoot
    if computerHits = true then

        randint (AIShootDir, 1, 4)
    else
        randint (xattack, 1, AIrandYArea)
        randint (yattack, 1, AIrandYArea)
    end if
end Shoot

Shoot
ship (1, 1, sizeOfShip, direction)

loop
    for row : 1 .. lengthOfArray
        for col : 1 .. lengthOfArray
            map (row, col) := "0"
        end for
    end for

    ship (1, 1, sizeOfShip, direction)

    put intstr (xattack) + "," + intstr (yattack)

    put computerHits

    map (xattack, yattack) := "x"

    Shoot
   
    if map (xattack, yattack) = "1" then
        put "Computer Hits"
        computerHits := true
        saveCoordinate := intstr (xattack) + "," + intstr (yattack)
        put "Saved Coordinate: ", saveCoordinate
        put ""
    else
        put "Computer Misses"
        put ""
        put ""
        computerHits := false
    end if

    computerHits := false

    for row : 1 .. lengthOfArray
        for col : 1 .. lengthOfArray
            put map (row, col) ..
        end for
        put ""
    end for

    delay (1000)

    View.Update
    cls
end loop
white_dragon




PostPosted: Sat Feb 07, 2004 5:54 pm   Post subject: (No subject)

i encountered some troubles and problems in the program. but it looks and sounds really good!
Cervantes




PostPosted: Sat Feb 07, 2004 6:19 pm   Post subject: (No subject)

good work, I like it. fix a few bugs and it'll be super!
the annoying bug is the text display messing up Confused you should make it so that it clears the field after you entered the coordinate. or clear it as soona s its your turn to choose again.
Andy




PostPosted: Sat Feb 07, 2004 6:24 pm   Post subject: (No subject)

u should do the starwarz version, its harder cuz the blocks r hexagons
TheXploder




PostPosted: Sat Feb 07, 2004 6:26 pm   Post subject: (No subject)

never heard of a starwarz version.. can you xplain
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 22 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: