Church.Net.API/WebAPI/GameRoomLogic.cs
2022-09-08 08:04:32 -07:00

36 lines
889 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebAPI.Models.IceBreak;
namespace WebAPI
{
public class GameRoomLogic
{
public List<GameRoom> GameRooms { get; set; }
public bool UserJoinGameRoom(string id,string userName,string gameRoomId)
{
if (GameRooms.Any(g => g.Id == gameRoomId))
{
//Make sure user not exist in other room
UserLeave(id);
}
return false;
}
public void UserLeave(string id)
{
foreach (var room in GameRooms)
{
if (room.Players.Any(p => p.Id == id))
{
room.Players.Remove(room.Players.FirstOrDefault(p => p.Id == id));
break;
}
}
}
}
}