Example #1
0
//----------------------------------------CREATING THE BOARD------------------------------------------\\

        // initialises the board by adding the array of buttons
        void initBoard()
        {
            Random r = new Random();

            // nested for loop that initialises an array of buttons
            for (int x = 0; x < btn.GetLength(0); x++)
            {
                for (int y = 0; y < btn.GetLength(1); y++)
                {
                    // creates new button object
                    btn[x, y] = new Button();
                    // sets dimentions and position of buttons
                    btn[x, y].SetBounds(60 * x, (60 * y) + 25, 60, 60);
                    btn[x, y].FlatStyle = FlatStyle.Flat;
                    btn[x, y].FlatAppearance.BorderColor = Color.FromArgb(17, 47, 65);
                    // generates a random number between 0 and 3
                    int colorNum = r.Next(4);
                    if (colorNum == 0)
                    {
                        // changes colour of button to red
                        btn[x, y].BackColor = Color.Red;
                    }
                    else if (colorNum == 1)
                    {
                        // changes colour of button to blue
                        btn[x, y].BackColor = Color.Blue;
                    }
                    else if (colorNum == 2)
                    {
                        // changes colour of button to green
                        btn[x, y].BackColor = Color.Green;
                    }
                    else if (colorNum == 3)
                    {
                        // changes colour of button to yellow
                        btn[x, y].BackColor = Color.Yellow;
                    }



                    //creates button click event handler
                    btn[x, y].Click += new EventHandler(this.btnEvent_Click);
                    // adds buttons to gui
                    Controls.Add(btn[x, y]);
                    multiLbl.Hide();
                    timeLbl.Hide();
                    scoreLabel.Hide();
                    plus2Lbl.Hide();
                    turnLbl.Hide();
                    CountdownLbl.Hide();
                    boardHomeBtn.Hide();
                    TitleLbl.Hide();
                    P1ScoreLbl.Hide();
                    P2ScoreLbl.Hide();
                }
            }
        }
Example #2
0
        //event handler for a second elapsing
        void timer_Tick(object sender, ElapsedEventArgs e)
        {
            //if time has run out
            if (tempTime <= 0)
            {
                tempTime = -1;
                CountdownLbl.Invoke(new Action(() => CountdownLbl.Hide()));
                timeCounter--;
            }
            else
            {
                //reduces time
                tempTime--;

                CountdownLbl.Invoke(new Action(() => CountdownLbl.Text = Convert.ToString(tempTime)));
            }

            if (timeCounter > 0)
            {
                // displays the time lable
                timeLbl.Invoke(new Action(() => timeLbl.Text = "Time: " + Convert.ToString(timeCounter)));
            }
            else
            {
                // displays time up
                timeLbl.Invoke(new Action(() => timeLbl.Text = "Times up!"));
            }
            //end game
            if (timeCounter == 0)
            {
                //  System.Windows.Forms.MessageBox.Show("GAME OVER\nyou scored: " + Convert.ToString(score));
                aTimer.Stop();
                timeCounter = -1;
                ticking     = false;

                btnClickTimeTrial(btn[1, 1], e);
            }
            //hides label
            if (timeCounter <= prevTime)
            {
                plus2Lbl.Invoke(new Action(() => plus2Lbl.Hide()));
            }
            // starts countdown sound
            if (timeCounter == 10)
            {
                System.Media.SoundPlayer player = new System.Media.SoundPlayer(@"timer.wav");
                player.Play();
            }
        }
Example #3
0
        //shows the main menu
        void showMenu()
        {
            ClassicBtn.Invoke(new Action(() => ClassicBtn.Show()));
            ExitBtn.Invoke(new Action(() => ExitBtn.Show()));
            HelpBtn.Invoke(new Action(() => HelpBtn.Show()));
            multiplayerBtn.Invoke(new Action(() => multiplayerBtn.Show()));
            TimeBtn.Invoke(new Action(() => TimeBtn.Show()));
            menuBack.Invoke(new Action(() => menuBack.Show()));
            HomeTLbl.Invoke(new Action(() => HomeTLbl.Show()));
            boardHomeBtn.Invoke(new Action(() => boardHomeBtn.Hide()));
            CountdownLbl.Invoke(new Action(() => CountdownLbl.Hide()));
            TitleLbl.Invoke(new Action(() => TitleLbl.Hide()));

            if (gameMode == 2)
            {
                P1ScoreLbl.Invoke(new Action(() => P1ScoreLbl.Hide()));
                P2ScoreLbl.Invoke(new Action(() => P2ScoreLbl.Hide()));
                turnLbl.Invoke(new Action(() => turnLbl.Hide()));
            }
        }
Example #4
0
        // initialises multi player game mode
        void multiplayerInit()
        {
            //stops the timer if one is running
            if (ticking)
            {
                aTimer.Stop();
                ticking = false;
            }
            //picks random player to start
            Random r    = new Random();
            int    turn = r.Next(2);

            scoreP1 = 0;
            scoreP2 = 0;
            // sets up lables
            P1ScoreLbl.Text = "P1 SCORE: " + scoreP1;
            P2ScoreLbl.Text = "P2 SCORE: " + scoreP2;
            // works out whos turn it is
            if (turn % 2 == 1)
            {
                turnLbl.Text = "Player 1's turn";
            }
            else
            {
                turnLbl.Text = "Player 2's turn";
            }
            // sets up menu
            gameMode = 2;
            multiLbl.Hide();
            scoreLabel.Hide();
            CountdownLbl.Hide();
            done = false;
            reshuffle();
            timeLbl.Hide();
            P1ScoreLbl.Show();
            P2ScoreLbl.Show();
            turnLbl.Show();
        }
Example #5
0
        //initialises time trial game
        void timeTrialInit()
        {
            // sets up initial timer
            tempTime = 3;
            // sets up inital values
            score      = 0;
            gameMode   = 1;
            multiplier = 1;
            //sets up menu
            multiLbl.Invoke(new Action(() => multiLbl.Hide()));
            done = false;
            reshuffle();
            tempTime = 3;
            CountdownLbl.Invoke(new Action(() => CountdownLbl.Show()));
            P1ScoreLbl.Invoke(new Action(() => P1ScoreLbl.Hide()));
            P2ScoreLbl.Invoke(new Action(() => P2ScoreLbl.Hide()));

            Console.WriteLine(tempTime);

            // starts the timer
            timeCounter = 60;
            if (ticking)
            {
                aTimer.Stop();
            }

            ticking = true;
            aTimer  = new System.Timers.Timer(1000);
            // Hook up the Elapsed event for the timer.
            aTimer.Elapsed  += timer_Tick;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;
            timeLbl.Invoke(new Action(() => timeLbl.Show()));
            scoreLabel.Invoke(new Action(() => scoreLabel.Show()));

            scoreLabel.Text = "Score: " + score;
        }
Example #6
0
 //initialises classic game
 void classicInit()
 {
     // checks if a timer is running
     if (ticking)
     {
         aTimer.Stop();
         ticking = false;
     }
     // sets up correct score game and multiplier values
     score      = 0;
     gameMode   = 0;
     multiplier = 1;
     multiLbl.Hide();
     done = false;
     //randomises button colors
     reshuffle();
     // sets up menu
     timeLbl.Hide();
     scoreLabel.Show();
     CountdownLbl.Hide();
     P1ScoreLbl.Hide();
     P2ScoreLbl.Hide();
     scoreLabel.Text = "Score: " + score;
 }