הקלאס של Start לא קורה לעצמו רקורסיבית ב קונסטראקטור.. הוא קורה למתודה בשם start עם s קטנה שמפעילה את כול התוכנית.
הסיבה שאני עושה את זה, כי אמרו לנו שב main אסור שיהיה יותר מ 10 שורות.בתוך main עצמו אני עושה
בשביל שיתחיל להריץ את את המתודה של Start בשם start שנמצאת בקונסטראקטור שלו
אני טיפה חלש בהגדרות.. אבל אני ינסה לפשט את מה שאני מנסה לעשות..
m_ChessBord זה המערך של לוח השח מט שלי.
לכול סוג של חייל אני פותח קלאס , בפנים אני יוצר מתודה שבה אני לוקח את הקורדינטה שהוא נמצא בא , ובדוק האם הקורדינטה שהוא רוצה להגיע אליה על הלוח היא ריקה או תפוסה.
מה שרשמתי בהודעה הראשונה .getm_ChessBord(x, y)==null מתבצע מתוך הקלאס של החייל , אני צריך מישם גישה למשתנה m_ChessBord לבצע בדיקות בתאים שלו.
m_ChessBord יכיל בתוך כול תא (לא בכולם ) חיילים שהם מוגדרים מסוג CheckTool
/** * This Class is the main class of all the check tools that will extend this class * will have a general stuff. * Color , name , position (source). */ public class CheckTool { private String m_Name; // contain the color of the Soldier private String m_Color; // contain the color of the Soldier private int m_Xsource; // Contain the X coordination of the source position private int m_Ysource; // Contain the Y coordination of the source position /** * The Contractor that set for the default value */ public CheckTool (String a_Name , String a_Color , int a_Xsource ,int a_Ysource) { m_Name = a_Name; // getting the Soldier name m_Color = a_Color; // setting the default m_Xsource = a_Xsource; // setting the default m_Ysource = a_Ysource; // setting the default } /** * This method set the color of the Soldier * @param a_Color - hold a string with the color of the soldier */ public void setm_Color(String a_Color) { this.m_Color = a_Color; } /** * This method getting the color of the Soldier * @return the m_Color */ public String getm_Color() { return m_Color; } /** * This method setting the X coordination of the soldier * @param m_Xsource - hold the int of the X coordination of the soldier */ public void setm_Xsource(int a_Xsource) { this.m_Xsource = a_Xsource; } /** * This method getting the X coordination of the soldier * @return the m_Xsource */ public int getm_Xsource() { return m_Xsource; } /** * This method setting the Y coordination of the soldier * @param m_Ysource - hold the int of the Y coordination of the soldier */ public void setm_Ysource(int a_Ysource) { this.m_Ysource = a_Ysource; } /** * This method getting the Y coordination of the soldier * @return the m_Ysource */ public int getm_Ysource() { return m_Ysource; } /** * This method setting the Soldier name * @param m_Name the m_Name to set */ public void setm_Name(String a_Name) { this.m_Name = a_Name; } /** * This method getting the Soldier name * @return the m_Name */ public String getm_Name() { return m_Name; } }
|
** * * This Class will contain all the Program method's and process * */ public class Start { public static CheckTool m_ChessBord = new CheckTool 8X8; מישום מה הוא מוחק לי את זה.. אבל זה רשום נכון כסינטקס public Start () { start(); } public void start () { סתם בדיקות pawn b ; b = new pawn(); boolean c = false; c= b.ValidMove(0, 0, 5, 5); System.out.println (""); } /** * This method setting in the board a soldier in a certain coordination * @param a_ChessBord - hold the soldier details */ public void setm_ChessBordEnemy(CheckTool a_ChessBord) { this.m_ChessBord = a_ChessBord; } /** * This method getting if there any soldier in a certain coordination on the board * @param x - holding the x coordination for checking * @param y - holding the y coordination for checking * @return the m_ChessBord */ public static boolean getm_ChessBordEnemy(int x ,int y) { boolean empty = false; if (m_ChessBord==null) { empty = true; } return empty; }
|
public class pawn extends CheckTool{ private boolean m_AsStart; // indicator if the Soldier moved from the game start or not /** * This is the contractor that will set the Soldier name */ public pawn (String a_Color,int a_Xsource , int a_Ysource) { super ("Pawn" ,a_Color,a_Xsource,a_Ysource); // starting the CheckTool contractor m_AsStart = true; // setting the As Start to true (didn't moved from the start) } public boolean ValidMove (int X , int Y ,int XX ,int YY) { if (X==XX&&YY==Y+1&&כאן אני צריך את הפקודה שרשמתי בהודעה הראשונה)כמו שאמרתי לך פה הוא לא נותן לי להכניס אותה . רק אם אני מגדיר אותה כ static זה נותן לי בצורה שרשמתי מעל.
|
אשמח להכוונות במידה ואני לא עובד נכון.
תודה רבה!
