Making a game and ideas
Making a game and ideas
Making a game and ideas
Making a game and ideas
Making a game and ideas
Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas
Making a game and ideas Making a game and ideas
Making a game and ideas
Go Back  Xtreme Visual Basic Talk > > > Making a game and ideas


Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2012, 05:50 PM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Unhappy Making a game and ideas


HI i am trying to make a connect 4 game. Firstly i am wondering what the code is for switch between players and when it is a player1's turn the block will be their color and vice versa for the other player.
Thanks
Reply With Quote
  #2  
Old 12-12-2012, 06:33 PM
Gruff's Avatar
GruffMaking a game and ideas Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Welcome to the forum. Don't forget to read the forum Posting Guidelines.

You write a loop that starts when you press a "Play" button.
At the start of the loop you toggle the player.

If you use an integer for your player variable.
You could use an if statement to toggle the player.
Code:
Player = 2 'Force red to start if that is what you want. Do If Player = 1 then Player = 10 DiskColor = Blue else Player = 1 DiskColor = Red end if 'Game code goes here. Loop Until GameOver

This is just a rough outline. If it were me I would be writing classes that encapsualted the real world objects involved.

For instance...

Public Class clsDisk
Public property PlayerNo
Public Property PlayerName
Public Property PlayerColor
'...
End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 12-12-2012 at 06:43 PM.
Reply With Quote
  #3  
Old 12-12-2012, 06:45 PM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Well i use picture boxes for my boxes and i put them all in an array and name the array shapes but when i try to make a code like shapes.backcolor = color.blue it doesnt work?
or should i not be using an array for this
Reply With Quote
  #4  
Old 12-12-2012, 08:35 PM
passel's Avatar
passelMaking a game and ideas passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

VB.Net is not going to support Control arrays by default. You have to do a little work.
Of course you could draw everything and not use control arrays, but if you want to use control arrays have a look at the links in this thread, especially the last link to our own site tutorial on control arrays.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #5  
Old 12-13-2012, 11:13 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Player = 2
Do
If Player = 1 Then
Player = 10
Shapes(42).BackColor = Color.Blue
Else
Player = 1
Shapes(42).BackColor = Color.Red
End If


Loop Until GameWon

End Sub
End Class
I have this so far but i get an error for the Shapes(42).BackColor = Color.Red
Help?
Reply With Quote
  #6  
Old 12-13-2012, 12:10 PM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Player = 2
i = 1
Do
If Player = 1 Then
Player = 10
Shapes(i) = New PictureBox
With Shapes(i)
.BackColor = Color.Red
End With
Else
Player = 1
Shapes(i) = New PictureBox
With Shapes(i)
.BackColor = Color.Blue
End With

End If

Loop

End Sub
I have updated my code to this, but i still dont have the switching between player thing
Reply With Quote
  #7  
Old 12-13-2012, 01:46 PM
Gruff's Avatar
GruffMaking a game and ideas Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

What I posted earlier was just an example of how to switch players.

Try this example. Run it and Press "No" to see the player switch back and forth. Press "Yes" to quit the loop.

Code:
Public Class Form1 Dim Player As Integer = 2 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Dim Ret As Long = 0 Do If Player = 1 Then Player = 2 Else Player = 1 End If Ret = MessageBox.Show("Player = " & Player & ". Exit Loop?", "", MessageBoxButtons.YesNo) Loop Until Ret = vbYes End Sub End Class

Note: the end condition after the loop statement. If you do not have an ending condition then you will have an infinite loop.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 12-13-2012 at 02:01 PM.
Reply With Quote
  #8  
Old 12-18-2012, 09:58 AM
qwerty123vb qwerty123vb is offline
Newcomer
 
Join Date: Dec 2012
Posts: 14
Default

I am now having trouble making the game end when a person has won.
The code I have is

If Picture1.BackColor = Color.Red and Picture2.BackColor = Color.Red....ect Then
MsgBox("Player2 Wins!!!", MessageButtons.vbOK)
End
End If
Reply With Quote
  #9  
Old 12-18-2012, 10:32 AM
Gruff's Avatar
GruffMaking a game and ideas Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

The 'End' statement by itself if a very bad way to end a program.
It tells the program to end regardless of what may still be running.
This can lead to other errors and issues.

There are two ways to exit a loop.
1) Set your and end condition to a 'true' value. (See my last example.)

2) Use the 'Exit Do' statement from within a 'Do...Loop')
or the 'Exit For' statement from within a 'For...Next' loop.

Edit:
Removed references and links to VB6 help
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 12-20-2012 at 06:29 PM.
Reply With Quote
  #10  
Old 12-19-2012, 03:51 AM
passel's Avatar
passelMaking a game and ideas passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

You should be aware that even though Gruff mentioned some VB6 documentation to get familiar with the basic code control structures and statements of the Visual Basic language, i.e. If statements and Loops, etc., the individual is using VB.Net, and VB6 references will only get you so far. Linking to VB6 example code is less likely to be useful, especially if it is doing any kind of graphics, since they are two very different paradigms.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #11  
Old 12-19-2012, 06:57 AM
AtmaWeapon's Avatar
AtmaWeaponMaking a game and ideas AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Yes, I'm not really sure why you would link to the VB6 documentation at all for a .NET topic, considering it's easy to get to the VB .NET Language Reference. It's also one of the most terrible ways to approach learning a language as a newbie.

qwerty, I suggest finding a book about VB and following that. If you really want to write games, there are books on that specific topic that will have you making functional games much faster than any non-game book. Be open to learning a different language; in particular C and C++ are quite useful and free. Personally I do not believe VB .NET is a good language for developing many kinds of games.

Books are the best way to start as a newbie because they are structured to teach you many skills in a logical progression. Learning from the internet will teach you random, unreliable facts and occasionally lead you useless places like the VB6 documentation when asking .NET questions. VB6 samples are most useful to those that are already familiar with .NET.

The questions you are asking are hard to answer because there's not a "right" way to write code "that switches between players". Determining how to convert tasks like that into lines of code is the "work" part of programming. There's not a book full of tricks; if there were it would require infinite pages. So have a look at a book and see if the answers don't become a little more clear.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #12  
Old 12-20-2012, 10:01 AM
ElderKnightMaking a game and ideas ElderKnight is offline
Senior Contributor

Forum Leader
 
Join Date: Oct 2003
Location: Central Florida
Posts: 1,275
Default

I think you'll find it easier to create a two-dimensional array (8-by-8 or whatever), each cell initialized to zero. Put a "1" or a "2" in a cell as the players indicate a move. Then, use the array values to update your visual display with appropriate colors.

To check for a winner, you'd check every row, every column and every diagonal in the array in a loop to look for four consecutive of the same number, and branch to the game-over logic upon finding any such case.
__________________
-- D.J.

I do not endorse any items advertised within this frame, and regret that the viewer is subjected to such.
Reply With Quote
  #13  
Old 12-20-2012, 06:25 PM
Gruff's Avatar
GruffMaking a game and ideas Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Sorry for the confusion. When I originally replied to this thread I took note it was a VB.NET thread.

In my later posts I assumed it was a VB6 thread.

My mistake.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
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
Making a game and ideas
Making a game and ideas
Making a game and ideas Making a game and ideas
Making a game and ideas
Making a game and ideas
Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas Making a game and ideas
Making a game and ideas
Making a game and ideas
 
Making a game and ideas
Making a game and ideas
 
-->