Package Model

Source Code of Model.ChineseChess

package Model;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

import View.GameView;

public class ChineseChess {

  
    RedChess[] r;
    BlackChess[] b;
    ImageSource img;
    String[] name = new String[]
        {"General","Advisor","Advisor","Elephant","Elephant","Horse","Horse","Chariot","Chariot","Cannon","Cannon","Soldier","Soldier","Soldier","Soldier","Soldier"};
    String[] beng = new String[]
        {"將","士","士","象","象","馬","馬","車","車","包","包","卒","卒","卒","卒","卒"};
    String[] reng = new String[]
        {"帥","仕","仕","相","相","瑪","瑪","車","車","炮","炮","兵","兵","兵","兵","兵"};
    int[] x = new int[]
        {4,3,5,2,6,1,7,0,8,1,7,0,2,4,6,8};
    int[] ry = new int[]
        {0,0,0,0,0,0,0,0,0,2,2,3,3,3,3,3};
    int[] by = new int[]
        {9,9,9,9,9,9,9,9,9,7,7,6,6,6,6,6};
   
    public ChineseChess(){
     
      new GameView(this);
      img = new ImageSource();
      r = new RedChess[16];
      b = new BlackChess[16];
     
        System.out.printf("%10s\t\t%s\t%s\t%s\n","name","ID","座標X","座標Y");
       for(int i=0;i<r.length;i++){
        
           r[i] = new RedChess(name[i], i+1, x[i], ry[i], true,img.getRedImageSource(i));
           b[i] = new BlackChess(name[i], i+17, x[i], by[i], true, img.getBlackImageSource(i));
          
           r[i].setEng(reng[i]);
           b[i].setEng(beng[i]);
       }
      
       for(int i=0;i<10;i++){
         for(int j=0;j<9;j++){
             for(int k=0;k<16;k++){
                if(r[k].getPositionX() == j && r[k].getPositionY() == i){
                  System.out.printf("%s",r[k].getEng());
                }
                else if(b[k].getPositionX() == j && b[k].getPositionY() == i){
                  System.out.printf("%s",b[k].getEng());
                }
                else{
                  System.out.printf("");
                }
             }
         }
         System.out.println();
       }
     
    }
    public boolean hasChess(int x,int y){    System.out.println("begin hasChess");
   
     
        for(int i=0;i<r.length;i++){
         
         
          System.out.println(x+" "+y);
          System.out.println("RED : X =>"+r[i].getPositionX()+"   "+"Y =>"+r[i].getPositionY());
          System.out.println("BLACK : X =>"+b[i].getPositionX()+"   "+"Y =>"+b[i].getPositionY());
          
            if(r[i].getPositionX() == x && r[i].getPositionY() == y){  
          //    System.out.println(x+" "+y);
          //    System.out.println("X =>"+r[i].getPositionX()+"   "+"Y =>"+r[i].getPositionY());
             
              System.out.println("找到RED => ("+r[i].getPositionX()+" , "+r[i].getPositionY()+")");
               return true;
            }
            if(b[i].getPositionX() == x && b[i].getPositionY() == y){ 
          //    System.out.println(x+" "+y);
          //    System.out.println("X =>"+b[i].getPositionX()+"   "+"Y =>"+b[i].getPositionY());
             
              System.out.println("找到BLACK => ("+b[i].getPositionX()+" , "+b[i].getPositionY()+")");
               return true;
            }
           
        }
       
        return false;
    }
    public RedChess[] getRedChess(){
       return this.r;
    }
    public BlackChess[] getBlackChess(){
       return this.b;
    }
}
TOP

Related Classes of Model.ChineseChess

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.