我正在尝试为我的游戏添加一个分数,每当多维数据集通过差距时,它会添加一个得分。我尝试了一些不同的方法,但没有一个适合我。这是我的脚本,我在那里有三个html,css和javascript,抱歉,如果它有点乱。谢谢。 PS。我必须在这个问题上加入更多信息才能发布
None
>>> response.xpath('//div//a[contains(@href, "product")]/@href').extract_first()
[u'/product_1', u'/product_1']
>>> response.xpath('//div//a[contains(@href, "product")]/@href').extract_first()
u'/product_1'
答案 0 :(得分:0)
if (pieceY == height) {
if (pieceX < length || pieceX > length + 20) {
document.getElementById("lose").style.visibility = "visible";
}
//Here add
myScore = myScore +1;
document.getElementById("score").innerHTML = myScore;
}
停止动画(当你想要停止时将gameIsOver设置为true):
var stop,gameIsOver;
function init() {
ctx = canvas.getContext('2d');
stop = setInterval(draw,10);
document.getElementById('lose').style.visibility = "hidden";
}
function draw(){
if(gameIsOver){
clearInterval(stop);
}
}
答案 1 :(得分:0)
停止绘制功能,记录间隔id:
var interval_id;
function init() {
ctx = canvas.getContext('2d');
document.getElementById('lose').style.visibility = "hidden";
interval_id = setInterval(draw,10); // to record the interval id
}
并在丢失时通过该ID清除间隔:
if (pieceY == height) {
if (pieceX < length || pieceX > length + 20) {
// to stop the draw interval
clearInterval(interval_id);
document.getElementById("lose").style.visibility = "visible";
}
myScore = myScore + 1;
// to update the score to the view
document.getElementById("score").innerHTML = myScore;
}
重启游戏:
function restart() {
// reset all variables that changed to it's initial value
pieceX = 200;
pieceY = 400;
height = 0;
myScore = 0;
// reset view
document.getElementById("score").innerHTML = myScore;
document.getElementById('lose').style.visibility = "hidden";
// start the interval loop(it will return a different id)
interval_id = setInterval(draw, 10); // to record the interval id
}