如何向" if"添加多个值?声明

时间:2016-12-13 17:12:48

标签: python python-3.x

很抱歉,如果值不是写字。 我基本上想要这样做:

// Variables //
p1y=p2y=40;
pt=10;
ph=100;
bx=by=50;
bd=6;
xv=yv=4;
score1=score2=0;
ais=4;
// window loading all //
window.onload=function(){
    canvas=document.getElementById('gc');
    context=canvas.getContext('2d');
    setInterval(update,1000/30);
    canvas.addEventListener('mousemove', function(e){
        p1y = e.clientY-ph/2;
    })
 }
 // Reset Function //
 function reset(){
    console.log('reset called');
    bx=canvas.width/2;
    by=canvas.height/2;
    xv=-xv;
    yv=3;

 //Update Function//
 }
 function update(){
bx+=xv;
by+=yv;
if(by<0 && yv<0){
    yv=-yv;
}
if(by>canvas.height && yv>0){
    yv=-yv;
}
if(bx<0){
    if(by>p1y && by<p1y+ph){
        xv=-xv;
        dy=by-(p1y+ph/2);
        yv = dy*0.3;
    } else{
        score2++;
        reset();
    }
}
if(bx>canvas.width){
    if(by>p2y && by<p2y+ph){
        xv=-xv;
        dy=by-(p2y+ph/2);
        yv = dy*0.3;
    } else{
        score1++;
        reset();
    }
}
if(p2y+ph/2<by){
    p2y+=ais;
} else{
    p2y-=ais;
}

// reset canvas
context.clearRect(0,0,canvas.width,canvas.height);
// background
context.fillStyle='black';
context.fillRect(0,0,canvas.width,canvas.height);
// paddles
context.fillStyle='white';
context.fillRect(0,p1y,pt,ph); // p1 paddle
context.fillRect(canvas.width-pt,p2y,pt,ph); // p2 paddle
context.fillRect(bx-bd/2,by-bd/2,bd,bd); // ball
// scores
context.fillText(score1,100,100);
context.fillText(score2,canvas.width-100,100);
}

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

你需要像这样使用in

if test in ["a", "A", "A."]: