public SessionPlayer(int id, Session session, CreatePlayerData data) { this.id = id; this.session = session; this.data = data; control = new SessionPlayerControl(this); score = 0; turnsPlayed = 0; victories = 0; List<Role> roles = Utils.GetRoles(); roleVictories = new Dictionary<Role, int>(roles.Count); foreach(Role role in roles) roleVictories[role] = 0; List<CharacterType> characters = Utils.GetCharacterTypes(session); characterVictories = new Dictionary<CharacterType, int>(characters.Count); foreach(CharacterType character in characters) characterVictories[character] = 0; }
public SessionPlayer(Session session, BinaryReader reader) { this.session = session; id = reader.ReadInt32(); try { BinaryFormatter bf = new BinaryFormatter(); data = (CreatePlayerData)bf.Deserialize(reader.BaseStream); } catch(InvalidCastException) { throw new FormatException(); } catch(SerializationException) { throw new FormatException(); } control = new SessionPlayerControl(this); score = reader.ReadInt32(); if(score < 0) throw new FormatException(); turnsPlayed = reader.ReadInt32(); if(turnsPlayed < 0) throw new FormatException(); victories = reader.ReadInt32(); if(victories < 0) throw new FormatException(); int roleVicCount = reader.ReadInt32(); roleVictories = new Dictionary<Role, int>(roleVicCount); for(int i = 0; i < roleVicCount; i++) { Role role = (Role)reader.ReadInt32(); int vic = reader.ReadInt32(); if(vic < 0) throw new FormatException(); roleVictories.Add(role, vic); } int characterVicCount = reader.ReadInt32(); characterVictories = new Dictionary<CharacterType, int>(characterVicCount); for(int i = 0; i < characterVicCount; i++) { CharacterType character = (CharacterType)reader.ReadInt32(); int vic = reader.ReadInt32(); if(vic < 0) throw new FormatException(); characterVictories.Add(character, vic); } }
public void ResetControl() { control.Disconnect(); control = new SessionPlayerControl(this); Game game = session.Game; if(game != null) { Player p = game.GetPlayer(id); p.ResetControl(); } }