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

كود لعبة

مغلق
بدأه shadooo في 17 ديسمبر 2007 · 2 رد · 676 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

جاري التطوير .......

import java.io.*;
public class SimpleDotCom2{
	int [] locationCells;
	int numofhits=0;
	public void setLocationCells(int[]locs){
		locationCells=locs;

	}
		public String checkyourself(String stringGuess){
			int guess=Integer.parseInt(stringGuess);
			String result="miss";
			for(int i=0;i<locationCells.length;i++)
			{
				if(guess==locationCells)
				{
					result="hit";
					numofhits++;
					break;

				}

			}
			if(numofhits==locationCells.length){
				result="kill";
			}
			System.out.println(result);
			return result;
		}
public static void main(String [] args){
	int numofguesses=0;//conter whit plyer
	SimpleDotCom2 dot=new SimpleDotCom2();
	Gamehelper helper=new Gamehelper();
		int randomnum=(int)(Math.random()*5);

		int [] locationCells={randomnum,randomnum+1,randomnum+2};

		dot.setLocationCells(locationCells);
		boolean  isAlive=true;
		while(isAlive==true){
			String guess=helper.getuserinput("enter a number");
			String result=dot.checkyourself(guess);
			numofguesses++;
			if(result.equals("kill")){

				isAlive=false;
				System.out.println(numofguesses+"guesses");
		}}


}

public static  class Gamehelper{
	public String getuserinput(String prompt)
	{
		String inputline=null;
		System.out.print(prompt+"  ");
			try{
				BufferedReader is =new BufferedReader(new InputStreamReader(System.in));
				inputline=is.readLine();
				if(inputline.length()==0)
					return null;

			}catch(IOException e){
				System.out.println("ioexception:"+e);


			}return  inputline;
	}
}
}

دائما عودتوني على ملاحظاتكم لاكوادني .....

لا تنسوا هذا الكود فهو من اكوادي

#2

ملاحظاتي :

1- ليه ال GameHelper عباره عن inner class ؟؟ كان ممكن أت جعله class عادي أو حتي method

2- ناقص وضع ال exception اللازمه ، مثل : NumberFormatException .....

3- ماذا تقصد ب miss و hit و kill ؟؟؟؟

4- ما فائدة جعل الداله هذه :

 public String getuserinput(String prompt)

instance method ؟؟؟؟؟؟

وكذلك كل الدوال في الفئه : SimpleDotCom2 ؟؟

5- ممممم، الفكره جيده و التنفيذ جيد

شكرا لك

#3

شكرا لك

1- اجبرني المترجم بوضع الGameHelper ستاتيك اما بالنسبة لل inner فلا اعرف ما ذا تقصد

2-ما زلت مبتداولا الم بكل الاكسبشنات

3-miss لم تصيب الهدف

hit اصابة هدف

kill الانتهاء من اللعبة القضاء على السفينة

4-

public String getuserinput(String prompt)

من اجل معالجة الادخال ب method وهوا السابق

شكرا

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

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