View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007

Milestone 6 Domain Implementation

M6 Requirements

Goals:
-We want to begin coding our game! There are a quite a few requirements that need to be completed, so refer to the M6 Requirements.
How We Accomplished Those Goals:
-For a visual representation of what our initial gui screens looked like, go here: Milestone 8 UI Evaluation and scroll down a bit. We made them with the built in gui maker.
-An example of one of the many blocks of code required for this Milestone would be the buyItem method in our Wagon class. Take note of the intuitive usage of "detect" when trying to add, say, more quantity to an item that already exists in the Collection. Also note the aspectAdaptor "#itemListBox" which updates the view for the user. Otherwise, the gui would never change even though the model is changing.

buyItem: anItem quan: anAmount weight: aWeight price: aPrice
"UPDATED: buys an item checks to see if Wagon Leader has enough funds to buy the item if they do then the items get added to inventory if they don't then a warning box pops up and nothing is purchased."

| x price weight theTotalWeight|
"Check to see if you can afford the item first
and checks to see if you can have the weight in the wagon without going over it's limit."
price := anAmount * aPrice.
weight := aWeight * anAmount.
theTotalWeight := (self totalWeight + weight).
((price < (leader money)) and: [theTotalWeight < (self maxWeight)])
ifTrue:["find the item in teh collection, if not there add it into the Collection"
    x := items detect: [:e | e name = anItem ]
    ifNone: [self addItem: (Item named: anItem weight: aWeight quanity: anAmount price: aPrice). items last. leader money: leader money - price. ^ true.].
    leader money: leader money - price.
    x buy: anAmount.
    self changed: #itemListBox.
    ^true]

-Another piece of code that we had to write for M6 was the RandomEvent code. Basically, we have a generateKindOfEvent method in our RandomEvent that will return either a WeatherEvent, NPCEvent, or nothing at all based upon random numbers:

generateKindOfEvent
| t1 t2 t3 |
t2 := OrderedCollection new.
t3 := (t3 := Time now) asSeconds.
(t1 := (t1 := (t1 := (t1 := (t1 := Random new seed: t3) nextValue) * 765) // 1) \\ 100) < 73
ifTrue:
    [t2 add: 0.
    t2 add: nil.
    ^t2].
t1 >= 73 & (t1 <= 83)
ifTrue:
    [t2 add: 1.
    t2 add: WeatherEvent.
    ^t2].
t1 >= 84 & (t1 <= 99)
ifTrue:
    [t2 add: 1.
    t2 add: NPCEvent.
    ^t2].
^self

Advice:
-This Milestone is when dividing up the work becomes even more crucial. There is a lot of coding to be done, so be sure to help out or your whole team may end up getting way behind.
-Create methods that make since based upon the design laid out in M5. Don't try to take cheap shortcuts that may ultimately cost you depending on what it is. Menfinity-- We. Are. Forever. Men.



Link to this Page