Create a typing game in Visual Studio with C#

This is full code for the typing game in C#.

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 typing_game
{
    public partial class Form1 : Form
    {
        //create on MooIct.com
        // full code on C# tutorial
        string[] words = {"mooict", "cat", "dog", "monkey", "tiger", "panda", "lion", "zebra"}; //store the words in here
        int num = 0; //num which will be used to go through the array
        int wordI; // going to be used for conditional checks
        
        public Form1()
        {
            InitializeComponent();
            txt.Text = words[2]; //this will return mooict. the word on 0 index of the array
            label2.Text = "" + words.Length; //this will show how many words there are in the array
            wordI = words.Length; // store the number of words in the array
        }

        private void playGame(object sender, EventArgs e)
        {
            //this function is linked to the text change event on the text box
            //each time the letters change in the text this function will run
            if(txt.Text == textBox1.Text)
            {
                    win();
                //when the condition is met this function will run
            }
        }

        public void win()
        {
            if (num < wordI - 1)
            {
                num++;
                txt.Text = words[num];
                textBox1.Text = "";
            //while the number is less tham total words game will continue
            //it will continue to increase the number thus changing the words
            }
            else
            {
                num = 0;
                txt.Text = words[num];
                textBox1.Text = "";
            //otherwise it will reset number to 0
            //start the game from beginning
            }

        }
    }
}


 




Comments are closed.