[ADDED] User the shared project + integrated it with the other classes
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<string> _usernames;
|
||||
//private List<string> _usernames;
|
||||
private List<User> _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<string>();
|
||||
//_usernames = new List<string>();
|
||||
_users = new List<User>();
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>6d26f969-9cb1-414f-ac3e-7253d449ac5a</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SharedClientServer</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ClientServerUtil.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)JSONConvert.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Lobby.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||
</ItemGroup>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>6d26f969-9cb1-414f-ac3e-7253d449ac5a</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SharedClientServer</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ClientServerUtil.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)JSONConvert.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Lobby.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)User.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
30
SharedClientServer/User.cs
Normal file
30
SharedClientServer/User.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user