package main import ( "fmt" ) type TeamBase struct { m_TeamId uint64 m_Rid uint32 m_RoomRule uint32 m_Players []uint64 } type TeamInt interface { Init() CreateTeam(accountId uint64, rid uint32) bool AddTeamPlayer(accountId uint64) bool DelTeamPlayer(accountId uint64) bool GetTeamBase() *TeamBase } type TeamNormal struct { TeamBase } func (this *TeamNormal) Init() { this.TeamBase.m_Players = make([]uint64, 0) this.TeamBase.m_TeamId = 0 this.TeamBase.m_Rid = 0 this.TeamBase.m_RoomRule = 0 } func (this *TeamNormal) CreateTeam(accountId uint64, rid uint32) bool { this.TeamBase.m_TeamId = accountId this.TeamBase.m_Rid = rid this.TeamBase.m_Players = append(this.TeamBase.m_Players, accountId) return true } func (this *TeamNormal) AddTeamPlayer(accountId uint64) bool { this.TeamBase.m_Players = append(this.TeamBase.m_Players, accountId) return true } func (this *TeamNormal) DelTeamPlayer(accountId uint64) bool { return true } func (this *TeamNormal) GetTeamBase() *TeamBase { return &this.TeamBase } type TeamManager struct { m_teamList map[uint64]TeamInt } var teamMgr *TeamManager func TeamManager_GetMe() *TeamManager { if teamMgr == nil { teamMgr = &TeamManager{ m_teamList: make(map[uint64]TeamInt), } } return teamMgr } func (this *TeamManager) CreateTeam(teamId uint64, rid uint32) bool { this.DelTeam(teamId) tn := &TeamNormal{} tn.Init() tn.CreateTeam(teamId, rid) this.m_teamList[teamId] = interface{}(tn).(TeamInt) return true } func (this *TeamManager) DelTeam(teamId uint64) { if this.GetTeam(teamId) != nil { delete(this.m_teamList, teamId) } } func (this *TeamManager) GetTeam(teamId uint64) TeamInt { k, err := this.m_teamList[teamId] if !err { return nil } return k }