我正在研究一个具有岩石剪刀系统的游戏,只有更复杂的是使用"值",例如3摇滚2摇滚,其中一个玩家可以选择该游戏他想一次使用的岩石数量。该游戏可以/必须处理2个以上的玩家,但也有2个玩家。我只能使用此代码来使用值:
array.push({ "player": player, "score": parseInt(cardInformation.value), "Seat": i, element: cardInformation.element});
array.sort(function (a, b) {
return b.score - a.score;
});
var rank = 1;
var lastWinner = -1;
for (var i = 0; i < array.length; i++) {
if (i > 0 && array[i].score < array[i - 1].score) {
rank++;
}
array[i].rank = rank;
array[i].winStatus = loss;
if(rank == 1) {
if(lastWinner != -1) {
array[lastWinner].winStatus = tie;
array[i].winStatus = tie;
} else
array[i].winStatus = win;
lastWinner = i;
}
}
我已经看着像岩石剪刀这样的系统,但是我只能找到2个玩家,我不确定如何使其更加更大。如果您有时间,请帮助我。
希望这会有所帮助:
const TURN_INTERVAL = 10//seconds
const GAME_STATE = {
status:1, // 1:player action is allowed / 0:player action is frozen
turnData:{ // temp storage for playerIDs grouped by value chosen
1:[], //paper
2:[], //scissors
3:[] //rock
},
versus:{ //what kills what
1:3,
2:1,
3:2
}
}
function GlobalTurn(){
console.log('[Round]','started')
GAME_STATE.status = 0; // players must wait for turn end response
for(var i=1; i<4;i++){ // notify each group of how many they killed
var thisGroupKills = GAME_STATE.versus[i]; //which is the weak group against this one
var totalKilled = GAME_STATE.turnData[thisGroupKills].length //how much this group has killed
console.log('group',i,'killed a total of',totalKilled) //send to clients instead
/* Here you can iterate over each playerID if you need to :
for(var j=0; j<GAME_STATE.turnData[i].length){
console.log('player',GAME_STATE.turnData[i],'killed a total of',totalKilled)
}
*/
}
EndTurn()
}
function EndTurn(){
console.log('Next round will start in',TURN_INTERVAL,'seconds')
GAME_STATE.turnData = {1:[],2:[],3:[]} //reset for next round
GAME_STATE.status = 1; // players can send actions (their pick)
setTimeout(GlobalTurn,TURN_INTERVAL*1000); //prepare next round calculator
}