Results 1 to 6 of 6

Thread: cant fix the errors in my battleships game

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    3

    cant fix the errors in my battleships game

    I am coding a battle ships game from a c++ code I had and i have translated it and ironed out most of the errors however there are a few left which i cant seem to fix plz could you have a look at the code and let me know what you think

    here is the code;
    VB Code:
    1. Imports Microsoft.VisualBasic
    2. Imports System
    3. Module module1
    4.  
    5.     Class
    6.         Sub main()
    7.  
    8.         Public Class GlobalMembersMain
    9.  
    10.             Public Const rows As Integer = 10
    11.             Public Const elements As Integer = 10
    12.  
    13.             Public Shared maxships As Integer = 10
    14.  
    15.             Public Shared matrix(rows - 1, elements - 1) As Integer
    16.         End Sub
    17.  
    18.         Public Shared Sub Clear()
    19.             For i As Integer = 0 To rows - 1
    20.                 For j As Integer = 0 To elements - 1
    21.                     matrix(i, j) = 0
    22.                 Next j
    23.             Next i
    24.         End Sub
    25.  
    26.         Public Shared Sub Show()
    27.             For i As Integer = 0 To rows - 1
    28.                 For j As Integer = 0 To elements - 1
    29.                     Console.Write(matrix(i, j))
    30.                     Console.Write(" ")
    31.                 Next j
    32.                 Console.Write(ControlChars.Lf)
    33.             Next i
    34.         End Sub
    35.  
    36.         Public Shared Function NumberOfShips() As Integer
    37.             Dim c As Integer = 0
    38.  
    39.             For i As Integer = 0 To rows - 1
    40.                 For j As Integer = 0 To elements - 1
    41.                     If matrix(i, j) = 1 Then
    42.                         c += 1
    43.                     End If
    44.                 Next j
    45.             Next i
    46.  
    47.             Return c
    48.         End Function
    49.  
    50.         Public Shared Sub SetShips()
    51.             Dim s As Integer = 0
    52.             Do While s < maxships
    53.                 Dim x As Integer = RandomNumbers.NextNumber() Mod rows
    54.                 Dim y As Integer = RandomNumbers.NextNumber() Mod elements
    55.                 If matrix(x, y) <> 1 Then
    56.                     s += 1
    57.                     matrix(x, y) = 1
    58.                 End If
    59.             Loop
    60.         End Sub
    61.  
    62.         Public Shared Function Attack(ByVal x As Integer, ByVal y As Integer) As Boolean
    63.             If matrix(x, y) = 1 Then
    64.                 matrix(x, y) = 2
    65.                 Return True
    66.             End If
    67.             Return False
    68.         End Function
    69.  
    70.         Shared Function Inputs() As Integer
    71.             RandomNumbers.Seed(time(Nothing))
    72.             GlobalMembersMain.Clear()
    73.             GlobalMembersMain.SetShips()
    74.             Dim pos1 As Integer
    75.             Dim pos2 As Integer
    76.             Dim prompt As SByte
    77.             Do
    78.                 Console.Write("Please input location: ")
    79.             cin >> pos1 >> pos2
    80.                 If GlobalMembersMain.Attack(pos1, pos2) Then
    81.                     Console.Write("You got me! : )")
    82.                     Console.Write(ControlChars.Lf)
    83.                 Else
    84.                     Console.Write("Sorry no ship at that position!")
    85.                     Console.Write(ControlChars.Lf)
    86.                 End If
    87.                 Console.Write("Number of ships left: ")
    88.                 Console.Write(GlobalMembersMain.NumberOfShips())
    89.                 Console.Write(ControlChars.Lf)
    90.                 Console.Write("Do you want to surrender (y/n)? ")
    91.             cin >> prompt
    92.                 If prompt = AscW("y"c) Then
    93.                     Exit Do
    94.                 End If
    95.             Loop
    96.             Console.Write("Game over!")
    97.             Console.Write(ControlChars.Lf)
    98.             GlobalMembersMain.Show()
    99.             System("pause")
    100.             Return 0
    101.         End Function
    102.     End Class
    103.  
    104. End Module
    Last edited by MAG x ZOMBIES; Oct 23rd, 2014 at 05:38 AM. Reason: to make easier to see

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: cant fix the errors in my battleships game

    Whats wrong with it ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: cant fix the errors in my battleships game

    1) no one's going to fix your code for you blindly. Put some effort. At least mark the line(s) where you're getting errors and what the errors are.
    2) No one like looking at a wall of code like that. Next time, use [code][/code] or [highlight=XXX][/highlight] tags (where XXX is the languages (SQL, VB, VB.NET, C#, etc)) It preserves the formatting and makes it easier to read. Right now it just lookslikeasentencewithnospacesinit.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    3

    Re: cant fix the errors in my battleships game

    sorry I haven't been on in a while internet has been down > OK cheers for the info techgnome but it was my first post and I will remember for next time.

    but the errors are that it can,t find the Sub Main and it expects a identifier at the end of the line five where it says class for the first time and if i put anything there it mess's the whole code up

    lines :
    5 and 6
    Last edited by MAG x ZOMBIES; Oct 23rd, 2014 at 05:39 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2014
    Posts
    3

    Re: cant fix the errors in my battleships game

    Moderators please close this thread as i am scrapping the program and working on it from scratch again.

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: cant fix the errors in my battleships game

    Quote Originally Posted by MAG x ZOMBIES View Post
    Moderators please close this thread as i am scrapping the program and working on it from scratch again.
    You can post the working code here when you redo the above code.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width