12 Replies - 956 Views - Last Post: 03 April 2012 - 02:04 PM Rate Topic: -----

#1 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Design a Visual Basic program that's the same as the simon says

Posted 30 March 2012 - 08:30 AM

Directions: Design a Visual Basic program that is similar to the classic electronic game Simon Says.
Interface: Simon Says has 4 shapes that have the colors green, red, yellow, and blue.
Gameplay: Once the games starts, Simon Says will randomly highlight one of the colors for a brief
second. The user will then have to click the shape with that was highlighted. If the user clicks the
shape that was highlighted then the game moves on to the next round.Each round of the game adds an additional color that the user must remember. Eventually the pattern
will become too large for the user to remember. The game will end when the user guesses an incorrect
sequence.

This is what i have so far.
Public Class frmSSays
    Public intscore As Integer = 0
    Public myNumberList1 As New ArrayList
    Private myNumberList2 As New ArrayList
    Private Sub frmSSays_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        ' ADD TO THE NUMBER LISTS
        myNumberList1.Add(1)
        myNumberList1.Add(2)
        myNumberList1.Add(3)
        myNumberList1.Add(4)
        myNumberList2.Add(1)
        myNumberList2.Add(2)
        myNumberList2.Add(3)
        myNumberList2.Add(4)
    End Sub
    Private Sub change_background(ByRef control As Panel, ByVal color As Color)
        control.BackColor = color
    End Sub
    Private Sub BtnStartSimonSays_Click(sender As System.Object, e As System.EventArgs) Handles BtnStart.Click
        ' START THE TIMER & DONT SHOW THE BUTTONS
        Me.BtnStart.Visible = False
        Me.BtnNext.Visible = False
        Me.Timer1.Enabled = True
    End Sub
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim intReturnedValue As Integer = -1
        Dim random As New Random(Now.Millisecond)
        ' Return a random number from the array list/remove it
        intReturnedValue = myNumberList1.Item(random.Next(0, myNumberList1.Count))
        myNumberList1.Remove(intReturnedValue)
        ' Call a random number/change panel color
        For i As Integer = 0 To intscore
            Select Case intReturnedValue
                Case 1
                    change_background(Me.PanGreen, Color.Green)
                    If Me.PanGreen.BackColor = Color.Green Then
                        Me.Timer1.Enabled = False
                    End If
                Case 2
                    change_background(Me.PanRed, Color.Red)
                    If Me.PanRed.BackColor = Color.Red Then
                        Me.Timer1.Enabled = False
                    End If
                Case 3
                    change_background(Me.PanYellow, Color.Yellow)
                    If Me.PanRed.BackColor = Color.Red Then
                        Me.Timer1.Enabled = False
                    End If
                Case 4
                    change_background(Me.PanBlue, Color.Blue)
                    If Me.PanBlue.BackColor = Color.Blue Then
                        Me.Timer1.Enabled = False
                    End If
            End Select
        Next
    End Sub
    Private Sub PanBlue_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PanBlue.Paint
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.LblScore.Text = "Score: " & intScore
        Me.BtnNext.Visible = True
    End Sub
    Private Sub panRed_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanRed.MouseClick
        ' DECLARE VARIABLES
        Dim intScore As Integer
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
    End Sub
    Private Sub panGreen_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanGreen.MouseClick
        ' DECLARE VARIABLES
        Dim intScore As Integer
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
    End Sub
    Private Sub panYellow_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanYellow.MouseClick
        ' DECLARE VARIABLES
        Dim intScore As Integer
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
    End Sub
    Private Sub BtnNext_Click(sender As System.Object, e As System.EventArgs) Handles BtnNext.Click
        Me.BtnNext.Enabled = False
        Me.BtnStart.Enabled = True
    End Sub
End Class

I don't know how to validate if the user that clicks the pan is correct or not??????????????????

This post has been edited by Atli: 30 March 2012 - 08:32 AM
Reason for edit:: Please use [code] tags when posting code.


Is This A Good Question/Topic? 0
  • +

Replies To: Design a Visual Basic program that's the same as the simon says

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Design a Visual Basic program that's the same as the simon says

Posted 30 March 2012 - 08:45 AM

By 'pan' do you mean 'panel'?

