Friday 29 May 2020

Create a simple game using c# in 20 minutes

Hello readers…,

I am here with a new article. In this post lets learn how to create a simple game in visual studio using c#.

First lets talk about c#. There are many programming languages in the trending technology and in the latest technology there is a huge demand for c#.
C# is the language in the .net framework where you can build all types of applications what not everything like windows, web, mobile applications. Learning this language and coding in the language is the best option for your future carrier.

In this post lets learn how to create a game for Windows using C#.

Lets enter in to the topic.


 1. Selecting new project.

For this all we have to do is open visual studio in your pc and then click on new then select new project. Then enter a name for your project as car racing then click on ok.

2. Designing for application 

Before coding the game, we have to create a design for our game. So, lets design our game.
Design the game as shown in the picture below.

For more details and explanation checkout the video from my channel in YouTube. by clicking the below link.

 https://youtu.be/XgzDnU3j-5Q

Hit a like for the video and subscribe to my channel on YouTube.

Coding the program

Now its time to code for our project.
Code your game as the same code below.
Code for game…

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace car_racing
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = true;
            over.Visible = false;
            close.Visible = false;
            restart.Visible = false;
         
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            moveline(gamespeed);
            enemy(gamespeed);
            gameover();

        }
        int gamespeed = 0;

        void moveline(int speed)                          // to move lines on the road//
        {
            if (pictureBox1.Top >= 500)
            {
                pictureBox1.Top = 0;
            }
            else
            {
                pictureBox1.Top += speed;
            }
            if (pictureBox2.Top >= 500)
            {
                pictureBox2.Top = 0;
            }
            else
            {
                pictureBox2.Top += speed;
            }
            if (pictureBox3.Top >= 500)
            {
                pictureBox3.Top = 0;
            }
            else
            {
                pictureBox3.Top += speed;
            }
            if (pictureBox4.Top >= 500)
            {
                pictureBox4.Top = 0;
            }
            else
            {
                pictureBox4.Top += speed;
            }
            if (pictureBox5.Top >= 500)
            {
                pictureBox5.Top = 0;
            }
            else
            {
                pictureBox5.Top += speed;
            }
            if (pictureBox6.Top >= 500)
            {
                pictureBox6.Top = 0;
            }
            else
            {
                pictureBox6.Top += speed;
            }
            if (pictureBox7.Top >= 500)
            {
                pictureBox7.Top = 0;
            }
            else
            {
                pictureBox7.Top += speed;
            }
            if (pictureBox8.Top >= 500)
            {
                pictureBox8.Top = 0;
            }
            else
            {
                pictureBox8.Top += speed;
            }
            if (pictureBox9.Top >= 500)
            {
                pictureBox9.Top = 0;
            }
            else
            {
                pictureBox9.Top += speed;
            }
            if (pictureBox10.Top >= 500)
            {
                pictureBox10.Top = 0;
            }
            else
            {
                pictureBox10.Top += speed;
            }
            if (pictureBox11.Top >= 500)
            {
                pictureBox11.Top = 0;
            }
            else
            {
                pictureBox11.Top += speed;
            }
            if (pictureBox12.Top >= 500)
            {
                pictureBox12.Top = 0;
            }
            else
            {
                pictureBox12.Top += speed;
            }
        }
        Random r = new Random();
        int a, b;
        void enemy(int speed)
        {
            if (enemy1.Top >= 500)
            {
                a = r.Next(0, 100);
                enemy1.Location = new Point(a, 0);
            }
            else
            {
                enemy1.Top += speed;
            }
            if (enemy2.Top >= 500)
            {
                a = r.Next(0, 250);
                enemy2.Location = new Point(a, 0);
            }
            else
            {
                enemy2.Top += speed;
            }
            if (enemy3.Top >= 500)
            {
                a = r.Next(0, 150);
                enemy3.Location = new Point(a, 0);
            }
            else
            {
                enemy3.Top += speed;
            }
            if (enemy4.Top >= 500)
            {
                a = r.Next(0, 350);
                enemy4.Location = new Point(a, 0);
            }
            else
            {
                enemy4.Top += speed;
            }

        }
        void gameover()
        {
            if (car.Bounds.IntersectsWith(enemy1.Bounds))
            {
                timer1.Enabled = false;
                over.Visible = true;
                close.Visible = true;
                restart.Visible = true;
            }
            if (car.Bounds.IntersectsWith(enemy2.Bounds))
            {
                timer1.Enabled = false;
                over.Visible = true;
                close.Visible = true;
                restart.Visible = true;
            }
            if (car.Bounds.IntersectsWith(enemy3.Bounds))
            {
                timer1.Enabled = false;
                over.Visible = true;
                close.Visible = true;
                restart.Visible = true;
            }
            if (car.Bounds.IntersectsWith(enemy4.Bounds))
            {
                timer1.Enabled = false;
                over.Visible = true;
                close.Visible = true;
                restart.Visible = true;
            }
        }


        private void close_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void restart_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }
