forked from zxl/Frame
1
0
Fork 0
Frame/Assets/Scripts/Room/Room.cs

76 lines
1.7 KiB
C#
Raw Normal View History

2024-04-06 11:59:18 +08:00
using System.Collections.Generic;
using Game.Player;
using UnityEngine;
namespace Game.Room;
public interface IRoom
{
RoomData roomData { get; }
RoomInfo roomInfo { get; }
List<IPlayer> players { get; }
bool Join(IPlayer player);
bool Quit(IPlayer player);
float ClearAll();
void Dispose();
bool InvestmentJinbei(IPlayer player, float jinbei);
}
class Room : IRoom
{
private GameObject self;
private RoomInfo _roomInfo;
private RoomData _roomData;
public RoomType roomType => this._roomData.roomType;
public RoomData roomData => this._roomData;
public RoomInfo roomInfo => this._roomInfo;
public List<IPlayer> players => this._roomData.players;
public Room(RoomType roomType, GameObject roomGo)
{
this._roomData = new RoomData(roomType);
// view
2024-04-06 11:59:18 +08:00
this._roomInfo = roomGo.GetComponent<RoomInfo>();
this.self = roomGo;
}
public bool Join(IPlayer player)
{
if (this.players.Contains(player))
return false;
this.players.Add(player);
return true;
}
public bool Quit(IPlayer player)
{
if (!this.players.Contains(player))
return false;
this.players.Remove(player);
return true;
}
public float ClearAll()
{
this.players.Clear();
return this._roomData.jinbei;
}
public void Dispose()
{
throw new System.NotImplementedException();
}
public bool InvestmentJinbei(IPlayer player, float jinbei)
{
if (!this.players.Contains(player))
return false;
this._roomData.jinbei += jinbei;
return true;
}
}