以下のようにruleファクトリを変更すると、ご要望のルールを実装できます。
────────────────────────────────────────────────────────────────────
jsCopy code'use strict';
var appName = "myxQuizMain";
var app = angular.module(appName);
/*******************************************************************************
- rule - 新ルール:正解ポイント×誤答ポイントで勝敗判定
******************************************************************************/
app.factory('rule', [ 'qCommon', function(qCommon) {
var rule = {};
var win = qCommon.win;
var lose = qCommon.lose;
var setMotion = qCommon.setMotion;
var addQCount = qCommon.addQCount;
rule.judgement = judgement;
rule.calc = calc;
/*****************************************************************************
- header - ルール固有のヘッダ
****************************************************************************/
rule.head = [ {
key : "mode",
value : "position",
style : "string"
} ];
/*****************************************************************************
- items - 初期ポイント設定
- o: 正解ポイント(初期 0)
- x: 誤答ポイント(初期 10)
****************************************************************************/
rule.items = [ {
key : "o",
value : 0,
style : "number",
css : "o"
}, {
key : "x",
value : 10,
style : "number",
css : "x"
}, {
key : "priority",
order : [ {
key : "status",
order : "desc",
alter : [ "win", 1, 0 ]
}, {
key : "o",
order : "desc"
}, {
key : "x",
order : "asc"
} ]
} ];
/*****************************************************************************
- tweet - 得点ツイートテンプレート
****************************************************************************/
rule.tweet = {
o : "handleName◯→{o}P ×xP",x:"{handleName}× → oP×{x}P"
};
/*****************************************************************************
- actions - プレイヤーごとの 動作
****************************************************************************/
rule.actions = [
// 正解時
{
name : "",
css : "action_o",
button_css : "btn btn-primary btn-lg",
: "k1",
enable0 : function(player, players, header) {
return (player.status === "normal" && !header.playoff);
},
action0 : function(player, players, header, property) {
setMotion(player, "o");
player.o += 1; // 正解ポイント +1
addQCount(players, header, property);
},
tweet : "o"
},
// 誤答時
{
name : "×",
css : "action_x",
button_css : "btn btn-danger btn-lg",
: "k2",
enable0 : function(player, players, header) {
return (player.status === "normal" && !header.playoff);
},
action0 : function(player, players, header, property) {
setMotion(player, "x");
player.x -= 1; // 誤答ポイント -1
addQCount(players, header, property);
},
tweet : "x"
}
];
/*****************************************************************************
- global_actions - 全体操作(スルー等)
****************************************************************************/
rule.global_actions = [
{
name : "thru",
button_css : "btn btn-default",
group : "rule",
keyboard : "Space",
enable0 : function(players, header) {
return true;
},
action0 : function(players, header, property) {
addQCount(players, header, property);
},
tweet : "thru"
}
];
/*****************************************************************************
- judgement - 勝敗判定
- ○×の積 >= 100 で勝抜け
- × <= 4 で失格
****************************************************************************/
function judgement(players, header, property) {
// rank (
players.filter(function(p) { return p.rank === 0; }),
function(player) {
// 勝利条件:正解ポイント × 誤答ポイント >= 100
if (player.o * player.x >= 100) {
win(player, players, header, property);
// 必要ならスコアを制限値に合わせる
// player.o = Math.ceil(100 / player.x);
}
// 失格条件:誤答ポイント <= 4
if (player.x <= 4) {
lose(player, players, header, property);
player.x = 4;
}
}
);
}
/*****************************************************************************
- calc - キー入力などの初期化
****************************************************************************/
function calc(players, header, items, property) {
angular.forEach(players, function(player, index) {
player.keyIndex = index;
});
}
return rule;
} ]);
変更点のポイント
rule.itemsでoを 0、xを 10 で初期化。
正解アクションでplayer.o += 1、誤答アクションでplayer.x -= 1。
judgement関数でplayer.o * player.x >= 100→win()player.x <= 4→lose()
player.o * player.x >= ()
player.x <= 4→lose()
rule.itemsでoを 0、xを 10 で初期化。
正解アクションでplayer.o += 1、誤答アクションでplayer.x -= 1。
judgement関数で
player.o * player.x >= ()
player.x <= 4→lose()
player.o * player.x >= ()
player.x <= 4→lose()
これで、
初期:正解ポイント0、誤答ポイント10
○で正解ポイント+1、×で誤答ポイント−1
両者の積が100以上で勝抜け
誤答ポイントが4以下で失格というルールが動作します。
初期:正解ポイント0、誤答ポイント10
○で正解ポイント+1、×で誤答ポイント−1
両者の積が100以上で勝抜け
誤答ポイントが4以下で失格というルールが動作します。