From 0b12e530aa7e8a82da87504ba322293531df8e70 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 19 Oct 2020 22:32:50 +0200 Subject: [PATCH] [ADDED] User the shared project + integrated it with the other classes --- Server/Models/ServerCommunication.cs | 2 +- SharedClientServer/Lobby.cs | 47 ++++++++++++++----- .../SharedClientServer.projitems | 33 ++++++------- SharedClientServer/User.cs | 30 ++++++++++++ 4 files changed, 83 insertions(+), 29 deletions(-) create mode 100644 SharedClientServer/User.cs diff --git a/Server/Models/ServerCommunication.cs b/Server/Models/ServerCommunication.cs index 0349f6b..ce6c70d 100644 --- a/Server/Models/ServerCommunication.cs +++ b/Server/Models/ServerCommunication.cs @@ -124,7 +124,7 @@ namespace Server.Models if (l == lobby) { bool succ; - l.AddUsername(username, out succ); + l.AddUser(username, out succ); if (!succ) { // TODO send lobby full message diff --git a/SharedClientServer/Lobby.cs b/SharedClientServer/Lobby.cs index 283c219..775edd8 100644 --- a/SharedClientServer/Lobby.cs +++ b/SharedClientServer/Lobby.cs @@ -1,4 +1,5 @@ -using System; +using SharedClientServer; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; @@ -13,24 +14,46 @@ namespace Client private int _id; private int _playersIn; private int _maxPlayers; - private List _usernames; + //private List _usernames; + private List _users; - public void AddUsername(string username, out bool success) - { - success = false; - if (_usernames.Count < _maxPlayers) - { - _usernames.Add(username); - success = true; - } - } + //public void AddUsername(string username, out bool success) + //{ + // success = false; + // if (_usernames.Count < _maxPlayers) + // { + // _usernames.Add(username); + // success = true; + // } + //} public Lobby(int id, int playersIn, int maxPlayers) { _id = id; _playersIn = playersIn; _maxPlayers = maxPlayers; - _usernames = new List(); + //_usernames = new List(); + _users = new List(); + } + + public void AddUser(string username, out bool succes) + { + succes = false; + if (_users.Count < _maxPlayers) + { + _users.Add(new User(username, 0)); + succes = true; + } + } + + public void AddUser(User user, out bool succes) + { + succes = false; + if (_users.Count < _maxPlayers) + { + _users.Add(user); + succes = true; + } } public int ID diff --git a/SharedClientServer/SharedClientServer.projitems b/SharedClientServer/SharedClientServer.projitems index c99a749..74ca621 100644 --- a/SharedClientServer/SharedClientServer.projitems +++ b/SharedClientServer/SharedClientServer.projitems @@ -1,17 +1,18 @@ - - - - $(MSBuildAllProjects);$(MSBuildThisFileFullPath) - true - 6d26f969-9cb1-414f-ac3e-7253d449ac5a - - - SharedClientServer - - - - - - - + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + true + 6d26f969-9cb1-414f-ac3e-7253d449ac5a + + + SharedClientServer + + + + + + + + \ No newline at end of file diff --git a/SharedClientServer/User.cs b/SharedClientServer/User.cs new file mode 100644 index 0000000..c639071 --- /dev/null +++ b/SharedClientServer/User.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SharedClientServer +{ + class User + { + private string _username; + private int _score; + + public User(string username, int score) + { + _username = username; + _score = score; + } + + public string Username + { + get { return _username; } + set { _username = value; } + } + + public int Score + { + get { return _score; } + set { _score = value; } + } + } +}