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

مساعده في لعبه tron

بدأه empror9 في 27 أغسطس 2010 · 2 رد · 410 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اتمنى انكم بصحه وعافيه ، عندي واجب في لغه السي بلس بلس وهو عباره عن لعبه tron لو تعرفوها

هذه اللعبه مثل شبيهه بلعبه الثعبان الموجود في الموبايلات القديمه ، في هذه اللعبه يكون هناك لاعبان (( الاعب الاول والاعب الثاني ))

اول ماتبدا اللعبه يكون لكل واحد مساره الخاص ولابد ان لا يصتدم بالاعب الثاني وايضا لا يصتدم بالجدار حتى لايخسر ، ويجب عليه ان يورط اللاعب الاخر كي يتصدم به حتى يخسر اللعبه وهكذا

هذا موقع يوجد به مثال

http://www.classicgamesarcade.com/game/21670/Tron-Game.html

وهنا مثال لنفس اللعبه المراد برمجتها وبلغه السي بلس بلس

http://www.mediafire.com/?bqc38cct3089y7n

انا عندي الداله الي تقوم بالتحرك تلقائيا ويجب فقط على المستخدم الاتجاه يمينا او شمالا او للاعلى او للاسفل (( على اعتبار انكم رايتم الامثله ))

هذه الداله

/* Demo Program: testkeys.cpp
*/
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

const int NO_OF_COLS = 80;
const int NO_OF_ROWS = 50;
char tile[NO_OF_COLS][NO_OF_ROWS];

void testKeys(void)
{
    unsigned char ch,ch2;

    do
    {
        cout << "."; Sleep(200);    /* continuously print a dot */
        if (kbhit()) //important    /* if there is char in keyboard buffer ... */
        {
            ch=getch();   /* read the key from the buffer */
            if (ch==0)
            {
                ch2 = getch(); /* read another char to determine the special key */
                cout << " [0 -> " << (int)ch2 << "]";
                switch (ch2)
                {
                case 71: cout << "=<Home>"; break;
                case 72: cout << "=<Up>"; break;
                case 73: cout << "=<PgUp>"; break;
                case 75: cout << "=<Left>"; break;
                case 77: cout << "=<Right>"; break;
                case 79: cout <<"=<End>"; break;
                case 80: cout <<"=<Down>"; break;
                case 81: cout <<"=<PgDn>"; break;
                case 82: cout <<"=<Ins>"; break;
                case 83: cout <<"=<Del>"; break;
                case 133: cout <<"=<F11>"; break;
                case 134: cout <<"=<F12>"; break;
                case 59: case 60: case 61: case 62: case 63:
                case 64: case 65: case 66: case 67: case 68:
                    cout << "=<F" << ch2-58 << ">"; break;
                }
            }
            else if (ch==224) /* if the char has value 224, it means it is special key */
            {
                ch2 = getch(); /* read another char to determine the special key */
                cout << " [224 -> " << (int)ch2 << "]";
                switch (ch2)
                {
                case 71: cout << "=<Home>";  break;
                case 72: cout << "=<Up>";    break;
                case 73: cout << "=<PgUp>";  break;
                case 75: cout << "=<Left>";  break;
                case 77: cout << "=<Right>"; break;
                case 79: cout << "=<End>";   break;
                case 80: cout << "=<Down>";  break;
                case 81: cout << "=<PgDn>";  break;
                case 82: cout << "=<Ins>";   break;
                case 83: cout << "=<Del>";   break;
                case 133: cout << "=<F11>";  break;
                case 134: cout << "=<F12>";  break;
                case 59: case 60: case 61: case 62: case 63:
                case 64: case 65: case 66: case 67: case 68:
                    cout << "=<F" << ch2-58 << ">"; break;
                }
            }
            else
            {
                switch (ch)
                {
                case  8:
                    cout << " [<Backspace> " << ch << "]";
                    break;
                case  9:
                    cout << " [<Tab> " << ch << "]";
                    break;
                case 13:
                    cout << " [<Enter> " << ch << "]";
                    break;
                case 27:
                    cout << " [<ESC> " << ch << "]";
                    break;
                case 32:
                    cout << " [<space> " << ch << "]";
                    break;
                default:
                    cout << " [" << ch << " " << (int)ch << "]";
                }
            }
        }
    }
    while (ch!=27);   /* ESC key has value 27, use ESC to exit */
}

وهذه الداله للالوان

/* Demo Program: colortext.cpp
*/
#include "colortext.hpp"
#include <iostream>
#include <conio.h>
#include <windows.h>
static int __BACKGROUND = BLACK;
static int __FOREGROUND = LIGHTGRAY;

void setcolor(int backgroundcolor, int foregroundcolor)
{
   textbackground(backgroundcolor);
   textcolor(foregroundcolor);
}

void _setcursortype (int type)
{
   CONSOLE_CURSOR_INFO Info;

   Info.bVisible = type;

   SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
   &Info);
}

void hidecursor()
{
   _setcursortype(FALSE); /* temporary hide the cursor */
}

void showcursor()
{
   _setcursortype(TRUE);
}

void gotoxy(int x, int y)
{
    COORD c;

    c.X = x - 1;
    c.Y = y - 1;
    SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}

// the second sets output attributes (weight, color, ...)
// play with this functions to understand how it works
void textattr (int _attr)
{
   SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
}

void textbackground (int color)
{
   __BACKGROUND = color;
   SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
   __FOREGROUND + (color << 4));
}

void textcolor (int color)
{
   __FOREGROUND = color;
   SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
   color + (__BACKGROUND << 4));
}

void clrscr()
{
   DWORD written;

   FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
   __FOREGROUND + (__BACKGROUND << 4), 2000, (COORD) {0, 0},
   &written);
   FillConsoleOutputCharacter (GetStdHandle
   (STD_OUTPUT_HANDLE), ' ',
   2000, (COORD) {0, 0}, &written);
   gotoxy (1, 1);
}

void clreol()
{
   COORD coord;
   DWORD written;
   CONSOLE_SCREEN_BUFFER_INFO info;

   GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
   &info);
   coord.X = info.dwCursorPosition.X;
   coord.Y = info.dwCursorPosition.Y;

   FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
   ' ', info.dwSize.X - info.dwCursorPosition.X, coord, &written);
   gotoxy (coord.X, coord.Y);
}

void delline()
{
   COORD coord;
   DWORD written;
   CONSOLE_SCREEN_BUFFER_INFO info;

   GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
   &info);
   coord.X = info.dwCursorPosition.X;
   coord.Y = info.dwCursorPosition.Y;

   FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
   ' ', info.dwSize.X * info.dwCursorPosition.Y, coord, &written);
   gotoxy (info.dwCursorPosition.X + 1, info.dwCursorPosition.Y + 1);
}

وهذه الداله الرئيسيه للعبه

#include <cstdlib>
#include <iostream>
#include <cctype>
#include <conio.h>
#include <windows.h>
#include "colortext.hpp"
#include "testkeys.cpp"

using namespace std;

int main()
{
	system("MODE CON: COLS=80 LINES=25");
	const int screenWidth = 50;
	const int screenHeight = 20;
	const int tableWidth = screenWidth + 2;
	const int tableHeight = screenHeight + 2;

	int table[tableWidth][tableHeight];
	for(int i = 0; i < tableWidth; ++i)
	{
		for(int j = 0; j < tableHeight; ++j)
			table[j] = 0;
	}

	int x = 25;
	int y = 10;
	gotoxy(25,10);
	setcolor(GREEN,WHITE);
	cout <<'B';

	//update the table
	table[x][y] = 1;

	while (true)
	{ //check for the keyboard
		if(kbhit())
		{
			unsigned char input = getch();

			if(toupper(input) == 'W')
				y--;
			else if(toupper(input) == 'A')
				x--;
			else if(toupper(input) == 'S')
				x++;
			else if(toupper(input) == 'Z')
				y++;		


		// check 
		if(table[x][y] == 1)
		{
			//show the collidion or make some noise
			Beep(262,1000); // make sound for 1 second (1000 mill)
			break;
		}
		else
		{

		gotoxy(x,y);
		setcolor(GREEN,WHITE);
		cout <<'B';

		table[x][y] = 1;
			}
		}
	}


	cout <<"escape from loop" <<endl;
	/*
	// clear the screen whith background
	setcolor(CYAN,DARKGRAY);
	system("cls");

	gotoxy(25,10);
	setcolor(GREEN,WHITE); // Green background and white foregroundcolor

	cout <<"hello";
	setcolor(BLACK,YELLOW);

	getch();
	*/
		testKeys();
	getch();
	return 0;	
}

مشكلتي انني لم استطع دمج الداله الاولى (( الحركه التلقائيه )) مع البرنامج الرئيسي وستلاحظون ذلك في اخر خمسه اسطر في البرنامج الرئيسي ولم افلح

ياريت المساعده واذا فيه اي اضافات ياريت لاتبخلون

ملاحظه هامه\ انا مازلت مبتدا في البرمجه ورجاءا مراعاه ذلك

تحياتي،،

#2

للرفع

#3

ياساتر مافي ولا مساعده وحده

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