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

[تنبيه - عنوان غير مناسب : ]مساعدة في تصميم لعبة

بدأه الخد التريب في 22 نوفمبر 2008 · 2 رد · 532 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله و بركاته

هذي اول مشاركة و طلب الي و اتمنى ما تخيبوني ..

بما اني مبتدأة في الجافا صادتني مشكلة في graphic interface اللي يمكن البعض يعتبرها سهله ..ابغي مساعدة في تصميم الديزاين اولا

اتمنى انكم تساعدوني في اسرع وقت لاني متعطلة اسوي implement بسبب design

التصميم عبارة :

grid consists of 100 squares each of 50× 50 with the following shapes:

908738258.jpg

Radio Button انسوهم لان تم الغاءهم من اللعبة

هذا الكود اللي سويته اللي بس يظهر المربعات بدون الاشكال داخلها و button

import  java.awt.*;
import  javax.swing.*;
import java.awt.event.*;
public class BestGift extends JFrame implements ActionListener
{
private JButton b1;
private Board area;
public BestGift()
{
	 JPanel area = new JPanel();
		area= new Board();
  b1= new JButton("New Game");
	 Container content = this.getContentPane();
	  content.add(area,BorderLayout.CENTER); 
	  content.add(b1,BorderLayout.SOUTH);	 
	 b1.addActionListener( this);
}

public void actionPerformed(ActionEvent event)
{
  /////////////////////
}
public static void main(String[] args)
	{ 
	 BestGift b = new BestGift();
	 b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	   b.setSize(509,560);
		b.setTitle("Best Gift");
		b.setResizable(false);
		b.setVisible(true);  
	 } 
}

// DrawingArea
class Board extends JPanel
{
private Square[][] boardArray;
public Board ()
{
  boardArray = new Square[10][10];
  for (int row = 0;  row < 10; row++)
  {
   for (int col = 0; col < 10; col++)
   {
	int x= row*50;
	int y= col*50;
	   boardArray[row][col] = new Square(x,y);
   }
  }
}

	public void paintComponent( Graphics g )
	{
	 super.paintComponent(g);
	 setBackground(Color.white);
		for (int row = 0; row < 10; row++) 
		{
		 for (int col = 0; col < 10; col++)
		 {
		  int x= row*50;
	   int y= col*50;
		  g.drawRect(x,y,50,50);
		 }
		}
	}
}

// on of square
class Square
{
int x;
int y;
char graphic_type;
boolean locked = false;
public Square(int width,int heigth)
	{
	 x = width;
	 y = heigth;
   //	gt = graphic_type;
	 locked = false;
	}
public int getX()
	{
	 return x;
	}
	public int getY()
	{
	 return y;
	}
	public void setLocked(boolean locked)
	{
	 this.locked = locked;
	} 
	public void isLocked()
	{
	 locked = true; 
	}
	public boolean locked()
	{
	 return locked;
	}
	public void setGtype( char gt )
	{
	 graphic_type = gt;
	} 
  public char getGtype( char gt )
  {
   return graphic_type;
   } 
}

في تصميم grid سويت المربعات فقط، بس اني ابغي اسوي في كل مربع شكل و هذا الشي

موجود في class Square .. parameter من نوع char اللي تدل على نوع الشكل اللي في المربع .. عاد اني ما حطيت هالباراميتر لحد الآن في ..constructer لاني في البداية كنت بصمم المربعات و اشوف الكود شغال لو لا .. و يوم جيت اسوي shape داخله بدت المشكلة.

الفكرة هي في class Board في paint نخلي if statement .. انه مثلا اذا حرف R بتطبق هالكود g.fillRect و اذا حرف A بتطبق كود g.fiiArc و هلما جرى

اني حاولت اسوي هالشي و فشلت فيه لان ما قام يطبق الي اللي سويته.. و بعد انه مستحيل

اخلي array فيها 100 char من shape و بعدين امشي عليها واحط if statment

و فشلت اني اسوي array فيها 3 char للاشكال الثلاثة و اسوي random

لان اللعبة لزما فيها شكلين نفس الشي متتاليين و هالشي اللي ما قدرت اطبقه باستخدام random

ما ادري اذا فهمتون اللي و الا لا

من جد اتمنى تساعدوني في تصميم graphic interface بداية و بعدين اذا صار بحاول استشيركم في implements اذا بديت فيه

تم تعديل هذه المشاركة بواسطة علاء الصالحي في 23 نوفمبر 2008 في 04:03 — السبب: تزبيط وسم code

#2

الأخ الكريم/الأخت الكريمة

السلام عليكم ورحمة الله وبركاته

مرحباً بكم في منتدى الفريق العربي للبرمجة

نود تنبيهك أن العنوان غير مناسب.

الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.

وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!

قواعد المشاركة

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#3

السلام عليكم

في الكود التالي يتم رسم و توزيع الأشكال بشكل عشوائي (random)

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class BestGift extends JFrame implements ActionListener {

	public static final char Arc = 'a';
	public static final char Rect = 'r';
	public static final char Circle = 'c';

	private JButton b1;

	public BestGift() {
		JPanel area = new Board();
		b1 = new JButton("New Game");
		Container content = this.getContentPane();
		content.add(area, BorderLayout.CENTER);
		content.add(b1, BorderLayout.SOUTH);
		b1.addActionListener(this);
	}

	public void actionPerformed(ActionEvent event) {
		// ///////////////////
	}

	public static void main(String[] args) {
		BestGift b = new BestGift();
		b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		b.setSize(509, 560);
		b.setTitle("Best Gift");
		b.setResizable(false);
		b.setVisible(true);
	}

//	 DrawingArea
	class Board extends JPanel {
		private Square[][] boardArray;

		public Board() {
			boardArray = new Square[10][10];
			for (int row = 0; row < 10; row++) {
				for (int col = 0; col < 10; col++) {
					int x = row * 50;
					int y = col * 50;
					boardArray[row][col] = new Square(x, y, randomShape());
				}
			}
		}

		public void paintComponent(Graphics g) {
			super.paintComponent(g);
			setBackground(Color.white);
			for (int row = 0; row < 10; row++) {
				for (int col = 0; col < 10; col++) {				
					boardArray[row][col].draw(g);
				}
			}
		}

		public char randomShape(){
			int rnd = (int) Math.floor(Math.random() * 3);
			switch(rnd){
				case 0: return Arc;
				case 1: return Rect;
				default: return Circle;
			}
		}		
	}

	class Square {
		int x;
		int y;
		char graphic_type;
		boolean locked = false;

		public Square(int width, int heigth, char gt) {
			x = width;
			y = heigth;
			graphic_type = gt;
			locked = false;
		}

		public void draw(Graphics g){
			g.drawRect(x, y, 50, 50);

			if(graphic_type==Arc){
				int R = 30;
				g.setColor(Color.black);
				g.fillArc(x + 25 - R / 2, y + 25 - R / 2, R, R, 0, 180);
			} else if(graphic_type==Rect){
				int R = 30;
				g.setColor(Color.black);
				g.fillRoundRect(x + 25 - R / 2, y + 25 - R / 2, R , R , 10, 10);
			} else if(graphic_type==Circle){
				int R = 30;
				g.setColor(Color.black);
				g.fillOval(x + 25 - R / 2, y + 25 - R / 2, R, R);
			}

		}

		public int getX() {
			return x;
		}

		public int getY() {
			return y;
		}

		public void setLocked(boolean locked) {
			this.locked = locked;
		}

		public void isLocked() {
			locked = true;
		}

		public boolean locked() {
			return locked;
		}

		public void setGtype(char gt) {
			graphic_type = gt;
		}

		public char getGtype(char gt) {
			return graphic_type;
		}			
	}			
}

و لكن ماذا تقصد بـ :

اقتباس
لان اللعبة لزما فيها شكلين نفس الشي متتاليين

هل المقصود أن التوزيع العشوائي يجب أن يكون بحيث أن كل شكل له مجاور واحد على الأقل من نفس الشكل ..؟؟!

و هل التجاور أفقي و عمودي فقط (لكل مربع 4 جيران) ,

post-152370-1227471772_thumb.png

أم قطري أيضاً (لكل مربع 8 جيران)..؟؟!!

post-152370-1227471780_thumb.png

أرجو التوضيح لنتمكن من المتابعة ..

أبو خالد السوري

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…