Lines 7-14... Are you hard-coding the sequence? The game is supposed to randomly select the sequence.

you seem to have two lists here... I'm assuming your plan was to have the first be the randomly chosen sequence, and the second be the player pressing sequence.

So just check if the elements of the index match.

If gameSequence[currentPress] = userSequence[currentPress]


I'd really recommend using meaningful names before you confuse yourself.
Was This Post Helpful? 1
  • +
  • -

#3 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Re: Design a Visual Basic program that's the same as the simon says

Posted 02 April 2012 - 05:19 AM

I need to know how to randomize the panels and add 1 each and every time the user has the correct sequence.
Was This Post Helpful? 0
  • +
  • -

#4 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Re: Design a Visual Basic program that's the same as the simon says

Posted 02 April 2012 - 05:26 AM

Please i see that alot of people have viewed my code. can some1 help me out.......
Was This Post Helpful? 0
  • +
  • -

#5 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Re: Design a Visual Basic program that's the same as the simon says

Posted 02 April 2012 - 07:04 AM

OK.... iv gotten a little bit farther from ur guys last visit here.
Heres the code:
Public Class frmSSays
    Public intscore As Integer = 0
    Public intRounds As Integer = 0
    Private intRandomSequence As Integer = 0
    Private intPlayerSequence As Integer = 0
    Public myNumberList1 As New ArrayList
    Private myNumberList2 As New ArrayList
    Private Sub frmSSays_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.BtnNext.Enabled = False
        ' ADD TO THE NUMBER LISTS
        myNumberList1.Add(1)
        myNumberList1.Add(2)
        myNumberList1.Add(3)
        myNumberList1.Add(4)
        myNumberList2.Add(1)
        myNumberList2.Add(2)
        myNumberList2.Add(3)
        myNumberList2.Add(4)
    End Sub
    Public Sub load_timer_event()
        ' DECLARE VARIABLES
        Dim random As New Random(Now.Millisecond)
        ' START THE TIMER & DONT SHOW THE BUTTONS
        Me.btnStart.Visible = False
        Me.btnNext.Visible = False
        Me.Timer1.Enabled = True
        For i = 1 To 4
            Select Case myNumberList1(random.Next(0, 4))
                Case 1
                    Me.PanBlue.BackColor = Color.Navy
                    Me.Timer2.Enabled = True
                Case 2
                    Me.PanGreen.BackColor = Color.ForestGreen
                    Me.Timer2.Enabled = True
                Case 3
                    Me.PanRed.BackColor = Color.Red
                    Me.Timer2.Enabled = True
                Case 4
                    Me.PanYellow.BackColor = Color.Yellow
                    Me.Timer2.Enabled = True
            End Select
            Select Case myNumberList2(random.Next(0, 4))
                Case 1
                    If Me.PanBlue.BackColor = Color.Navy Then
                        Me.Timer2.Enabled = False
                        Me.PanBlue.BackColor = Color.CornflowerBlue
                    End If
                Case 2
                    If Me.PanBlue.BackColor = Color.ForestGreen Then
                        Me.Timer2.Enabled = False
                        Me.PanGreen.BackColor = Color.PaleGreen
                    End If
                Case 3
                    If Me.PanBlue.BackColor = Color.Red Then
                        Me.Timer2.Enabled = False
                        Me.PanRed.BackColor = Color.IndianRed
                    End If
                Case 4
                    If Me.PanBlue.BackColor = Color.Yellow Then
                        Me.Timer2.Enabled = False
                        Me.PanYellow.BackColor = Color.LightYellow
                    End If
            End Select
            ' STOP THE TIMER
            Me.Timer1.Enabled = False
        Next
    End Sub
    Private Sub panBlue_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanBlue.MouseClick
        If Me.Timer1.Enabled = False Then
            ' ADD TO THE SCORE IF CORRECT OR END THE GAME
            intscore += 1
            Me.LblScore.Text = "Score: " & intscore
            Me.BtnNext.Visible = True
            ' SET UP FOR NEXT ROUND
            If intscore > 0 Then
                Me.BtnNext.Text = "Round " & intscore + 1
            End If
        End If
    End Sub
    Private Sub panRed_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanRed.MouseClick
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
        ' SET UP FOR NEXT ROUND
        If intScore > 0 Then
            Me.btnNext.Text = "Round " & intScore + 1
        End If
    End Sub
    Private Sub panGreen_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanGreen.MouseClick
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
        ' SET UP FOR NEXT ROUND
        If intScore > 0 Then
            Me.btnNext.Text = "Round " & intScore + 1
        End If
    End Sub
    Private Sub panYellow_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PanYellow.MouseClick
        ' ADD TO THE SCORE IF CORRECT OR END THE GAME
        intScore += 1
        Me.lblScore.Text = "Score: " & intScore
        Me.btnNext.Visible = True
        ' SET UP FOR NEXT ROUND
        If intScore > 0 Then
            Me.btnNext.Text = "Round " & intScore + 1
        End If
        If intScore > 3 Then
            Me.btnNext.Text = "Round " & (intScore - (Me.lblScore.Text / 2)) + 1
        End If
    End Sub
    Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles BtnNext.Click
        load_timer_event()
    End Sub
    Private Sub change_background(ByRef control As Panel, ByVal color As Color)
        control.BackColor = color
    End Sub
    Private Sub BtnStartSimonSays_Click(sender As System.Object, e As System.EventArgs) Handles BtnStart.Click
        ' DECLARE VARIABLES
        Dim random As New Random(Now.Millisecond)
        ' START THE TIMER & DONT SHOW THE BUTTONS
        Me.BtnStart.Visible = False
        Me.BtnNext.Visible = False
        Me.Timer1.Enabled = True
        For i = 1 To 4
            Select Case myNumberList1(random.Next(0, 4))
                Case 1
                    Me.PanBlue.BackColor = Color.Navy
                    Me.Timer2.Enabled = True
                Case 2
                    Me.PanGreen.BackColor = Color.ForestGreen
                    Me.Timer2.Enabled = True
                Case 3
                    Me.PanRed.BackColor = Color.Red
                    Me.Timer2.Enabled = True
                Case 4
                    Me.PanYellow.BackColor = Color.Yellow
                    Me.Timer2.Enabled = True
            End Select
            Select Case myNumberList2(random.Next(0, 4))
                Case 1
                    If Me.PanBlue.BackColor = Color.Navy Then
                        Me.Timer2.Enabled = False
                        Me.PanBlue.BackColor = Color.CornflowerBlue
                    End If
                Case 2
                    If Me.PanBlue.BackColor = Color.ForestGreen Then
                        Me.Timer2.Enabled = False
                        Me.PanGreen.BackColor = Color.PaleGreen
                    End If
                Case 3
                    If Me.PanBlue.BackColor = Color.Red Then
                        Me.Timer2.Enabled = False
                        Me.PanRed.BackColor = Color.IndianRed
                    End If
                Case 4
                    If Me.PanBlue.BackColor = Color.Yellow Then
                        Me.Timer2.Enabled = False
                        Me.PanYellow.BackColor = Color.LightYellow
                    End If
            End Select
        Next
        ' STOP THE TIMER
        Me.Timer1.Enabled = False
    End Sub
    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim intReturnedValue As Integer = -1
        Dim random As New Random(Now.Millisecond)
        ' Return a random number from the array list/remove it
        intReturnedValue = myNumberList1.Item(random.Next(0, myNumberList1.Count))
        myNumberList1.Remove(intReturnedValue)
        ' Call a random number/change panel color
        For i As Integer = 0 To 100
            intRandomSequence += 1
            Select Case intReturnedValue
                Case 1
                    change_background(Me.PanGreen, Color.PaleGreen)
                    If Me.PanGreen.BackColor = Color.PaleGreen Then
                        Me.BtnNext.Enabled = True
                    End If
                Case 2
                    change_background(Me.PanRed, Color.IndianRed)
                    If Me.PanRed.BackColor = Color.IndianRed Then
                        Me.Timer1.Enabled = False
                        Me.BtnNext.Enabled = True
                    End If
                Case 3
                    change_background(Me.PanYellow, Color.LightYellow)
                    If Me.PanYellow.BackColor = Color.LightYellow Then
                        Me.Timer1.Enabled = False
                        Me.BtnNext.Enabled = True
                    End If
                Case 4
                    change_background(Me.PanBlue,
Color.CornflowerBlue)
                    If Me.PanBlue.BackColor = Color.CornflowerBlue Then
                        Me.Timer1.Enabled = False
                        Me.BtnNext.Enabled = True
                    End If
            End Select
            Me.Timer1.Enabled = False
        Next
    End Sub
