 |
 |

07-19-2004, 11:31 PM
|
 |
Junior Contributor
|
|
Join Date: Oct 2003
Location: @WinMain
Posts: 211
|
|
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?
|
|

07-19-2004, 11:44 PM
|
|
Freshman
|
|
Join Date: Dec 2003
Posts: 33
|
|
|
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
|
|

07-20-2004, 12:18 AM
|
 |
Junior Contributor
|
|
Join Date: Oct 2003
Location: @WinMain
Posts: 211
|
|
|
I never used a collection. Can you give me a quick example?
Thanks.
|
|

07-20-2004, 01:00 AM
|
 |
Junior Contributor
|
|
Join Date: Jun 2003
Posts: 287
|
|
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
|
|

07-20-2004, 01:12 AM
|
|
Freshman
|
|
Join Date: Dec 2003
Posts: 33
|
|
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.
|
|

07-20-2004, 02:41 AM
|
|
Centurion
|
|
Join Date: Jun 2004
Location: Central Coast, Australia
Posts: 152
|
|
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 
|
|

07-21-2004, 11:14 AM
|
|
Freshman
|
|
Join Date: Jan 2004
Location: Sydney, Australia
Posts: 40
|
|
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.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|