11 Replies - 694 Views - Last Post: 30 April 2013 - 12:51 PM Rate Topic: -----

#1 JohnF84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-April 13

Card game WAR using arrays and images

Posted 30 April 2013 - 11:51 AM

I'm having trouble figuring out how to input my shuffle code into the shuffle button and getting my program to add the score for each player as each hand is determined. Can anyone help? I don't want anyone to do the work for me, I just want to know how to complete it.

Public Class Form1
    Dim img1, img2, img3, p1p, p2p, dec As Image
    Dim value(11) As Integer

    Private Sub btnShuffle_Click(sender As System.Object, e As System.EventArgs) Handles btnShuffle.Click

    End Sub

    Private Sub btnDraw_Click(sender As System.Object, e As System.EventArgs) Handles btnDraw.Click

        boom(img1)
        Player1Play.Image = img1
        boom(img2)
        Player2Play.Image = img2
        boomer(img3)
        Decision.Image = img3
        p1p = Player1Play.Image
        p2p = Player2Play.Image
        dec = Decision.Image
    End Sub

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
        P1score.Text = 0
        P2score.Text = 0
    End Sub

    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
        Close()
    End Sub

    Public Sub shuffel()
        Dim switch, number_of_cards, value(51), tempval As Integer
        Dim tempcard, card(12) As Image

        number_of_cards = 52

        For i = 1 To number_of_cards
            switch = Int(Rnd() * number_of_cards + 1)
            tempval = value(i)
            value(i) = value(switch)
            value(switch) = tempval
            tempcard = card(i)
            card(i) = card(switch)
            card(switch) = tempcard
        Next
    End Sub
    Sub valu(ByRef bingo)

        Dim rand, values(12) As Integer

        values(1) = 1
        values(1) = 14
        values(1) = 27
        values(1) = 40
        values(2) = 2
        values(2) = 15
        values(2) = 28
        values(2) = 41
        values(3) = 3
        values(3) = 16
        values(3) = 29
        values(3) = 42
        values(4) = 4
        values(4) = 17
        values(4) = 30
        values(4) = 43
        values(5) = 5
        values(5) = 18
        values(5) = 31
        values(5) = 44
        values(6) = 6
        values(6) = 19
        values(6) = 32
        values(6) = 45
        values(7) = 7
        values(7) = 20
        values(7) = 33
        values(7) = 46
        values(8) = 8
        values(8) = 21
        values(8) = 34
        values(8) = 47
        values(9) = 9
        values(9) = 22
        values(9) = 35
        values(9) = 48
        values(10) = 10
        values(10) = 23
        values(10) = 36
        values(10) = 49
        values(11) = 11
        values(11) = 24
        values(11) = 37
        values(11) = 50
        values(12) = 12
        values(12) = 25
        values(12) = 38
        values(12) = 51
        values(13) = 13
        values(13) = 26
        values(13) = 39
        values(13) = 52
    End Sub
    Sub boom(ByRef imgPop)

        Dim intRand As Integer

        intRand = Int(Rnd(51) * 10) + 1

        If intRand = 1 Then
            imgPop = My.Resources.aceh
        ElseIf intRand = 2 Then
            imgPop = My.Resources.twoh
        ElseIf intRand = 3 Then
            imgPop = My.Resources.threeh
        ElseIf intRand = 4 Then
            imgPop = My.Resources.fourh
        ElseIf intRand = 5 Then
            imgPop = My.Resources.fiveh
        ElseIf intRand = 6 Then
            imgPop = My.Resources.sixh
        ElseIf intRand = 7 Then
            imgPop = My.Resources.sevenh
        ElseIf intRand = 8 Then
            imgPop = My.Resources.eighth
        ElseIf intRand = 9 Then
            imgPop = My.Resources.nineh
        ElseIf intRand = 10 Then
            imgPop = My.Resources.tenh
        ElseIf intRand = 11 Then
            imgPop = My.Resources.jackh
        ElseIf intRand = 12 Then
            imgPop = My.Resources.queenh
        ElseIf intRand = 13 Then
            imgPop = My.Resources.kingh
        ElseIf intRand = 14 Then
            imgPop = My.Resources.acec
        ElseIf intRand = 15 Then
            imgPop = My.Resources.twoc
        ElseIf intRand = 16 Then
            imgPop = My.Resources.threec
        ElseIf intRand = 17 Then
            imgPop = My.Resources.fourc
        ElseIf intRand = 18 Then
            imgPop = My.Resources.fivec
        ElseIf intRand = 19 Then
            imgPop = My.Resources.sixc
        ElseIf intRand = 20 Then
            imgPop = My.Resources.sevenc
        ElseIf intRand = 21 Then
            imgPop = My.Resources.eightc
        ElseIf intRand = 22 Then
            imgPop = My.Resources.ninec
        ElseIf intRand = 23 Then
            imgPop = My.Resources.tenc
        ElseIf intRand = 24 Then
            imgPop = My.Resources.jackc
        ElseIf intRand = 25 Then
            imgPop = My.Resources.queenc
        ElseIf intRand = 26 Then
            imgPop = My.Resources.kingc
        ElseIf intRand = 27 Then
            imgPop = My.Resources.aced
        ElseIf intRand = 28 Then
            imgPop = My.Resources.twod
        ElseIf intRand = 29 Then
            imgPop = My.Resources.threed
        ElseIf intRand = 30 Then
            imgPop = My.Resources.fourd
        ElseIf intRand = 31 Then
            imgPop = My.Resources.fived
        ElseIf intRand = 32 Then
            imgPop = My.Resources.sixd
        ElseIf intRand = 33 Then
            imgPop = My.Resources.sevend
        ElseIf intRand = 34 Then
            imgPop = My.Resources.eightd
        ElseIf intRand = 35 Then
            imgPop = My.Resources.nined
        ElseIf intRand = 36 Then
            imgPop = My.Resources.tend
        ElseIf intRand = 37 Then
            imgPop = My.Resources.jackd
        ElseIf intRand = 38 Then
            imgPop = My.Resources.queend
        ElseIf intRand = 39 Then
            imgPop = My.Resources.kingd
        ElseIf intRand = 40 Then
            imgPop = My.Resources.aces
        ElseIf intRand = 41 Then
            imgPop = My.Resources.twos
        ElseIf intRand = 42 Then
            imgPop = My.Resources.threes
        ElseIf intRand = 43 Then
            imgPop = My.Resources.fours
        ElseIf intRand = 44 Then
            imgPop = My.Resources.fives
        ElseIf intRand = 45 Then
            imgPop = My.Resources.sixs
        ElseIf intRand = 46 Then
            imgPop = My.Resources.sevens
        ElseIf intRand = 47 Then
            imgPop = My.Resources.eights
        ElseIf intRand = 48 Then
            imgPop = My.Resources.nines
        ElseIf intRand = 49 Then
            imgPop = My.Resources.tens
        ElseIf intRand = 50 Then
            imgPop = My.Resources.jacks
        ElseIf intRand = 51 Then
            imgPop = My.Resources.queens
        ElseIf intRand = 52 Then
            imgPop = My.Resources.kings
        Else
            MessageBox.Show("Error")
        End If
    End Sub

    Sub boomer(ByRef imgPopper)

        Dim inRand As Integer
        If inRand = 1 Then
            imgPopper = My.Resources.winleft
        ElseIf inRand = 2 Then
            imgPopper = My.Resources.winright
        ElseIf inRand = 3 Then
            imgPopper = My.Resources.tie
        Else
            MessageBox.Show("Error 2")
        End If
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Randomize()


This post has been edited by AdamSpeight2008: 30 April 2013 - 11:53 AM
Reason for edit:: correcting code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Card game WAR using arrays and images

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:01 PM

Since vb.net is an object orientated programming language, it allows you to define your own object classes. Have you consider defining a Card class?

It good programming practice to not repeat yourself, so have think is it possible to write a generic swap method?
Was This Post Helpful? 0
  • +
  • -

#3 JohnF84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-April 13

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:12 PM

View PostAdamSpeight2008, on 30 April 2013 - 12:01 PM, said:

Since vb.net is an object orientated programming language, it allows you to define your own object classes. Have you consider defining a Card class?

It good programming practice to not repeat yourself, so have think is it possible to write a generic swap method?



I guess I don't understand what you are talking about. I just started writing VB code back in January.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9392
  • View blog
  • Posts: 35,271
  • Joined: 12-June 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:16 PM

He is saying that Vb.NET operates on objects.. objects are made from classes.. Do you have a 'card' class? How about a 'deck' class?

If you look around you will find this is a pretty common homework assignment.
Was This Post Helpful? 0
  • +
  • -

#5 JohnF84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-April 13

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:25 PM

Can you point my toward a couple of them? I can't seem to find any of them.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9392
  • View blog
  • Posts: 35,271
  • Joined: 12-June 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:26 PM

Oh come on.. basic research chap!
Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:31 PM

Collections are Zero Index Based.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#8 JohnF84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-April 13

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:32 PM

Is there anything wrong with the coding I'm using right now? I have to have this program done by Thursday 10am EST.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:42 PM

Also consider using Functions instead of ByRef and collecions.
Was This Post Helpful? 0
  • +
  • -

#10 JohnF84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-April 13

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:45 PM

I'm sorry buy you are talking above my head. I haven't learned any of this. I'm taking this class in a local community college.
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:46 PM

View PostJohnF84, on 30 April 2013 - 08:32 PM, said:

Is there anything wrong with the coding I'm using right now? I have to have this program done by Thursday 10am EST.


I don't know. Does it meet the specification and requirements?

I've pointed out lots of issues with the code. To me your are using old and outdated VB6 coding approaches to the problem, take some time out to research and experiment with more modern .net approaches. It'll be worth it.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9392
  • View blog
  • Posts: 35,271
  • Joined: 12-June 08

Re: Card game WAR using arrays and images

Posted 30 April 2013 - 12:51 PM

... so this is your assignment and you haven't learned about "byval/byref", classes, objects, or what not? I guess I always learned objects before collections like arrays. Oh well.

Things that confuse me - the sub 'valu'... you have an array called 'values'.. and it has 12 spots in it.. yet you seem to be over writing the spots multiple times.

values(1) = 1
values(1) = 14
values(1) = 27
values(1) = 40



What is the value of values(1)? The answer is 40. 'values(12) As Integer' doesn't magically stack those numbers in the (1) spot.. they are over written.

What you, probably, need there is an array of length 52.. *AND* start your index counting at 0, not 1.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1