Begin work on the backend info needed for the game itself
This commit is contained in:
parent
a709630c62
commit
03db868b7c
2 changed files with 126 additions and 2 deletions
|
|
@ -1 +1,76 @@
|
|||
export class Board {}
|
||||
const fascist_abilities: {[index: string]: any} = {
|
||||
"5": {
|
||||
"3": ["ViewPolicies"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
},
|
||||
"6": {
|
||||
"3": ["ViewPolicies"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
},
|
||||
"7": {
|
||||
"2": ["InvestigateParty"],
|
||||
"3": ["SpecialElection"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
},
|
||||
"8": {
|
||||
"2": ["InvestigateParty"],
|
||||
"3": ["SpecialElection"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
},
|
||||
"9": {
|
||||
"1": ["InvestigateParty"],
|
||||
"2": ["InvestigateParty"],
|
||||
"3": ["SpecialElection"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
},
|
||||
"10": {
|
||||
"1": ["InvestigateParty"],
|
||||
"2": ["InvestigateParty"],
|
||||
"3": ["SpecialElection"],
|
||||
"4": ["Execution"],
|
||||
"5": ["Execution", "VetoUnlock"]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export class Board {
|
||||
private _fascist: number;
|
||||
private _liberal: number;
|
||||
private _board: any;
|
||||
|
||||
constructor(player_count: number) {
|
||||
this._fascist = 0;
|
||||
this._liberal = 0;
|
||||
this._board = fascist_abilities[player_count.toString()];
|
||||
};
|
||||
|
||||
get fascist(): number {
|
||||
return this._fascist;
|
||||
};
|
||||
|
||||
get liberal(): number {
|
||||
return this._liberal;
|
||||
};
|
||||
|
||||
public add_policy(party: policy): void {
|
||||
if (party == `fascist`) {
|
||||
this._fascist++;
|
||||
} else {
|
||||
this._liberal++;
|
||||
};
|
||||
};
|
||||
|
||||
public has_winner(): policy|"no" {
|
||||
if (this._liberal == 5) {
|
||||
return `liberal`;
|
||||
} else if (this._fascist == 6) {
|
||||
return `fascist`;
|
||||
};
|
||||
return `no`;
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +1,16 @@
|
|||
/* How many cards are in the deck */
|
||||
const DECK = {
|
||||
total: 17,
|
||||
fascist: 11,
|
||||
liberal: 6,
|
||||
}
|
||||
|
||||
/* How many Fascists are in the game (excluding hitler) */
|
||||
const FASCIST_COUNTS: {[index: number]: number} = {
|
||||
5:1, 6:1, 7:2, 8:2, 9:3, 10:3
|
||||
};
|
||||
|
||||
|
||||
export class Game {
|
||||
readonly code: string;
|
||||
public status: game_states;
|
||||
|
|
@ -5,6 +18,8 @@ export class Game {
|
|||
private banned_players: string[];
|
||||
private _players: players;
|
||||
|
||||
private deck: policy[] = [];
|
||||
|
||||
public constructor(code: string) {
|
||||
this.code = code;
|
||||
this._players = {};
|
||||
|
|
@ -56,11 +71,45 @@ export class Game {
|
|||
* @return The error that prevents the game from starting.
|
||||
*/
|
||||
if (this.player_len <= 4) {
|
||||
return `Cannot start game with less than 4 players.`;
|
||||
return `Cannot start game with less than 5 players.`;
|
||||
};
|
||||
return ``;
|
||||
};
|
||||
|
||||
public start(): void {
|
||||
/**
|
||||
* Starts the game, this assigns roles and populates the presidential
|
||||
* queue. (randomly picks the first loop, then repeats that same
|
||||
* iteration until the game ends)
|
||||
*/
|
||||
let players = Object.keys(this._players);
|
||||
|
||||
let hitler = Math.floor(Math.random() * players.length);
|
||||
this._players[players[hitler]].role = "hitler";
|
||||
players.splice(hitler, 1);
|
||||
|
||||
// Assign fascists
|
||||
for (var i = 0; i <= FASCIST_COUNTS[this.player_len]; i++) {
|
||||
let player_index = Math.floor(Math.random() * players.length);
|
||||
this._players[players[player_index]].role = `fascist`;
|
||||
players.splice(player_index, 1);
|
||||
};
|
||||
|
||||
// Everyone else is a liberal
|
||||
for (var player of players) {
|
||||
this._players[player].role = `liberal`;
|
||||
};
|
||||
|
||||
// Create the deck for the game
|
||||
for (var i = 0; i <= DECK.total; i++) {
|
||||
if (i <= DECK.fascist) {
|
||||
this.deck[i] = `fascist`;
|
||||
} else {
|
||||
this.deck[i] = `liberal`;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
public toString(): string {
|
||||
let player_count = Object.keys(this._players).length;
|
||||
return `Game(code=${this.code},players=${player_count})`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue