Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Game Programming > Turnbased Game. Need help with dates.


Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2004, 11:31 PM
Ranma_at's Avatar
Ranma_at Ranma_at is offline
Junior Contributor
 
Join Date: Oct 2003
Location: @WinMain
Posts: 211
Arrow Turnbased Game. Need help with dates.


Hello,

I am into a simple turnbased game. With each new turn we get into a new month.
For example we start with: January 2004. Next turn would be February 2004 and so on.

My problem is how to tell the program which month follows the next one and how to tell after
december 2004 it gets to 2005. It seems quite simple but i dont know where to start.


Here is what i was thinking:
I need to declare all months as a public string.
The years should be an integer, after 12 turns it goes +1. So i need another Integer for each turn?
Reply With Quote
  #2  
Old 07-19-2004, 11:44 PM
JJason JJason is offline
Freshman
 
Join Date: Dec 2003
Posts: 33
Default

Do you want the month to progress when the turn occurs, or for the turn to progress when the month changes?

If you just want to keep track of the month and year, you could have a Collection of the months, and this as the turn progress up to 12, you add +1 to a month counter variable. Then once you get to 12, reset the variable to 1 and +1 to the year counter. So if you ever need to know what month it is, just use the month counter to reference the corresponding month in the collection
Reply With Quote
  #3  
Old 07-20-2004, 12:18 AM
Ranma_at's Avatar
Ranma_at Ranma_at is offline
Junior Contributor
 
Join Date: Oct 2003
Location: @WinMain
Posts: 211
Default

I never used a collection. Can you give me a quick example?
Thanks.
Reply With Quote
  #4  
Old 07-20-2004, 01:00 AM
martrinex's Avatar
martrinex martrinex is offline
Junior Contributor
 
Join Date: Jun 2003
Posts: 287
Default

if you want to keep adding a month to a date vb has a nice function for it:
Code:
Date = "12/1/1" Date = DateAdd("m", 1, Date) '<< m for month
this will do the years for you aswell
the only trouble is its all numeric you may want todo split the numbers up and turn it into text
Reply With Quote
  #5  
Old 07-20-2004, 01:12 AM
JJason JJason is offline
Freshman
 
Join Date: Dec 2003
Posts: 33
Default

A collection in its simpilist form (as far as I know) is like a special array that can store objects. In your instance, you may want something like:
Code:
Dim colMonths as New Collection
Then you would want to add all your months to it:
Code:
' You use the Add method to add items to the collection colMonths.Add "January" colMonths.Add "February" colMonths.Add "March" ' etc etc...

Now, say its the 7 turn, and you want to see what month that translates to:

Code:
' You use the Item method to obtain the value at a certain position in the Collection ' In this case, intTurnCount = 7, which means its July Debug.Print colMonths.Item (intTurnCount)

Asumming you added all the months in right, the above would return "July". The only other two methods are 'Remove' (Self explanitory) and 'Count' which says how many items are in the collection.
Reply With Quote
  #6  
Old 07-20-2004, 02:41 AM
Priddo Priddo is offline
Centurion
 
Join Date: Jun 2004
Location: Central Coast, Australia
Posts: 152
Default

Code:
Datenow = "1/1/2004" Datenow = DateAdd("m", 1, Date) thismonth.Caption = Format(datenow, "mmmm")

have 3 m's for it to be Jan Feb etc four means January etc.

that will add the date by a month then format it to just show the month into the caption
Reply With Quote
  #7  
Old 07-21-2004, 11:14 AM
Sketchy Sketchy is offline
Freshman
 
Join Date: Jan 2004
Location: Sydney, Australia
Posts: 40
Default

If I understand your problem correctly I believe the following code may help -

Code:
'Declare an array to hold the names of the months and then fill it up Dim arrMonths(11) As String arrMonths(0) = "January" 'Fill in other months here arrMonths(11) = "December" 'Declare a long(or integer) to hold the amount of turns it has been since the game has started Dim lTurn As Long 'Then create a simple function to return the date of the current turn like the following one Function GetDate() As String 'You can replace the '2000' with whatever year the game starts at GetDate = arrMonths(lTurn Mod 12) & " " & (2000 + (lTurn \ 12)) End Function

That should return the date of any given turn. Hope this helps you out.
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
 
 
-->