Permalink
Browse files

King can Jump and code fix

  • Loading branch information...
Subhanga
Subhanga committed Nov 26, 2012
1 parent d00c35a commit 7c1d54eebd26a38bafc17e6c56cf6aabd74dc440
@@ -445,7 +445,7 @@ public void onClick(View arg0)
}
else if (canJump(clickedButton))
{
- Jump(clickedButton);
+ Move(clickedButton);
if (canBeKing(clickedButton))
{
makeKing(clickedButton);
@@ -472,6 +472,7 @@ else if (canJump(clickedButton))
}
}
+
private boolean canBeKing (MyButton pbutton) {
if(pbutton.isPlayerGreen() && pbutton.getPx() == 0)
{
@@ -498,31 +499,17 @@ else if (!pButton.isPlayerGreen())
}
pButton.setCrown(true);
}
+
- private boolean isKing(MyButton pButton)
+ private boolean isKing(MyButton pButton)
{
if(pButton.isCrown())
return true;
else
return false;
}
- private void Jump(MyButton clickedButton)
- {
-
- int changeImage = orangePlayer;
- if (prevButton.isPlayerGreen())
- changeImage = greenPlayer;
- clickedButton.setImageResource(changeImage);
- clickedButton.setEmpty(false);
- clickedButton.setPlayerGreen(prevButton.isPlayerGreen());
-
- prevButton.setEmpty(true);
- prevButton.setImageResource(0);
- setBackground(R.drawable.bg_board_bright, prevButton);
-
- prevButton = null;
- }
+
private void Move(MyButton clickedButton)
{
@@ -589,8 +576,8 @@ private boolean canMove(MyButton button)
private boolean canJump(MyButton cbutton)
{
- if (!prevButton.isCrown()){
-
+ if (!prevButton.isCrown())
+ {
int change_In_X = (cbutton.getPx() - prevButton.getPx())/2;
int change_In_Y = (cbutton.getPy() - prevButton.getPy())/2;
@@ -638,8 +625,55 @@ private boolean canJump(MyButton cbutton)
}
}
}
- else {
- return false;
+
+ else
+ {
+ int change_In_X = (cbutton.getPx() - prevButton.getPx())/2;
+ int change_In_Y = (cbutton.getPy() - prevButton.getPy())/2;
+
+ MyButton middleButton = (MyButton)findViewById((prevButton.getPx() + change_In_X) *10 + (prevButton.getPy() + change_In_Y));
+
+ if(prevButton.isPlayerGreen())
+ {
+ if (abs(cbutton.getPx()-prevButton.getPx()) == 2 && abs(cbutton.getPy()-prevButton.getPy()) == 2)
+ {
+ if (middleButton.isPlayerGreen() != prevButton.isPlayerGreen())
+ {
+ middleButton.setEmpty(true);
+ middleButton.setImageResource(0);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ if (abs(cbutton.getPx()-prevButton.getPx()) == 2 && abs(cbutton.getPy()-prevButton.getPy()) == 2)
+ {
+ if (middleButton.isPlayerGreen() != prevButton.isPlayerGreen())
+ {
+ middleButton.setEmpty(true);
+ middleButton.setImageResource(0);
+ return true;
+ }
+
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
}
}

0 comments on commit 7c1d54e

Please sign in to comment.