GameLobby

From WowAce Wiki
Jump to: navigation, search
Summary
GameLobby
A Lobby for moduled Games.
TOC 2.1 (20100)
Category Miscellaneous Addons
Author Warloxx
Details
Embeds Ace2, SharedMediaLib, DewdropLib, FuBarPlugin-2.0, MD5Lib, Waterfall-1.0
OptionalDeps FuBar
Links
Betas Ace SVN Zip
Changelog FishEye

A Lobby for moduled Games.

Example

this is a very simple "game". You can click a button one after another whith 2 up to 4 players

this example is drycoded

 local MyGameClass = GameLobby:NewGame("MyGame", RoundBasedGame)
 
 MyGameClass.minSlots = 2
 MyGameClass.maxSlots = 4
 MyGameClass.icon = ""
 
 MyGameClass.Memoizations = {}
 
 function MyGameClass.prototype:StartGame()
    self:CreateGUI()
    self:StartRoundBasedGame()
 end
 
 function MyGameClass.prototype:CreateGUI()
    --create a gui
    self.GUI={}
    local f = self.newFrame("Frame", UIParent)
    f:SetPoint("CENTER")
    f:SetWidth(100)
    f:SetHeight(100)
    --f:SetBackdrop(   )
    self.GUI.f = f
    
    local button = self.newFrame("Button", f, nil, "UIPanelButtonTemplate2")
    button:SetScript("OnClick", function() self:NextPlayer() this:Disable() end)
    button:SetText("Click me")
    button:SetPoint("CENTER")
    button:Disable()
    self.GUI.button = button
    
    button = GameLobby.newFrame("Button", f, nil, "UIPanelCloseButton")
    button:SetPoint("TOPRIGHT")
    button:SetScript("OnClick",
          function()
               this:GetParent():Hide()
               self:PreClose()
          end
    )
    self.GUI.CloseBtn = button
 end
 
 function MyGameClass.prototype:DisposeGUI()
    self.GUI.closeBtn = self.delFrame(self.GUI.closeBtn)
    self.GUI.button = self.delFrame(self.GUI.button)
    self.GUI.f = self.delFrame(self.GUI.f)
 end
 function MyGameClass.prototype:PreClose()
    self:DisposeGUI()
    
    -- call this at least, this will delete this obj and will disconnect the gameserver if nessesary.
    self:Close()
 end
 function MyGameClass.prototype:OnMyTurn("sender", [...])
    -- do something with the data
    self.GUI.button:Enable()
 end
 
 function MyGameClass.prototype:OnSomebodysTurn(sender, player, ...)
    -- do something with the data
 end


Core API Documentation

:NewGame("name", gameclass, ...)

Returns a new gameclass based on given name and class.

Args

"name" 
string - name of the game
gameclass 
table - Superclass to inherit from.
... 
[optional] tuple - Mixins and Interfaces to inherit from

Returns

table - the new gameclass

Remarks

The superclass to inherit from should be GameLobby/BasicServer or GameLobby/RoundBasedGame.

Example

local TicTacToe = GameLobby:NewGame("TicTacToe", RoundBasedGame)