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

مساعده في لعبة الmystrey Game

مغلق
بدأه I love Java في 4 يناير 2008 · 8 رد · 788 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

ارجو المساعده في الخروج من لوب الwhile بشرطين:

1- ان الكاونتر وهو عدد المحاولات = 0<<وهذي محلوله

2- ان word2[] تحتوي على نفس محتويات word1[] اي ان الuser نجح في معرفة الكلمه<<هذي هي المشكله

وهذا هو الكود:

#include <iostream>
using namespace std;

int main()
{
	char word1[] = {'s', 'm', 'i', 'l', 'e'};
	char word2[] = {'_', '_', '_', '_', '_'};
	int size = 5;
	char letter;
	int counter = 6;

	cout << "*******Welcome to the mystrey word game*******";
	cout << "\n\nyou have 6 gessings to gess the word!";

	for(int i=0; i<size; i++)
	{
		cout<<word2<<" ";
	}

	cout << "\nEnter a letter:";
	cin >> letter;
	cout << "\n\n";

	while(counter > 0)
	{
		for(int i=0; i<size; i++)
		{	
			if (letter == word1){
				word2=letter;
				counter+=1;
				for(int i=0; i<size; i++)
				{
					cout<<word2<<" ";
				}
			}
		}
		counter-=1;


		if (counter == 0){
			cout << "you have no more gessings";
			break;}

		cout << "\nyou have " << counter << " gessings left to gess the word!";
		cout << "\nEnter the a letter:";
		cin >> letter;
		cout << "\n\n";

	}

	if (counter == 0)
		cout << "\nyou can try again later;)";

	return 0;
}
#2

اخي العزيز ..

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

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

تحياتي العطرة ..

يَارَبُ إِن ضَاقَت قُلُوُب الْنَّاسٍ عَنْ مّافِي .. مِنْ خَيْرٍٍ فَعَفْوكَ لَا يَضِيْقْ ..

#3

انا اقارن الletter بعناصر المصفوفه وليس بالمصفوفه نفسها، والمطلوب مقارنتها هي word1[] و word2[]<<هذي هي المصفوفات

#4

السلام عليكم

شوف هذا التعديل ... أرجو ألا يكون للأسوأ :unsure: :

// b.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
	char word1[] = {'s', 'm', 'i', 'l', 'e',0};
	char word2[] = {'_', '_', '_', '_', '_',0};
	int size = 5;
	char letter[5];
	int counter = 6;

	cout << "*******Welcome to the mystrey word game*******";
	cout << "\n\nyou have 6 gessings to gess the word!";

	for(int i=0; i<size; i++)
	{
		cout<<word2<<" ";
	}

	cout << "\nEnter a letter:";
	cin >> letter;
	cout << "\n\n";

	while(counter > 0)
	{
		for(int k=0; k<size; k++)
		{	
			if (letter[k] == word1[k])
			{
				word2[k]=letter[k];  
			}

		}
		counter-=1;
		cout<<word2<<" \n";
		if (letter[k] == word1[k])
		{
			cout << "Godjob!";
			cout << "\n";
			int e;
			cin >> e;
			return 0;
		}

		if (counter == 0){
			cout << "you have no more gessings";
			break;}

		cout << "\nyou have " << counter << " gessings left to gess the word!";
		cout << "\nEnter the a letter:";
		cin >> letter;
		cout << "\n\n";

	}

	if (counter == 0)
		cout << "\nyou can try again later;)";

	return 0;
}

mov eax, dword ptr ds:[0xffdf0308]

jmp dword ptr [eax+0xfc]

#5

للأسف يا أخ GamingMasteR كودك فيه أخطاء منطقيه، من غير ماأجربه

ولو تتبعته بتكتشف هالاخطاء :rolleyes:

عموما بوضح فكرتي عشان تتضح للجميع:

- The first array contains the mystery word which is: smile

- The second array contains only five dashes( the number of the letters in the mystery word)

- Then if the user guessed a litter of the mystery word, the program will but it in the correct position of the mystery word in the second array.

- The counter is the number of the tryings.

- If the user finished all the tryings, then the program will end the game.

- If the user guessed all the letters of the mystery word, the program will end the game.<<this is my problem

so i don't now how to compare between the first array and the second array, then break the while loop.

اتمنى تكون فكرتي الحين وضحت.

تم تعديل هذه المشاركة بواسطة I love Java في 4 يناير 2008 في 21:10

#6

بص دا ال output بتاع البرنامج لما شغلته و طبعا مش هو دا اللى إنت عايزه أساسا

screenshotahmedubuntubote9.png

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

أما بخصوص المقارنة فا ليه متستخدمش strcmp() ؟ و لو لقيتهم متساويين يبقى المستخدم دخل الكلمة كلها صح.

#7

هذا هو الout put اللي انا ابيه

وممكن تشرحلي الmethod: strcmp()? لو سمحت

#8

بحثت عن الmethod وعرفت طريقة استخدامها، وضبط معي الكود B)

وهذا هو الكود للفائدة:

#include <iostream>
using namespace std;

int main()
{
	char word1[] = {'s', 'm', 'i', 'l', 'e'};
	char word2[] = {'_', '_', '_', '_', '_'};
	int size = 5;
	char letter;
	int counter = 3;

	cout << "*******Welcome to the mystrey word game*******";
	cout << "\n\nyou have 3 attempts to gess the word!";

	for(int i=0; i<size; i++)
	{
		cout<<word2<<" ";
	}

	cout << "\nEnter a letter:";
	cin >> letter;
	cout << "\n\n";

	while(counter > 0)
	{
		for(int i=0; i<size; i++)
		{	
			if (letter == word1)
			{
				cout << "\n:)";
				word2=letter;
				counter+=1;
				for(int i=0; i<size; i++)
				{
					cout<<word2<<" ";
				}
			}
		}
		counter-=1;


		if (counter == 0)
		{
			cout << "\n\nyou have no more attempts";
			cout << "\ntry again later;)\n";
			break;
		}

		if (strcmp(word1, word2) == 0){
			cout <<"\n\n*****Good job, you won the game!*****\n";
			break;}

		cout << "\n" << counter << " attempts left to gess the word!";
		cout << "\ntray another letter:";
		cin >> letter;
		cout << "\n\n";

	}

	return 0;
}

برايفت بنات كلاسي:ياويل اللي تسرق كودي :wink:

#9

إدخل على اللينك حتﻻقى شرح وافى ليها :), و أنا قصدى تستخدمها فى ال condition بتاع ال while فى حالة إنه وجد إن ال word1 & word2 متساويين ميدخلش فى اللوب.

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

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