Anonymous Anonymous - 10 months ago
297 0

No description

Java

Chessthingss

package testApplication;


import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


public class TestApplication {
    /**
     * @param args the command line arguments
     */
    
    public static String[][] chessArray = new String [8][8];
    public static ArrayList <ChessItems> arrayList;
    
    public static void main(String[] args) {
        // TODO code application logic here
        AssignBoard(); //will assign board
        PrintBoard(); //prints current state of board
        
    }
      public static void PrintBoard()
      {
       
        for(int i =0; i < arrayList.size(); i++){
        	
            if((i)%8 == 0 && i > 0){
            	System.out.print("|\n|"+arrayList.get(i));
            }
            else{
                System.out.print("|" + arrayList.get(i));
            }
        
        }
        System.out.println("|\n");
      }
      
        
      public static void AssignBoard() /*assigns piece */ {

    	  arrayList = new ArrayList<>();
	       for(int i =0; i< 64; i++)
	       {
	           arrayList.add(null);
	       
	       }
          //kings and queens
          chessArray [0][4] = "k";
          ChessItems bking = new ChessPiece("k",0,4,8);  
          arrayList.set(bking.returnPosition(), bking);
          chessArray [7][4] = "K";
          ChessItems wking = new ChessPiece("K", 7,4,8);
          arrayList.set(wking.returnPosition(), wking);
          chessArray [0][3] = "q";
          ChessItems bqueen = new ChessPiece("q",0,3,8);
          arrayList.set(bqueen.returnPosition(), bqueen);
          chessArray [7][3] = "Q";
          ChessItems wqueen = new ChessPiece("Q",7,3,8);  
          arrayList.set(wqueen.returnPosition(), wqueen);
          
          //Bishops
          chessArray [0][2] = "b";
          ChessItems bbishop1 = new ChessPiece("b",0,2,8);  
          arrayList.set(bbishop1.returnPosition(), bbishop1);
          chessArray [0][5] = "b";
          ChessItems bbishop2 = new ChessPiece("b",0,5,8);  
          arrayList.set(bbishop2.returnPosition(), bbishop2);
          chessArray [7][2] = "B";
          ChessItems wbishop1 = new ChessPiece("B",7,2,8);  
          arrayList.set(wbishop1.returnPosition(), wbishop1);
          chessArray [7][5] = "B";
          ChessItems wbishop2 = new ChessPiece("B",7,5,8);  
          arrayList.set(wbishop2.returnPosition(), wbishop2);
          //Knights
          chessArray [0][1] = "n";
          ChessItems bknight1 = new ChessPiece("n",0,1,8);  
          arrayList.set(bknight1.returnPosition(), bknight1);
          chessArray [0][6] = "n";
          ChessItems bknight2 = new ChessPiece("n",0,6,8);  
          arrayList.set(bknight2.returnPosition(), bknight2);
          chessArray [7][1] = "N";
          ChessItems wknight1 = new ChessPiece("N",7,1,8);  
          arrayList.set(wknight1.returnPosition(), wknight1);
          chessArray [7][6] = "N";
          ChessItems wknight2 = new ChessPiece("N",7,6,8);
          arrayList.set(wknight2.returnPosition(), wknight2);
          //Rooks
          chessArray [0][0] = "r";
          ChessItems brook1 = new ChessPiece("r",0,0,8);  
          arrayList.set(brook1.returnPosition(), brook1);
          chessArray [0][7] = "r";
          ChessItems brook2 = new ChessPiece("r",0,7,8);  
          arrayList.set(brook2.returnPosition(), brook2);
          chessArray [7][0] = "R";
          ChessItems wrook1 = new ChessPiece("R",7,0,8);  
          arrayList.set(wrook1.returnPosition(), wrook1);
          chessArray [7][7] = "R";
          ChessItems wrook2 = new ChessPiece("R",7,7,8);  
          arrayList.set(wrook2.returnPosition(), wrook2);
          
          //lowercase pawns
          for (int x=0;x<8;x++)
          {
              chessArray[1][x] = "p";
              arrayList.set((1*8+x),new ChessPiece("p", 1, x, 8));
          }
          
          //uppercase pawns
          for (int x=0;x<8;x++)
          {
              //chessArray[6][x] = "P";
              arrayList.set((6*8+x),new ChessPiece("P", 6, x, 8));
          }
          for(int x = 0; x < arrayList.size(); x++) {
        	  if(arrayList.get(x) == null) {
        		  arrayList.set(x, new ChessPiece("0", x, x, 8));
        	  }
          }
                   
      }

    
             
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download