Игра в нарды - мне нужна помощь, пожалуйста :)
Эй, я пытаюсь сделать игру в нарды, мой учитель попросил меня сделать что-то в моем проекте, и я действительно не знаю, как это сделать, может ли кто-нибудь помочь мне с этим, пожалуйста?
Я пытаюсь это сделать, и это не работает для меня, пожалуйста, может ли кто-нибудь помочь мне в этом?
Мой учитель говорит: "Есть место, куда мы писали, чтобы проверить, разрешили ли ему переехать
Затем напишите функцию, которая проверяет, можно ли вообще двигаться: и возвращает can или can not. Как только вы найдете одно место, которое может двигаться, тогда вы вернете истину и не должны продолжать проверять
Если там есть игрок, то проверьте для каждого куба, если ему разрешено поставить его на место, что он приносит его.
Если все его части находятся на месте конца (а потом можно вытащить), то проверьте, что можно сдвинуть (потому что законность там немного другая)
Если там нет игрока, то для любого места, где есть игроки, проверьте каждый куб, если вы можете двигаться"
Мой Код C#
using System; namespace ConsoleApp43 { class Program { static string playerName1, playerName2; static int whatToMove; static int countToMove; static int turn; static int[] bord = new int[26]; // מערך בשביל הלוח static int[] dice = new int[4]; // מערך בשביל הקוביות static Random rnd = new Random(); // בשביל מספרים אקראיים בשביל הקוביות static int outRed; // משתנה עבור כמה אדומים בחוץ static int outBlue; // משתנה עבור כמה כחולים בחוץ static void PrintPlayers() // מדפיס על הלוח את מיקום השחקנים { ///משתנה עזר לקפוץ מעל 99 int jump = 0; /// לולאה עבור כתיבת השחקנים for (int i = 0; i < 13; i++) { // מדפיס את השורה העליונה Console.SetCursorPosition(i * 5 + jump + 3, 2); if (bord[i] != 0) { if (bord[i] > 0) Console.ForegroundColor = ConsoleColor.Blue; else Console.ForegroundColor = ConsoleColor.Red; Console.Write(Math.Abs(bord[i]) + " "); } // מדפיס את השורה התחתונה Console.SetCursorPosition(i * 5 + jump + 3, 12); if (bord[25 - i] != 0) { if (bord[25 - i] > 0) Console.ForegroundColor = ConsoleColor.Blue; else Console.ForegroundColor = ConsoleColor.Red; Console.Write(Math.Abs(bord[25 - i]) + " "); } if (i == 6) // קפיצה על המקום האמצעי jump = 5; } if (outBlue > 0) // מדפיס כמה כחולים בחוץ אם יש { Console.ForegroundColor = ConsoleColor.Blue; Console.SetCursorPosition(38, 2); Console.Write(outBlue); } if (outRed > 0) // מדפיס כמה אדומים בחוץ אם יש { Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition(38, 12); Console.Write(outRed); } Console.ForegroundColor = ConsoleColor.White; // מחזיר את הצבע ללבן } public static void PrintScreen() // מדפיס את המסגרת ודברים שלא משתנים כלל { /// שורה ראשונה של מינוסים Console.SetCursorPosition(1, 1); for (int i = 1; i <= 71; i++) Console.Write("═"); // שורה אחרונה של מינוסים Console.SetCursorPosition(1, 13); for (int i = 1; i <= 71; i++) Console.Write("═"); ///מדפיס 5 עמודות של קוים עומדים for (int i = 2; i <= 12; i++) { Console.SetCursorPosition(1, i); Console.Write("║"); Console.SetCursorPosition(6, i); Console.Write("║"); Console.SetCursorPosition(36, i); Console.Write("║"); Console.SetCursorPosition(41, i); Console.Write("║"); Console.SetCursorPosition(71, i); Console.Write("║"); } /// מדפיס קוים עומדים להפריד בין המספרים for (int i = 0; i < 14; i++) { Console.SetCursorPosition(1 + i * 5, 2); Console.Write("║"); Console.SetCursorPosition(1 + i * 5, 12); Console.Write("║"); } /// מדפיס את המספרים int jump = 0; for (int i = 1; i < 13; i++) { // מדפיס שורה עליונה Console.SetCursorPosition(jump + 3 + i * 5, 0); Console.Write(i); // מדפיס שורה תחתונה Console.SetCursorPosition(jump + 3 + i * 5, 14); Console.Write(25 - i); if (i == 6) jump = 5; } // מדפיס את ה99 Console.SetCursorPosition(38, 0); Console.Write(99); Console.SetCursorPosition(38, 14); Console.Write(99); } static void PrintDice(int x, int y, int dice) // מדפיס קוביה לפי מיקום שנותנים לו וערך הקוביה { Console.SetCursorPosition(x, y); Console.Write("╔═══╗"); Console.SetCursorPosition(x, y + 1); Console.Write("║"); Console.SetCursorPosition(x + 2, y + 1); Console.Write(dice); Console.SetCursorPosition(x + 4, y + 1); Console.Write("║"); Console.SetCursorPosition(x, y + 2); Console.Write("╚═══╝"); } static void DeleteDice() /// מוחק את הקוביה { for (int i = 0; i < 3; i++) { Console.SetCursorPosition(14, 6 + i); Console.Write(" "); Console.SetCursorPosition(49, 6 + i); Console.Write(" "); } } /// מגריל ערך לקוביות ומכניס את הערך למערך ומדפיס את הקוביות public static void PrintDice() { dice[0] = rnd.Next(1, 7); dice[1] = rnd.Next(1, 7); // קודם למחוק את הקוביות הקודמות DeleteDice(); /// בודק אם יש דאבל ואם יש זה מדפיס ארבע קוביות if (dice[0] == dice[1]) { ///קוביה מספר 1 PrintDice(14, 6, dice[0]); ///קוביה מספר 2 PrintDice(24, 6, dice[0]); ///קוביה מספר 3 PrintDice(49, 6, dice[0]); ///קוביה מספר 4 PrintDice(59, 6, dice[0]); dice[2] = dice[0]; dice[3] = dice[0]; } /// אם אין דאבל זה מדפיס שתי קוביות else { ///קוביה מספר 1 PrintDice(17, 6, dice[0]); ///קוביה מספר 2 PrintDice(55, 6, dice[1]); dice[2] = 0; dice[3] = 0; } } // roie // לבנות פונקציה שבודקת אם בכלל יכול לזוז // roie // צריך להוסיף בדיקות האם לא יצאנו מהלוח // לבדוק אם מותר להוציא חלקים // לבדוק אם בחר אפס public static bool checkDice(int countToMove, bool toPrint = false) { for (int i = 0; i < dice.Length; i++) if (dice[i] == countToMove) { int whereToMove = bord[whatToMove + (countToMove * turn)]; if (whereToMove == 0 || whereToMove == Math.Abs(whereToMove) * turn || whereToMove == turn * -1) return true; else { if (toPrint == true) Console.WriteLine("You cannot move there"); return false; } } if (toPrint == true) Console.WriteLine("No dice like that"); return false; } public static bool checkMove(int whatToMove) { if (whatToMove == 99) { if (turn == 1 && outBlue > 0) return true; else { if (turn == -1 && outRed > 0) return true; else return false; } } if (turn == 1 && bord[whatToMove] > 0) return true; else if (turn == -1 && bord[whatToMove] < 0) return true; return false; } // פונקציה שמדפיסה את התור של השחקן public static void PrintPlayerTurn() { if (turn == 1) { Console.SetCursorPosition(0, 15); Console.WriteLine("Its your turn: " + playerName1); } else { Console.WriteLine("Its your turn: " + playerName2); } } // roie public static void MoveMe(int whatToMove, int countToMove) { } static void Main(string[] args) // פונקציה ראשית - תחילת התכנית { //Console.WriteLine("Please enter first player name"); //playerName1 = Console.ReadLine(); playerName1 = "Roie"; // Console.WriteLine("Please enter second player name"); // playerName2 = Console.ReadLine(); playerName2 = "Avichay"; // איתחול הלוח למצב ראשוני for (int i = 0; i < 26; i++) bord[i] = 0; bord[1] = 2; bord[12] = 5; bord[17] = 3; bord[19] = 5; bord[24] = -2; bord[13] = -5; bord[8] = -3; bord[6] = -5; outBlue = 0; outRed = 0; turn = 1; PrintScreen(); // נדפיס רק פעם אחת //while () // { PrintPlayers(); // זה יהיה בתוך לולאה של המשחק PrintDice(); // מדפיס את הקוביות PrintPlayerTurn(); // להדפיס תור מי עכשיו Console.SetCursorPosition(0, 16); do { Console.Write("What do you want to move? "); try { whatToMove = int.Parse(Console.ReadLine()); } catch (Exception e) { whatToMove = 0; } } while (((whatToMove > 0 && whatToMove < 26) || whatToMove == 99) && checkMove(whatToMove) == false); do { Console.Write("how much do you want to move? "); // roie // לעשות בדיקה שלא הכניס אותיות בטעות countToMove = int.Parse(Console.ReadLine()); } while (checkDice(countToMove, true) == false); //} Console.SetCursorPosition(0, 20); // להחזיר את הסמן לסוף הלוח } } }
Что я уже пробовал:
Я пытался сделать это, и это не сработало для меня...
Проект выглядит именно так прямо сейчас :
Скриншот 1 — imgbb.com[^]