Design and conditions
Design and conditions
Design and conditions
Design and conditions
Design and conditions
Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions
Design and conditions Design and conditions
Design and conditions
Go Back  Xtreme Visual Basic Talk > > > Design and conditions


Reply
 
Thread Tools Display Modes
  #1  
Old 02-16-2015, 04:47 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default Design and conditions


Hey,

I've been away from this hobby for awhile, but decided to take it back up again on a new text adventure. I've learned a couple things, forgot a couple thing, lol. The biggest thing is I'll never be good, that finally sunk in. I was looking at discrete math and was like, wow, heavy coding will never be my thing... anyway, I jut can't shake the fun of it... so, it remains a hobby.

I'm trying to find an easy way to code my game, but increase in oop skills. The problem I'm having is with class design, and condition. I can't believe this button condition is giving me problems....

I had the condition playercreation.creationstep in the start of the button click but each click of the button would reset it. I moved it to a module to segregate it, which I've learned through reading is a bad idea, but not sure what else to do...

For classes likely going to have:

room
player
monster
object
item

I have a bad set up. Looking for simple solution that will increase my order, but not break my brain... Thanks

Main Window

Code:
Imports System.Text.RegularExpressions
Class MainWindow

    Dim hero As player = New player
    Dim currentRoom As room = New room
    Dim command As String
    Dim runOption As String
    Public Sub run_command()

        command = input_text.Text

        If runOption = "new game" Then

            ''Start of new game.
            output_text.SelectAll()
            output_text.Selection.Text = ""

            Select Case playercreation.creationStep
                Case 0
                    output_text.AppendText("A pounding headache blocked all recognition of a name. Maybe it would come. It had to. Enter a name below." + vbNewLine)
                    playercreation.creationStep = 1
                Case 1

                    Dim numberPattern As String = "\d"

                    While hero.has_name() = False
                        '' Check entered name for empty value
                        If command = "" Then

                            output_text.AppendText("Thinking harder might have helped. Please enter a name." + vbNewLine)

                            '' Check entered name for numbers.
                        ElseIf Regex.IsMatch(command, numberPattern) Then

                            output_text.AppendText("No, there were no numbers in it." + vbNewLine)

                        Else

                            '' The entered name is accepted.
                            hero.set_name(command)
                           
                        End If

                    End While

                      playercreation.creationStep = 2

            End Select

            '' End of new game
        ElseIf runOption = "load game" Then
            '' Start of load game

        End If

    End Sub

    Public Sub new_game()

        Me.runOption = "new game"

        run_command()

    End Sub

    Public Sub load_game()

        run_command()

    End Sub

End Class
player class

Code:
Public Class player

    Private name As String
    Private hasName As Boolean


    Public Sub set_name(nameSet As String)

        name = nameSet

    End Sub

    Public Function has_name() As Boolean

        If name = "" Then

            Return False

        Else

            Return True

        End If

    End Function

End Class
player creation module

Code:
Module playercreation

    Public creationStep As SByte = 0

End Module

Last edited by JeremyBenson11; 02-16-2015 at 05:03 PM.
Reply With Quote
  #2  
Old 02-16-2015, 05:41 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

oops, I fixes my infinite loop with a couple of Exit Sub commands in my if statement. Still would love any oop ideas though, so I can drop the module if possible...
Reply With Quote
  #3  
Old 02-17-2015, 09:00 PM
JeremyBenson11 JeremyBenson11 is offline
Regular
 
Join Date: Dec 2013
Posts: 50
Default

I've fixed up my hero class with members and properties, but I've run into a bit of a hole in my main program. I'm getting syntax error. In my subs below the main button event are highlighted a little near the parameters. I took out the entire sub and started pasting it back in bit by bit. Not sure why the first case is saying I haven't closed an If statement. It was working fine.

Code:
    Public Sub run_command()

        command = input_text.Text.ToLower
        input_text.Text = ""
        scrollbar.ScrollToBottom()

        If runOption = "new game" Then

            ''Start of new game.
            If playercreation.creationStep = 0 Then

                output_text.SelectAll()
                output_text.Selection.Text = ""

            End If

            Select playercreation.creationStep
                Case 0
                    output_text.AppendText("A pounding headache blocked all recognition of a name. Maybe it would come. It had to. Enter a name below." + vbNewLine + vbNewLine)
                    playercreation.creationStep = 1
                Case 1
                    While hero.Name = ""
                        '' Check entered name for empty value

                        If command = "" Then

                            output_text.AppendText("Thinking harder might have helped. Please enter a name." + vbNewLine)
                            Exit Sub
                            '' Check entered name for numbers.

                        ElseIf command.Length > 12 Then

                            output_text.AppendText("No, it can't be, it must have been less than 12 letters..." + vbNewLine)
                            Exit Sub
                            '' Check for whitespace

                        ElseIf Regex.IsMatch(command, "\s") Then

                            output_text.AppendText("No, it was only one word...")
                            Exit Sub

                            '' Check for numbers
                        ElseIf Regex.IsMatch(command, numberPattern) Then

                            output_text.AppendText("No, there were no numbers in it." + vbNewLine)
                            Exit Sub

                        ElseIf Regex.IsMatch(command, "\W") Then

                            output_text.AppendText("It couldn't have been. Surely there were no strange symbols in it." + vbNewLine)
                            Exit Sub

                        Else

                            '' The entered name is accepted.
                            hero.Name = command

                        End If

                    End While

                    output_text.AppendText("Gender raced through " + hero.Name + "'s " + "mind. Male or female?" + vbNewLine)
                    playercreation.creationStep = 2

                Case 2
            End Select

    End Sub

Last edited by JeremyBenson11; 02-17-2015 at 10:04 PM.
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
Design and conditions
Design and conditions
Design and conditions Design and conditions
Design and conditions
Design and conditions
Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions Design and conditions
Design and conditions
Design and conditions
 
Design and conditions
Design and conditions
 
-->