[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)
|
if (l == lobby)
|
||||||
{
|
{
|
||||||
bool succ;
|
bool succ;
|
||||||
l.AddUsername(username, out succ);
|
l.AddUser(username, out succ);
|
||||||
if (!succ)
|
if (!succ)
|
||||||
{
|
{
|
||||||
// TODO send lobby full message
|
// TODO send lobby full message
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -13,24 +14,46 @@ namespace Client
|
|||||||
private int _id;
|
private int _id;
|
||||||
private int _playersIn;
|
private int _playersIn;
|
||||||
private int _maxPlayers;
|
private int _maxPlayers;
|
||||||
private List<string> _usernames;
|
//private List<string> _usernames;
|
||||||
|
private List<User> _users;
|
||||||
|
|
||||||
public void AddUsername(string username, out bool success)
|
//public void AddUsername(string username, out bool success)
|
||||||
{
|
//{
|
||||||
success = false;
|
// success = false;
|
||||||
if (_usernames.Count < _maxPlayers)
|
// if (_usernames.Count < _maxPlayers)
|
||||||
{
|
// {
|
||||||
_usernames.Add(username);
|
// _usernames.Add(username);
|
||||||
success = true;
|
// success = true;
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
public Lobby(int id, int playersIn, int maxPlayers)
|
public Lobby(int id, int playersIn, int maxPlayers)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_playersIn = playersIn;
|
_playersIn = playersIn;
|
||||||
_maxPlayers = maxPlayers;
|
_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
|
public int ID
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||||
<HasSharedItems>true</HasSharedItems>
|
<HasSharedItems>true</HasSharedItems>
|
||||||
<SharedGUID>6d26f969-9cb1-414f-ac3e-7253d449ac5a</SharedGUID>
|
<SharedGUID>6d26f969-9cb1-414f-ac3e-7253d449ac5a</SharedGUID>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Configuration">
|
<PropertyGroup Label="Configuration">
|
||||||
<Import_RootNamespace>SharedClientServer</Import_RootNamespace>
|
<Import_RootNamespace>SharedClientServer</Import_RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ClientServerUtil.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ClientServerUtil.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)JSONConvert.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)JSONConvert.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Lobby.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Lobby.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)ObservableObject.cs" />
|
||||||
</ItemGroup>
|
<Compile Include="$(MSBuildThisFileDirectory)User.cs" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</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