blocked on some logic...WIP commit
This commit is contained in:
parent
6cca64e62e
commit
e3b0f99f04
6 changed files with 191 additions and 168 deletions
|
@ -1,4 +1,5 @@
|
|||
import {MessageUserPosition} from "./Websocket/MessageUserPosition";
|
||||
import { World } from "./World";
|
||||
export class Group {
|
||||
static readonly MAX_PER_GROUP = 4;
|
||||
|
||||
|
@ -15,4 +16,37 @@ export class Group {
|
|||
isFull(): boolean {
|
||||
return this.users.length >= Group.MAX_PER_GROUP;
|
||||
}
|
||||
|
||||
isPartOfGroup(user: MessageUserPosition): boolean
|
||||
{
|
||||
return this.users.indexOf(user) !== -1;
|
||||
}
|
||||
|
||||
isStillIn(user: MessageUserPosition): boolean
|
||||
{
|
||||
if(!this.isPartOfGroup(user)) {
|
||||
return false;
|
||||
}
|
||||
let stillIn = true;
|
||||
for(let i = 0; i <= this.users.length; i++) {
|
||||
let userInGroup = this.users[i];
|
||||
let distance = World.computeDistance(user.position, userInGroup.position);
|
||||
if(distance > World.MIN_DISTANCE) {
|
||||
stillIn = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stillIn;
|
||||
}
|
||||
|
||||
removeFromGroup(users: MessageUserPosition[]): void
|
||||
{
|
||||
for(let i = 0; i < users.length; i++) {
|
||||
let user = users[i];
|
||||
const index = this.users.indexOf(user, 0);
|
||||
if (index > -1) {
|
||||
this.users.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue