الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تفضلوا برنامجي!

مغلق
بدأه حسام الملحم في 15 يناير 2005 · 16 رد · 3,234 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم...

هذا البرنامج صنعته منذ زمن. إليكم هذه اللعبة التي يمكن تشغيلها بالضغط على ملف Queens.jar مرتين.

لا يحتاج لتشغيلها إلا المحرك JRE 1.4 على ما أظن :unsure:

كما يمكنكم تشغيلها كبريمج على المتصفح. اسم البريمج QueensApplet.class داخل الرزمة Queens.jar

هل تستطيع الفوز؟

ملاحظة: لا تنس إرفاق اسمي مع البرنامج إن كنت ستضعه في صفحتك!!!

حسام الملحم......

Queens.jar

#2

نسيت شرح اللعبة:

ضع ثمانية وزراء على الرقعة (من لعبة الشطرنج) على أن لا يهدد أحد منهم الآخر.

إذا فزت في اللعبة ووضعت الثمانية على الرقعة، فشارك بوضع الأرقام التي انتصرت بها في المنتدى....

أنتظر الإجابات....

#3

حلو الكلام...

مع انني منشغل جدا جدا و لكن اعدك ان احاول..

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#4

هه :lol: ... حليتها لكان يا عم انا آخذ ميدالية في الشطرنج على مستوى مدينتي (h)

ramywon.JPG

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#5

يبدو انني لم اعطي فرصة للآخرين...

سؤال هل يمكن وضع تسعة

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#6

مستحيل، على فكرة لا تستطيع وضع 9 قلاع!!!

يوجد العديد من الحلول ما يقارب 92 حلا.

