battleships game
battleships game
battleships game
battleships game
battleships game
battleships game battleships game battleships game battleships game battleships game battleships game battleships game battleships game
battleships game battleships game
battleships game
Go Back  Xtreme Visual Basic Talk > > > battleships game


Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2013, 02:07 PM
greentea greentea is offline
Newcomer
 
Join Date: Jan 2013
Posts: 2
Default battleships game


Hi guys,
I am new to this forum and wanted to post this new thread because i didnt seem to find any information that could help me finish the game im currently making.
btw I'm a real noob in programming
I want to make a battleships game. I already made two gameboards(player and computer) using a dynamic arrays and pictureboxes. I already have a code which lets me calculate random numbers for rows/columns/direction but i dont know how i can use these numbers in a way that lets the computer randomly place enemy ships.. I cant really explain further cause i dont understand it..
but if i sometime get finished with the placing of the ships i still need to figure out how to shoot and switch turns between the computer and player...
well, i hope u guys can help me out because im lost!
thx a lot!
i'm using vb 2010 express edition
Attached Files
File Type: zip battleships.zip (76.0 KB, 60 views)
Reply With Quote
  #2  
Old 01-16-2013, 03:18 PM
AtmaWeapon's Avatar
AtmaWeaponbattleships game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Here's how I'd do it:
Code:
* While there are ships to place:
    * Pick a ship.
    * While the ship has not been placed:
        * Pick a random location on the board.
        * Pick an orientation.
        * Place the ship if it can fit there.
I haven't looked at your code, but "Can it fit there?" with 2D arrays and a good guess at a Ship class with a 10x10 board would look something like:
Code:
If horizontal Then
    For x = startPoint.X To startPoint.X + ship.size - 1
        If IsOccupied(x, startPoint.Y) Then
            Return False
        End If
    Next
Else
    For y = startPoint.Y To startPoint.Y + ship.size - 1
        If IsOccupied(startPoint.X, y) Then
            Return False
        End If
    Next
End If

Return True
Might be off-by-one on the size. That's easy to fix.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 01-16-2013, 03:57 PM
greentea greentea is offline
Newcomer
 
Join Date: Jan 2013
Posts: 2
Default

thx for the reply but the code you suggested did not work...
are there any other solutions?
Reply With Quote
  #4  
Old 01-16-2013, 07:27 PM
AtmaWeapon's Avatar
AtmaWeaponbattleships game AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Describe how it didn't work. It wasn't meant to be copy/pasted. The hint was "I haven't looked at your code." You were supposed to look at it and figure out how it would fit in your code. If you're looking for someone to completely finish the game for you I'm afraid you came to the wrong forum.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 01-17-2013, 06:08 AM
DrPunk's Avatar
DrPunkbattleships game DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Always kinda annoys me when I see things like this and says "uses pictureboxes" as though the interface is the most important part of the program.

Got no idea about how any of the logic works, but the pretty pictures look great.

The logic IS the game. The pretty pictures are just a means of displaying it. You could just as easily display the game as text characters.

Ultimately try and get away from "This is how it looks, now how do I make it work looking like this". It should be "This is how it works, now how do I make that look". As shown by AtmaWeapon. His post doesn't care about how anything looks, he's broken the problem down into a number of steps, then it's a case of turning those steps into code. And that practice makes it much easier for us to help because rather than saying "Here's some code, finish it for me!!!" you can ask "Hey, how do I work out if a ship of size AxB will fit into the grid?" and people might be willing to help.
__________________
There are no computers in heaven!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
battleships game
battleships game
battleships game battleships game
battleships game
battleships game
battleships game battleships game battleships game battleships game battleships game battleships game battleships game
battleships game
battleships game
 
battleships game
battleships game
 
-->