在void(keyPressed)上重复打印

时间:2019-05-20 21:18:30

标签: processing

我正在创建一个垄断的棋盘游戏,目前,我有两个在棋盘上都有代币的玩家。当令牌落在一个点上时,它将打印出位置和相应的动作。但是,在玩游戏时会发生一些事情,而且动作不会打印出来:唯一打印出来的就是掷骰子。

void keyPressed(){    

  Random rand = new Random();
  println("");


//player 1 mech
    if (key == 'l'){
        // Obtain a number between [0 - 5].
        p1diceroll = rand.nextInt(6) + 1;
        println("You rolled a " + p1diceroll + "!"); 

        pos_l = (pos_l + p1diceroll) % fields.size();


          if (pos_l == 0) {
            p1money = p1money+200; 
            println("You passed go! collect $200");
          }
          numClicks+=1; 
    }
        if (board1[pos_l].getAvail() == (true) && board1[pos_l].getType().equals("prop") && numClicks==1) {
          if (key == 'y' ){
             board1 [pos_l].setAvail(false);
             board1[pos_l].setOwner (name1); 
             p1money = p1money - board1[pos_l].getPrice(); 
             println("you have bought it! you now have " +p1money + ". player 2 press 'a' to roll the die.");
             numClicks=0;
          } else {
          println (board1[pos_l].getName() + " is available for $" + board1[pos_l].getPrice() + ". Press y to buy.");
          println("player 2 roll the die (a) if player 1 doesn't buy it");
          println("");
          }
      }
          else if (board1[pos_l].getAvail() == (false) && !board1[pos_l].getOwner().equals(name1) && numClicks==1) {
            System.out.println (board1[pos_l].getOwner() + " owns this. Pay $" + board1[pos_l].getRent()); 
            p1money = p1money - board1[pos_l].getRent(); 
            numClicks=0;
          }
        else if(board1[pos_l].getAvail() == (false) && board1[pos_l].getOwner().equals(name1) && numClicks==1){
          println("You own this! player 2 press a to roll"); 
          numClicks=0;
        }
        else if (board1[pos_l].getType().equals ("chance") && numClicks==1) {
            println(chances[j].getChance());
            p1money = p1money + chances[j].getMoney(); 
            println("You now have " + p1money + ". Player 2 press 'a' to roll the die.");
            j++; 
            numClicks=0;
          }
          else if (board1[pos_l].getType().equals ("cc") && numClicks==1) {
              println("Campus Charges! Pay $100.");
              p1money = p1money - 100; 
              println("you now have " + p1money + ". player 2 press 'a' to roll the die."); 
              numClicks=0;
            }
          else if (board1[pos_l].getType().equals ("free") && numClicks==1) {
            println ("Free space! player 2 press 'a' to roll the die."); 
            numClicks=0;
          }


    //player 2 mech
   if (key == 'a'){

        // Obtain a number between [0 - 5].
        p2diceroll = rand.nextInt(6) + 1;
        println("You rolled a " + p2diceroll + "!");  

        //move token
        pos_a = (pos_a + p2diceroll) % fields.size();

            if (pos_a == 0) {
                println("You passed go! collect $200");
                p2money = p2money + 200; 
              }
        numClicks1+=1;
    }
     if (board1[pos_a].getType().equals ("prop") && board1[pos_a].getAvail() == (true) && numClicks1==1 ) {
              if (key == 'r'){
                board1 [pos_a].setAvail(false);
                board1[pos_a].setOwner (name2); 
                p2money = p2money - board1[pos_a].getPrice(); 
                println("you have bought it! you now have " +p2money + ". player 1 press 'l' to roll the die.");
                numClicks1=0;
     }else{
           println (board1[pos_a].getName() + " is available for $" + board1[pos_a].getPrice() + ". Press r to buy.");
           println("player 1 roll the die (l) if player 2 doesn't buy it");
           println("");
              }
     }else if (board1[pos_a].getAvail() == (false) && !board1[pos_a].getOwner().equals(name2) && numClicks1==1){
            System.out.println (board1[pos_a].getOwner() + " owns this. Pay $" + board1[pos_a].getRent()); 
            p2money = p2money - board1[pos_a].getRent();
            numClicks1=0;

          }
        else if(board1[pos_a].getAvail() == (false) && board1[pos_a].getOwner().equals(name2)  && numClicks1==1){
          println("You own this! player 1 press l to roll"); 
          numClicks1=0;

        }
        else if (board1[pos_a].getType().equals ("chance")&& numClicks1==1) {
            println(chances[x].getChance());
            p2money = p2money + chances[x].getMoney();
            println("You now have " + p2money + ". Player 1 press 'l' to roll the die.");
            x = x-1; 
            numClicks1=0;
        }
        else if (board1[pos_a].getType().equals ("cc") && numClicks1==1) {
              println("Campus Charges! Pay $100.");
              p2money = p2money - 100; 
              println("you now have " + p2money + ". player 1 press 'l' to roll the die.");
              numClicks1=0;
        }
        else if (board1[pos_a].getType().equals ("free") && numClicks1==1) {
            println ("Free space! player 1 press 'l' to roll the die."); 
            numClicks1=0;
        }


    }

在发生某些情况(我不知道是什么)之后,它只会打印出“您滚动了__!”。而不是“您滚动了__!+这个位置是开放的,偶然的,等等。”

预先感谢

0 个答案:

没有答案