مع التنويه أن هذا البرنامج يؤدي إلى تسهيل اللعبة بأن يعرض عليك الأماكن التي لا تستطيع وضع قطعة معينة فيه! ولهذا صنعت البرنامج (حتى يتسنى لي حلها بسرعة بدون أن تزغلل عيناي في اللوحة!!!

وعلى حد علمي فإن هذا اللغز يعطى في مادة البرمجة 202 في جامعة البترول كتدريب لاستخدام الطريقة التي تستدعي نفسها للحصول على النتيجة.

تم تعديل هذه المشاركة بواسطة أبومازن في 16 يناير 2005 في 00:08

#7

يعني ان عملته كواجب للجامعة اللي درست فيها ؟؟

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#8

أنا لم آخذ أي درس برمجي في الجامعة، تعلمت اللغة بمفردي ولي قصة طويلة!

لكن العلم جاءني أن في هذه المادة يدرسون (الطريقة التي تنادي نفسها) recursive method ويطبقونها على الأقل فكريا في شكل كتابة طريقة أو وسيلة تحل هذه المشكلة بإنتاج جواب يمكن من وضع ثمانية قطع على الطاولة!

#9

هلأ دخلت على المنتدى و شفت المشاركة و بأقل من 0.000001 ثا حليتها

لكان يا عم انا آخذ ميدالية في الشطرنج على مستوى بلدي

ra.jpg

الحياة كلها وقفة عز فقط

------------------------------------------

المجتمع معرفة و المعرفة قوة

#10

لو مكثت دقيقة لأنتجت أكثر....

92 حلا.....

لم أستطع إرفاق بعض الصور،، لم أعرف كيف!!!

#11

وجدت أكتر من هاد الحل بس ما حطيت غير هاد

ادخل على هذا الربط و حمل الصورة من جهازك و بعدين خود عنوان الصورة و عندما تضيف مشاركة اضغط على زر IMG و أدخل عنوان صورتك فتظهر في المشاركة

تحميل الصور

تم تعديل هذه المشاركة بواسطة hani1 في 17 يناير 2005 في 20:40

الحياة كلها وقفة عز فقط

------------------------------------------

المجتمع معرفة و المعرفة قوة

#12

هاني .... هاني... حراتنا ضيقة و نعرف بعض وين مداليتك ؟؟؟

انا و انت بنفس القطر كيف اخذتها بدون علمي اصلا اللي اخذها على مستوى القطر هو " شلاش حطحجر" و الثاني " سليم مشولش" و الثالث " صطيف علاكو "

و انت و لا واحد منهم؟؟؟

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#13

queens.jpg

يعطيك العافية..

#14

هذا هو شفرة البرنامج لتعم الفائدة.... مكون من صفان أساسيان لشغيل البرنامج وصف آخر بسيط لجعله بريمج.....

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class ButtonBoard extends JFrame{ ///Just a Bourd countaining Buttons 
	//Just Run the class and see 
	//This class is used by other programs to make it easy to use a Button Bourd Like Queens
	private JButton button[][];
	private int row,col;
	ButtonBoard(int row,int col){	//constructor
  this.row=row;
  this.col=col;
  getContentPane().setLayout(new GridLayout(row,col));//layout, all companents layed all equal sizes in a table, like a spread sheet
  button=new JButton[row][col];//creating the Array, But still empty.
  int x=0;
  for(int i=0;i<button.length;i++)
 	 for(int o=0;o<button.length;o++){	//filling the Array, and laying it on the contentPane
    button[o]=new JButton(""+(++x));
    getContentPane().add(button[o]);
 	 }
  pack();	//(Very Good)Shrinks the Frame to the Preffered Size, according to all its components
  setDefaultCloseOperation(EXIT_ON_CLOSE);//If you close the Frame, the Program will exit
	}

	public void addActionListener(ActionListener al){//This Method Allows any body who can listen to action Events to listen to all Buttons
  for(int i=0;i<button.length;i++)
 	 for(int o=0;o<button.length;o++)
    button[o].addActionListener(al);
	}

	public JButton getButton(int row,int col){//returns a button based on a row and colomn
  return button[row][col];
	}

	public JButton getButton(int index){//returns a button based on an Index
  return (JButton)(getContentPane().getComponent(index));
	}
  
	public int getRow(JButton b){// returns the row of a button
  for(int i=0;i<button.length;i++)
 	 for(int o=0;o<button.length;o++)
    if(b==button[o])return i;
  return -1;
	}
	public int getCol(JButton b){//returns the col
  for(int i=0;i<button.length;i++)
 	 for(int o=0;o<button.length;o++)
    if(b==button[o])return o;
  return -1;
	}

	public static void main(String[]a){// A Test Main Method, Run it and see
  ButtonBoard b=new ButtonBoard(16,18);//creating the Button Board
  b.show();//displaying
  System.out.println(b.getButton(1,1).getText());
  System.out.println(b.getButton(1).getText());
	}
  
	public int getIndex(JButton b){//returns the Index of a button
  return Integer.parseInt(b.getText());
	}
}

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
class Queens implements ActionListener{//We want to listen to all Buttons
	// a program that uses a Button Board to act as a Chess Board
	//Put 8 Queens in the Board with out them threatning each other

	int max=8;
	int queenNo=0;
	ButtonBoard bb;
	Color normalColor=Color.gray;//The button is empty. These colors reflecting the type of button
	Color queenColor=Color.red;// The Button has a queen
	Color wayColor=Color.green;// The Button is in a way of a queen.
	Vector v;//the collection of the queen buttons
	Queens(boolean autoShow){//constuctor, When we create a new Object shall we show the Frame automatically or wait.
  bb=new ButtonBoard(8,8);//creating a Button Board
  bb.addActionListener(this);//This Object will listen to all Buttons 
  bb.setTitle("Hussam's Queens Problem.");
  for(int i=0;i<64;i++)//changing the COlor of all
 	 bb.getButton(i).setBackground(normalColor);
  v=new Vector();
  if(autoShow)show();
  //to change the Title window each 3 sec.
  javax.swing.Timer t=new javax.swing.Timer(3000,new ActionListener(){
 	 public void actionPerformed(ActionEvent ae){
    if (bb.getTitle().equals("Hussam's Queens Problem."))bb.setTitle("Place 8 Queens on the chess table");
    else bb.setTitle("Hussam's Queens Problem.");
 	 }
  });
  t.start();//to start the timer, to change the title every 3 sec
	}

	public void show(){
  bb.show();
	}

	public void actionPerformed(ActionEvent e){//receives Events for the Buttons
  JButton b=(JButton)e.getSource();
  
  if(b.getBackground().equals(normalColor))v.add(b);//if it is normal (not a queen button neither a way button) then make it a queen button and add it
  else if(b.getBackground().equals(queenColor))v.remove(b);//if it is a queen button then cancel it and make it normal
  else return;//if it was a green button
  setWays();//check and make all the souronding buttons to be Ways (Green) so that they canot be choosen
  if(v.size()==8)JOptionPane.showMessageDialog(null,"You won. 8 Queens are on the table.");
  
	}

	public static void main(String[]a){
  Queens q=new Queens(true);// new Game and auto show
  //q.show(); //use this if it is set to manual show;
	}

	private void setQueen(int row,int col){//make the Button in the row and colomn specified to be a queen button
  bb.getButton(row,col).setBackground(queenColor);
  
	}

	private void setWays(JButton b,Color c){//the starting method for calculating
  
  int row,col,index;
  row=bb.getRow(b);
  col=bb.getCol(b);
  index=bb.getIndex(b);
  setWay(row,col,8,c);
  setWay(row,col,-8,c);
  setWay(row,col,1,c);
  setWay(row,col,-1,c);
  setWay(row,col,9,c);
  setWay(row,col,-9,c);
  setWay(row,col,7,c);
  setWay(row,col,-7,c);
  
  
  
	}
	private void clearWays(){
  for(int i=0;i<64;i++)
 	 bb.getButton(i).setBackground(normalColor);
	}

	private void setWays(){
  clearWays();
  Iterator r=v.iterator();
  while(r.hasNext())
 	 setWays((JButton)r.next(),wayColor);
  r=v.iterator();
  while(r.hasNext())
 	 ((JButton)r.next()).setBackground(queenColor);
 	 
	}
	private void setWay(int row,int col,int space,Color c){//recursive method calculating 
  try{
 	 bb.getButton(row,col).setBackground(c);
 	 switch(space){
    case(1):col++;break;
    case(-1):col--;break;
    case(8):row++;break;
    case(-8):row--;break;
    case(9):col++;row++;break;
    case(-9):col--;row--;break;
    case(7):col--;row++;break;
    case(-7):col++;row--;break;
 	 }

 	 setWay(row,col,space,c);
 	 
  }catch(ArrayIndexOutOfBoundsException e){return;}
  
	}  
}

import javax.swing.*;

public class QueensApplet extends JApplet{

	public void init(){
  new Queens(true);
	}


}
#15

شكرا لك اخي و اتمنى منك ان تستمر بنفس وتيرة النشاط هذه ماشاء الله عليك

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#17

تلقيت رسالة من الأخ NUCLEAR تبين لي أن البرنامج غير موجود أو أن الوصلة لا تعمل.

هذا إصدار جديد، هو نفس البرنامج مع تغيير بسيط في النافذة!

لا أدري ولكن أعتقد أنه سيعمل على 1.4 من JDK !

كما أنوه أن هذه البرامج موجودة في صفحتي والله أعلم. وطبعا الشفرة ذهبت مع القرص الصلب الذي تعطل! الشيء الجميل أن الشفرة موجودة في المنتدى!

QueensAppletV1.5.zip

هذا الموضوع مغلق.

مواضيع مشابهة