April 19th, 2005, 08:10 PM
|
#1 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
How do I add 3X3 array
1 2 1
2 1 1
2 1 1
if I wanted to add the first row together how could I do that? 1 + 2 + 2 ?
sum ={0,0} + {1,0} + {2,0}
I'm using Studio .Net with VB to write this.
redfox
__________________
For the Emperor, there were the Jedi. For the Evil Empire of Microsoft, there is a penguin.
|
| |
April 19th, 2005, 08:27 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Jun 2003 Location: NJ
Posts: 2,467
|
Do you mean row or column? |
| |
April 19th, 2005, 08:34 PM
|
#3 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
I actually I'm doing a tic tac toe game and I figured if i had the game check the rows and the columns it could figure out who wins. ......so both |
| |
April 19th, 2005, 08:41 PM
|
#4 (permalink)
| | Ultimate Member
Join Date: Jan 2003 Location: MA / NH
Posts: 1,497
| Quote: |
Originally Posted by redfoxstorm I actually I'm doing a tic tac toe game and I figured if i had the game check the rows and the columns it could figure out who wins. ......so both |
Well as far as a tic tac toe game, what if they make a diagonal path. You’re gonna be setting yourself up for a lot of needless coding if you do it that way.
Instead of using a multi-dimensional array, why don’t you use three simple arrays?
-Blaze |
| |
April 19th, 2005, 08:44 PM
|
#5 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
| |
| |
April 19th, 2005, 10:14 PM
|
#6 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
the assignment calls for me to make a class that has a private data of 3 by 3 integer array? The constructor should initialized the empty board to all zeros.
Doesn't this work for the 3 by 3 Array? Code: Public Class CTicTacToe
Inherits Object
Private grid As Array
Public Sub New()
Dim grid1 As Integer(,)
grid1 = New Integer(,) {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
End Sub
Public Sub grid1(,){{byVal label1.text As Integer, ByVal label2.text As integer, ByVal label3.text As integer},{{ByVal label4.text As Integer, ByVal Label5.text As Integer, ByVal Label6.text As Integer}, {ByVal label7.text As Integer, ByVal Label8.text As Integer, ByVal Label9.text As Integer}} |
| |
April 19th, 2005, 10:15 PM
|
#7 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
|
I'd still do a multi-dimensional array. IMO it actually would be easier than three simple arrays because you can do this to sum your diagonal rows: Code: for i = 0 to 2
mySum1 = myArray(i,i)
mySum2 = myArray(i,2-i)
next to add them together, you would do this: Code: mySum = myArray(row,column) + myArray(row,column) + myArray(row,column) You can also throw things into loops which might make things easier.
EDIT: Ewwwww, you guys are doing classes in VB? That's like hot rodding a chevy nova! |
| |
April 19th, 2005, 11:17 PM
|
#8 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
| Quote: |
Ewwwww, you guys are doing classes in VB? That's like hot rodding a chevy nova!
| Is that like awesome or bad?
Red |
| |
April 20th, 2005, 12:52 AM
|
#9 (permalink)
| | Ultimate Member
Join Date: Dec 2004
Posts: 1,558
| Quote: |
Is that like awesome or bad?
| Superfluous really. There isn't any real, legitimate reason to be using classes in VB, especially at the level it's being used at. It's pointless, like "hot rodding a chevy nova" 
__________________
"Be quiet, Brain, or I'll stab you with a Q-tip"
-Homer Simpson
|
| |
April 20th, 2005, 07:17 PM
|
#10 (permalink)
| | Member
Join Date: Feb 2005
Posts: 386
|
Hey, since I don't have to have an array in the program...this is as far as I've gotten with my tictactoe program
I just need to make a way to check my results after each click?
I think this is where the class comes in at. Code:
Public Class Form1
Dim User1 As Integer
Dim User2 As Integer
Dim Usersumx As Integer
Dim Usersumo As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
User2 = 0
User1 = 1
Label10.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
User1 = 0
User2 = 2
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
If user1 = 1 Then
Label1.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label1.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
If User1 = 1 Then
Label2.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label2.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
If User1 = 1 Then
Label3.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label3.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
If User1 = 1 Then
Label4.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label4.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
If User1 = 1 Then
Label5.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label5.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
If User1 = 1 Then
Label6.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label6.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
If User1 = 1 Then
Label7.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label7.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click
If User1 = 1 Then
Label8.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label8.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label9.Click
If User1 = 1 Then
Label9.Text = " X "
Usersumx = Usersumx + 1
End If
If User2 = 2 Then
Label9.Text = " 0 "
Usersumo = Usersumo + 1
End If
End Sub
End Class |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |