Beispiel #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();
                }
            }
        }
Beispiel #2
0
 //hides the main menu
 void hideMenu()
 {
     ClassicBtn.Hide();
     ExitBtn.Hide();
     HelpBtn.Hide();
     TimeBtn.Hide();
     multiplayerBtn.Hide();
     menuBack.Hide();
     HomeTLbl.Hide();
     boardHomeBtn.Show();
     TitleLbl.Show();
     if (gameMode == 2)
     {
         P1ScoreLbl.Show();
         P2ScoreLbl.Show();
         turnLbl.Show();
     }
 }
Beispiel #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()));
            }
        }
Beispiel #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();
        }
Beispiel #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;
        }
Beispiel #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;
 }