End Class


This post has been edited by modi123_1: 02 April 2012 - 07:12 AM
Reason for edit:: code tags - they WRAP the code...

Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Design a Visual Basic program that's the same as the simon says

Posted 02 April 2012 - 02:57 PM

View Postsudokuking, on 02 April 2012 - 06:19 AM, said:

I need to know how to randomize the panels and add 1 each and every time the user has the correct sequence.


What part of that is causing you trouble? Do you not know how to use Random? Do you not know how to add to a List<>?

I don't even see a method for SelectRandomPanel or for AddToSequence... (any naming you like that had these intentions).

If you don't try, then we have no code efforts to help you with. It is YOUR homework after all.
Was This Post Helpful? 1
  • +
  • -

#7 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 05:03 AM

i know how to use a random and how to add to a list. like what you said it's my homework, our teacher doesnt teach us how to do that. i learn how to do it myself. i don't know how to create a SELECTRANDOMPANEL or a ADDTOSEQUENCE function. I don't even know how to create a function..............
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14155
  • View blog
  • Posts: 56,745
  • Joined: 12-June 08

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 06:46 AM

Quote

I don't even know how to create a function..............


A function - it's like a subroutine except it returns a variable.
Was This Post Helpful? 1
  • +
  • -

#9 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 07:54 AM

