Ticker

6/recent/ticker-posts

Easy Tutorial for making a Ludo Game using C# Windows Form Application

When I was in my first year of software engineering, I made a Ludo game using the C# Windows Form App. When it was being started, I realized that it will be tough to make a perfectly running Ludo Game in two months with only one more group member who can help. My respected teacher gave me only one hint that you can use "Arrays" to save the path and then we started. In the end, it was not so good but running fine and we got good Data Structures and OOP skills for a project and very good grades.

Here I will discuss all the important problems of this game and also guide you to make a Ludo game from basic knowledge and even if you are new to programming. The platform and other things which we used in this project are written below:

  • Microsoft Visual Studio(I prefer 2010 or above for this)
  • Some knowledge and practice on C# and Windows Form App
  • You must have met with "Mr. Arrays" including 2-D Arrays.
Making a game in Visual Studio for your student project seems a tough job but it becomes easy if you are motivated to work and code. I spent almost three months making this project because I started from the very start of the semester when the professor announced that he will be expecting a project for the Object Oriented Programming Course. We decided quickly that we will be making a Ludo game despite the Professor and Lab Engineer warning us that it will be very difficult to complete a full game in one semester. So, I started development and asked my group member to get me the X-Y coordinates of each box. He calculated them and saved them in arrays like this. 

       class dice

    {

        //these arrays will be used to store x and y axis of blocks in Ludo Game

        public int[] rx_axis = new int[57]; //rx_axis array means x-axis path of Red token

        public int[] ry_axis = new int[57]; //ry_axis array means y-axis path of Red token

        public int[] yx_axis = new int[57]; //yx_axis array means x-axis path of Yellow token

        public int[] yy_axis = new int[57]; //yy_axis array means y-axis path of Yellow token

        public int[] bx_axis = new int[57]; //bx_axis array means x-axis path of Blue token

        public int[] by_axis = new int[57]; //by_axis array means y-axis path of Blue token

        public int[] gx_axis = new int[57]; //gx_axis array means x-axis path of Green token

        public int[] gy_axis = new int[57]; //gy_axis array means y-axis path of Green token

        }

After initializing arrays, I put the x-y axis values of all blocks that my group member found. I did that like this. Please remember that these two pictures of code are for the x-axis and y-axis path of Red Tokens, we will need to do the same as this for X and Y axis of all tokens.




Now, coming to the UI part, It was a simple form with a Ludo board background image and a few buttons like Register Player, that are used to register a name and some text boxes to enter names and labels to show those names. It also has buttons as tokens that will move around using the path we just saved using 2-D Arrays. The UI of that form can be seen in first picture in this blog.

The Ludo UI has a Register Player button for each player and a textbox is show to enter his/her name. The picture and code to do that is given below:


private void rgister_blue_Click(object sender, EventArgs e)

        {

            if (cntb == 0) // zero means not registered yet

            {

                textBox1.Visible = true;

                textBox1.Location = new Point(463, 102);

                textBox1.Text = "Enter Name".ToString();

                textBox1.Select();

                rgister_blue.Text = "OK".ToString();

                 cntb = 1;

            }

           else if(cntb ==1)

            {

                textBox1.Visible = false;

                label2.Text = textBox1.Text;

                rgister_blue.Enabled = false;

                blue1.Visible = true;

                blue2.Visible = true;

                blue3.Visible = true;

                blue4.Visible = true;

                button1.Enabled = true;

                cntb = 2;

             

            }           

        }







To be continued... (Last edited: January 31, 2023) Comment below if you are having any problems.


Post a Comment

1 Comments

  1. Could you post the rest of the code for the Ludo game

    ReplyDelete