Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public class Main {
  2. public static void main(String[] args) {
  3. Piece piece = new Piece();
  4. Queen queen = new Queen();
  5. Position testPosition = new Position(3,7);
  6. if(queen.isValidMove(testPosition)){
  7. System.out.println("Yes, I can move there.");
  8. }
  9. else {
  10. System.out.println("Nope, can't do!");
  11. }
  12. }
  13. }
  14.  
  15. public class Game {
  16. Piece [][] board;
  17. // Constructor creates an empty board
  18. Game(){
  19. board = new Piece[8][8];
  20. }
  21. }
  22.  
  23. public class Position {
  24. int row;
  25. int column;
  26. // Constructor using row and column values
  27. Position(int r, int c){
  28. this.row = r;
  29. this.column = c;
  30. }
  31. }
  32.  
  33. public class Piece {
  34. Position position;
  35.  
  36. boolean isValidMove(Position newPosition){
  37. if(position.row>0 && position.column>0
  38. && position.row<8 && position.column<8){
  39. return true;
  40. }
  41. else{
  42. return false;
  43. }
  44. }
  45. }
  46.  
  47. public class Queen extends Piece {
  48. int row;
  49. int column;
  50. boolean isValidMove(Position newPosition){
  51. if(newPosition.column == this.column || newPosition.row == this.row|| Math.abs(newPosition.column - this.column) == Math.abs(newPosition.row - this.row)){
  52. return true;
  53. }
  54. else{
  55. return false;
  56. }
  57. }
  58. }
  59.  
  60. boolean isValidMove(Position newPosition){
  61. // combine super.isValidMove(newPosition) and your current code
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement