步步高游戏 - 我需要帮助请:) [英] Backgammon game - I need help please :)

查看:73
本文介绍了步步高游戏 - 我需要帮助请:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试制作一个步步高游戏,我的老师让我在我的项目中做了一些事情,我真的不知道该怎么做,有人可以帮我吗?

我正在尝试这样做而且它不适合我,请有人可以帮助我吗?



我的老师说有一个地方我们写信要检查如果他被允许移动

然后编写一个检查可以移动的函数:并且返回可以或不可以。一旦找到一个可以移动的地方,那么你将返回真相,应该不要继续检查

如果那里有一个玩家,那么检查每个立方体是否允许将它放在它所带来的位置。

如果它的所有零件都是代替结束(然后可以拉出)然后检查可以移动(因为合法性有一点不同)

如果那里没有球员,那么任何有球员的地方检查每个立方体是否可以移动





我的C#代码

Hey, I am trying to make a backgammon game, My teacher asked me to do somestuff in my project and i dont really know how to do it, Can someone help me with that please?
I am trying to do it and its not working for me, Please can someone help me with that?

My Teacher Says "There is a place where we wrote to check if he was allowed to move
Then write a function that checks the can move at all: and returns can or can not. Once you find one place that can move, then you will return the truth and should not continue to check
If there is a player out there, then check for each cube if allowed to put it in place that it brings it.
If all its parts are in place of the end (and then can pull out) then check that can move (because the legality there is a little different)
If there is no player out there, then for any place that has players check for each cube if you can move"


My C# Code

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 [ ^ ]

推荐答案

只是将您的整个代码转储给我们并说它不起作用并不能为您提供解决方案:我们不做您的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



亲自尝试,你可能会发现它不是和你想的一样困难!



如果遇到具体问题,请询问相关问题,我们会尽力提供帮助。但我们不打算为你做这一切!
Just dumping your whole code on us and saying "it doesn't work" isn't going to get you a solution: We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


这篇关于步步高游戏 - 我需要帮助请:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