View Postsudokuking, on 03 April 2012 - 06:03 AM, said:

I don't even know how to create a function..............



You need to stop. Close your textbook. Now open it to page 1. READ it. Don't skim it looking for just the part that matters today. READ it and learn. WORK the exercises. I don't care if you've done them before; you need to do them again. Do no move forward to new material before you have learned and thouroghly comprehend the current material.

If you don't have a solid foundation all of this is going to come crashing on your head. Do not think you can fake your way through it until it one day magically starts making sense. This is not cooking class. If you try that approach all that can happen is you fall further and further behind.
Was This Post Helpful? -1
  • +
  • -

#10 sudokuking   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-March 12

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 08:25 AM

Dude my teacher doesn't even give us textbooks.
Was This Post Helpful? 0
  • +
  • -

#11 Ryano121   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1461
  • View blog
  • Posts: 3,289
  • Joined: 30-January 11

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 08:33 AM

View Postsudokuking, on 03 April 2012 - 04:25 PM, said:

Dude my teacher doesn't even give us textbooks.


You might want to think about getting one then in that case.

If you don't even know how to create a function then go through the wealth of information online that you can uncover with a simple Google search -

How to create a function in VB.NET

Functions and subroutines

But seriously, I don't recommend learning a language through only online material. If you want to get a good grip on a language, you can't go wrong with a good textbook.
Was This Post Helpful? 1
  • +
  • -

#12 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 08:53 AM

View Postsudokuking, on 03 April 2012 - 09:25 AM, said:

Dude my teacher doesn't even give us textbooks.


Then WTF are you paying for? I mean really... You say the prof isn't teaching in class and not supplying text books. So what... They just sit with their feet up and collect tuition money? Is the teacher really not teaching, or is it that you aren't getting anything out of the class? I have a hard time believing the teacher could keep a job if the entire class was drowning with you: Semester after semester.

If the teacher is really doing nothing, then band together with your fellow students and go to the dean. Its your education: TAKE IT.

If the teacher is teaching but you aren't getting anything from it, then go to the book store or Amazon.com and pick up some book(s). You are allowed to learn from as many sources as you like. We have numerous tutorials here: WORK THEM. There is a book list here: Buy one. Become pro-active about your future earning and hiring potential. Its your life: Are you going to remain content with what people give you, or are you going to demand more.

This post has been edited by tlhIn`toq: 03 April 2012 - 08:57 AM

Was This Post Helpful? 0
  • +
  • -

#13 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Design a Visual Basic program that's the same as the simon says

Posted 03 April 2012 - 02:04 PM

View Postsudokuking, on 04 April 2012 - 01:25 AM, said:

Dude my teacher doesn't even give us textbooks.

Wow... what kind of teacher is that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1