//To control the car. //

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                if (car.Left > 0)
                    car.Left += -8;

            }
            if (e.KeyCode == Keys.Right)
            {
                if (car.Right < 350)
                    car.Left += 8;
            }
            if (e.KeyCode == Keys.Up)
            {
                if (gamespeed < 20)
                    gamespeed++;
            }
            if (e.KeyCode == Keys.Down)
            {
                if (gamespeed > 0)
                    gamespeed--;
            }

        }
    }
}

That’s all for code then run the program using ctrl+F5.
Checkout the video from youtube for more complete procedure and steps to right the code.
Subscribe my youtube channel for more interesting videos and hit a like for the video share to your friends as they can also learn programming.
Hope you enjoyed creating the game.
Like the post and subcribe for more interesting posts..

Thank you
Your s
vinay 

Friday 22 May 2020

Interesting useful websites

Hello   Readers….,

I am here with Some Cool Websites that you must visit when you feel Bored….
All of us are very interested to visit websites whenever necessary. It may be for the sake of our personal work, business, company work, etc.… some of us are interested to visit websites whenever we are free or in leisure period. To spend their leisure time by visiting the sites is the hobby of some people.
But…,
Finding those websites, I mean people who wants to complete their work that may be their personal, business, or company are wants to visit some sites. So, finding those websites may be time taking process or Risk… and people who want to spend their leisure time on websites are also wants to find some websites.
This article will help those both the persons to know the website that will help them...
I hope that this article will be liked by you….

There are many websites in the internet that make our time passed easily when we feel bored. In this page I want to tell a few websites that every internet user should visit.
As we search in the internet we can find many websites of different uses and different types. But actually we don`t like all the sites, right.!  We choose only some of them for our use and we may like only them.
So. Without late let us move to our topic…
The first site that you should visit is

1. Boredpanda.com

This is the site that you should visit when you feel bored. This site contains of much information based on categories.
We can find wide collection of topics like Science, Art, Technology, Social life, photography, etc... this site is the most helpful site to collect the data of our choice by choosing the categories.
   Visit the site to improve your knowledge...

LET’S MOVE TO SECOND SITE AND THAT IS…

2.THIS IS MY WEBSITE.COM

This is my website is the best site to visit when we feel too bored…
In the site we can play different types of games that are provided in the site… and in this site you can take decisions as it is a type of game in the website. As if you are religious then you can also find the holy book Bible and etc.… to empower your religious knowledge in the religious side.
 You can pass your time by playing games in the site... as there are many games in the site like MAZE MINE, DEFEND, FAST TAP, RANDAM TOP, DECISION MAKER, etc.… there are many more games like this. Just tap them to play the games and enjoy…
     Visit this site to play games and make decisions…

Let’s move to our third website….


 3.CROSSFADE.IO
Crossfade.io is the site to visit to listen to the two music at once…
         This is the best site for Music lovers. When you see two music videos at two    different platforms then to listen the both at a time just copy both the links and paste them in the site. This site will create a playlist for you and you can listen the both at a time.
 We can enjoy through this site by listen to our favorite music….
    Visit this site to enjoy the two different music videos at a time…

Your s Vinay

META the new name for Facebook

 The largest social media Facebook.  Everyone has a account in fb. As there are many news spreading in the title change of Facebook. Everyo...