Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 飞镖游戏-AngularJS中的检查问题_Javascript_Angularjs_Svg - Fatal编程技术网

Javascript 飞镖游戏-AngularJS中的检查问题

Javascript 飞镖游戏-AngularJS中的检查问题,javascript,angularjs,svg,Javascript,Angularjs,Svg,以下是我的AngularJS(JavaScript)文件的内容: //定义新的角度模块 var myApp=angular.module('myApp',[]); myApp.controller('MyAppController',函数($scope){ $scope.player=''; $scope.players=[]; $scope.totalPoints=[]; $scope.flag=1; $scope.myNumberRegex=/[0-9]/; $scope.last={};

以下是我的AngularJS(JavaScript)文件的内容:

//定义新的角度模块
var myApp=angular.module('myApp',[]);
myApp.controller('MyAppController',函数($scope){
$scope.player='';
$scope.players=[];
$scope.totalPoints=[];
$scope.flag=1;
$scope.myNumberRegex=/[0-9]/;
$scope.last={};
$scope.score={};
$scope.winner=0;
$scope.nextPlayer='';
$scope.nextRound=false;
var-actualPlayer=0;
var pointsValue,四舍五入=0;
var internalRoundCounter=1;
var shootsString='';
$scope.$watch('roundCount',函数(值){
console.log('新值',值);
});
$scope.add=函数(){
$scope.players.push({name:$scope.player,totalPoints:0,字段:[]});
$scope.player='';
};
$scope.checkForm=函数(){
var valid=true;
如果($scope.players.length==0){
警报('没有添加玩家!');
有效=错误;
}
如果($scope.roundCount<3 | |$scope.roundCount>10){
警报(“不正确的轮数!”);
有效=错误;
}
如果($scope.players.length==1){
log('Tömb hossza:',$scope.players.length);
警惕(“一个玩家是不够的!”);
有效=错误;
}
如果(有效){
$scope.flag=2;
var startingPlayer=$scope.players[actualPlayer].name;
$scope.nextPlayer=startingPlayer;
}
};
函数showResults(){
$scope.flag=3;
}
//观察变化的价值
$scope.$watch('last.id',函数(newValue){
日志('last.id changed',newValue);
pointsValue=0;
//-----------------------------------------------------------
//检查目标以计算赢得的分数
//-----------------------------------------------------------
如果(newValue==“Bull”){
点值+=50;
console.log(pointsValue);
}
else if(newValue==“外部”){
点值+=25;
console.log(pointsValue);
}
else if(['s','d','t'].indexOf(newValue[0])!=-1){
var乘数=1;
如果(新值[0]=“d”)
乘数=2;
else if(newValue[0]=“t”)
乘数=3;
var tmp=newValue.split(“”).splice(1,2).join(“”);
点值+=(tmp*乘数);
}
//-----------------------------------------------------------
//玩飞镖的时候
if(舍入<$scope.roundCount){
if(内部圆形计数器<4){
shootsString+=newValue+'';
$scope.players[actualPlayer].totalPoints+=pointsValue;
内部计数器++;
}
否则{
$scope.players[actualPlayer].fields.push({fieldId:round+1,fieldName:shootsString});
shootsString='';
内部计数器=1;
实际层++;
if(actualPlayer==$scope.players.length){
实际层=0;
round++;
}
$scope.nextPlayer=$scope.players[actualPlayer].name;
}
}
//比赛结束时
否则{
showResults();
$scope.winner=$scope.players[0]。名称;
//在阵列中找到赢家
对于(var i=1;i$scope.players[i-1].totalPoints){
$scope.winner=$scope.players[i].name;
}
}
log($scope.players);
}
});
});
myApp.directive('dartClickListener',function(){
返回{
限制:“A”,
范围:假,
链接:函数(范围、元素、属性){
console.log(angular.element(element));
angular.element(element.find('g').children().bind('click',function()){
console.log(angular.element(this.attr('id'));
scope.last.id=angular.element(this.attr('id');
作用域:$apply();
});
}
}
});

.::省道::。
飞镖
添加玩家
轮数(3-10)
开始比赛
玩家点数
{{player.name}{{player.totalPoints}}
{{nextPlayer}}是下一个
获胜者:{{winner}}@points:{{{player.totalPoints}
玩家
圆形的
总分
{{field.fieldId}
{{player.name}
{{field.fieldName}
{{player.totalPoints}

为什么不简单地计算每个玩家的3次投篮次数?一个简单的计数器,当玩家换球时会重置。但是离开$scope.$watch()结构?你必须这样做,除非你想改为ng click(然后你就可以去掉整个