home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 October A / Pcwk10a98.iso / Inprise / TRIAL / JBUILDER / JSAMPLES.Z / KingPos.java < prev    next >
Text File  |  1998-05-08  |  3KB  |  119 lines

  1. /*
  2.  * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
  3.  * 
  4.  * This SOURCE CODE FILE, which has been provided by Borland as part
  5.  * of a Borland product for use ONLY by licensed users of the product,
  6.  * includes CONFIDENTIAL and PROPRIETARY information of Borland.  
  7.  *
  8.  * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS 
  9.  * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
  10.  * THE PRODUCT.
  11.  *
  12.  * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
  13.  * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
  14.  * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
  15.  * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
  16.  * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
  17.  * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
  18.  * CODE FILE.
  19.  */
  20. package borland.samples.apps.chess.client;
  21.  
  22. import borland.samples.apps.chess.client.board.*;
  23.  
  24. /**helper class for the ChessRules class
  25. */
  26. public class KingPos
  27. {
  28.   private int kingRank = -1;
  29.   private int kingFile = -1;
  30.   private int kingCheckCount = 0;
  31.   private int attacker = -1;
  32.   private int attackerFile = -1;
  33.   private int attackerRank = -1;
  34.   private int kingColor;
  35.  
  36.   public KingPos(int color) {
  37.     if (color == Chessboard.WHITEPIECE)
  38.       kingColor = Chessboard.WHITEPIECE ;
  39.     else
  40.       kingColor = Chessboard.BLACKPIECE;
  41.   }
  42.  
  43.   public int getKingColor() {
  44.     return kingColor;
  45.   }
  46.  
  47.   public boolean kingPosEquals(int file,int rank){
  48.     if (rank == kingRank && file == kingFile)
  49.       return true;
  50.     else
  51.       return false;
  52.   }
  53.  
  54.   public void setKingPos(int file,int rank) {
  55.     if (rank >= 0)
  56.       kingRank = rank;
  57.     if (file >= 0)
  58.       kingFile = file;
  59.   //System.out.println("King Pos = " + file + rank + " (" + kingColor);
  60.   }
  61.  
  62.   public void setAttacker(int piecevalue,int file,int rank){
  63.     if (piecevalue  < 0) {
  64.       System.out.println("no attacker");
  65.       attacker = -1;
  66.       attackerRank = -1;
  67.       attackerFile = -1;
  68.       kingCheckCount = 0;
  69.     }
  70.     else {
  71.       System.out.println("found attacker" + piecevalue + file + rank);
  72.       attacker = piecevalue;
  73.       attackerRank = rank;
  74.       attackerFile = file;
  75.       kingCheckCount++;
  76.     }
  77.   }
  78.  
  79.   public int getKingFile(){
  80.     return kingFile;
  81.   }
  82.  
  83.   public int getKingRank(){
  84.     return kingRank;
  85.   }
  86.  
  87.   public int getAttacker() {
  88.    return attacker;
  89.   }
  90.  
  91.   public int getAttackerFile() {
  92.     return attackerFile;
  93.   }
  94.  
  95.   public int getAttackerRank() {
  96.     return attackerRank;
  97.   }
  98.  
  99.   public void kingInCheck(boolean b) {
  100.     if (b)
  101.       kingCheckCount++;
  102.     else {
  103.       // System.out.println("no attacker");
  104.       attacker = -1;
  105.       attackerRank = -1;
  106.       attackerFile = -1;
  107.       kingCheckCount = 0;
  108.     }
  109.   }
  110.  
  111.   public boolean isDoubleCheck() {
  112.     return (kingCheckCount > 1)  ;
  113.   }
  114.  
  115.   public boolean isInCheck () {
  116.     return (kingCheckCount != 0);
  117.   }
  118. }
  119.