dimanche 2 octobre 2016

'else' without 'if; error Java Chess Application

I'm trying to add movement code for the queen in a chess game but I'm running into and else without if error when I add the diagonal movement code. I have put stars around the line where I get the error. Am I structuring this wrong? Any help would be greatly appreciated.

if(pieceName.contains("Queen")){ Boolean intheway1 = false; if(((landingX < 0) || (landingX > 7))||((landingY < 0)||(landingY > 7))){ validMove = false; } else {

                      if(((Math.abs(startX-landingX) !=0)&&(Math.abs(startY-landingY) == 0))|| ((Math.abs(startX-landingX)==0)&&(Math.abs(landingY-startY)!=0)))
                      {
                        if(Math.abs(startX-landingX)!=0){
                              if(startX-landingX > 0){
                            for(int i=0;i < xMovement;i++){
                              if(piecePresent(initialX-(i*75), e.getY())){
                                intheway1 = true;
                                break;
                              }
                              else{
                                intheway1 = false;
                              }
                          }
                        }
                        else{
                          for(int i=0;i < xMovement;i++){
                            if(piecePresent(initialX+(i*75), e.getY())){
                              intheway1 = true;
                              break;
                            }
                            else{
                              intheway1 = false;
                            }
                          }
                        }
                      }
                      else{
                        if(startY-landingY > 0){
                          for(int i=0;i < yMovement;i++){
                            if(piecePresent(e.getX(),initialY-(i*75))){
                              intheway1 = true;
                              break;
                            }
                            else{
                              intheway1 = false;
                            }
                          }
                        }
                        else{
                          for(int i=0;i < yMovement;i++){
                            if(piecePresent(e.getX(),initialY+(i*75))){
                              intheway1 = true;
                              break;
                            }
                            else{
                              intheway1 = false;
                            }
                          }
                        }
                      }
                      if(intheway1){
                        validMove = false;
                      }
                      else{
                        if(piecePresent(e.getX(), (e.getY()))){
                          if(pieceName.contains("White")){
                            if(checkWhiteOponent(e.getX(), e.getY())){
                              validMove = true;
                            }
                            else{
                              validMove = false;
                            }
                          }
                          else{
                            if(checkBlackOponent(e.getX(), e.getY())){
                              validMove = true;
                            }
                            else{
                              validMove = false;
                            }
                          }
                        }
                        else{
                          validMove = true;
                        }
                      }
                    }
                    else{
                      validMove = false;
                    }

                 ***************else{*******************
                      validMove = true;
                      if(Math.abs(startX-landingX)==Math.abs(startY-landingY)){
                        if((startX-landingX < 0)&&(startY-landingY < 0)){
                          for(int i=0; i < distance;i++){
                            if(piecePresent((initialX+(i*75)), (initialY+(i*75)))){
                              intheway1 = true;
                            }
                          }
                        }
                      else if((startX-landingX < 0)&&(startY-landingY > 0)){
                        for(int i=0; i < distance;i++){
                          if(piecePresent((initialX+(i*75)), (initialY-(i*75)))){
                            intheway1 = true;
                          }
                        }
                      }
                      else if((startX-landingX > 0)&&(startY-landingY > 0)){
                        for(int i=0; i < distance;i++){
                          if(piecePresent((initialX-(i*75)), (initialY-(i*75)))){
                            intheway1 = true;
                          }
                        }
                      }

                      else if((startX-landingX > 0)&&(startY-landingY < 0)){
                        for(int i=0; i < distance;i++){
                          if(piecePresent((initialX-(i*75)), (initialY+(i*75)))){
                            intheway1 = true;
                          }
                        }
                      }

                      if(intheway1){
                        validMove = false;
                    }
                  else{
                    if(piecePresent(e.getX(), (e.getY()))){
                      if(pieceName.contains("White")){
                        if(checkWhiteOponent(e.getX(), e.getY())){
                          validMove = true;
                        }
                        else{
                          validMove = false;
                        }
                        }

                      else{
                        if(checkBlackOponent(e.getX(), e.getY())){
                          validMove = true;
                        }
                        else{
                          validMove = false;
                        }
                      }
                    }
                    else{
                      validMove = true;
                    }
                  }
                }
                else{
                  validMove = false;
                }
              }
            }
      }

Aucun commentaire:

Enregistrer un commentaire