Example #1
0
        public void TestMethodToStringPM()
        {
            Time2 myTime = new Time2(14, 4, 5);

            string expResult = "2:04:05 PM";

            //NUnit
            Assert.AreEqual(expResult, myTime.ToString());
        }
Example #2
0
        public void TestMethodToStringAM()
        {
            Time2 myTime = new Time2(11, 4, 5);

            //NUnit
            string expResult = "11:04:05 AM";

            Assert.AreEqual(expResult, myTime.ToString());
        }
Example #3
0
        //Update the current time label using Time2 object
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (sender == timer1)
            {
                if (!usingCustomTime)
                {
                    //capture current time in DateTime object
                    currentTime = DateTime.Now;

                    currentTimeConverted = ConvertDateTime(currentTime);

                    //Update time label on form
                    currentTimeLabel.Text = currentTimeConverted.ToString();
                }
                else
                {
                    currentTimeCustom.Second++;
                    currentTimeLabel.Text = currentTimeCustom.ToString();
                }

                //Loop through alarms and see if one needs to be triggered.
                foreach (AlarmTime a in alarmsListBox.Items)
                {
                    if (!usingCustomTime)
                    {
                        if ((currentTimeConverted.ToString()).Equals(a.ToString()))
                        {
                            currentAlarm = a;
                            alarmTriggered(currentAlarm);
                        }
                    }
                    else
                    {
                        if ((currentTimeCustom.ToString()).Equals(a.ToString()))
                        {
                            currentAlarm = a;
                            alarmTriggered(currentAlarm);
                        }
                    }
                }
            }
        }
Example #4
0
    public static void Main(string[] args)
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(t4);         // 12:25:42
        Time2 t6;                         // initialized later in the program

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("   {0}", t1.ToUniversalString()); // 00:00:00
        Console.WriteLine("   {0}\n", t1.ToString());        // 12:00:00 AM

        Console.WriteLine("t2: hour specified; minute and second defaulted");
        Console.WriteLine("   {0}", t2.ToUniversalString()); // 02:00:00
        Console.WriteLine("   {0}\n", t2.ToString());        // 2:00:00 AM

        Console.WriteLine("t3: hour and minute specified; second defaulted");
        Console.WriteLine("   {0}", t3.ToUniversalString()); // 21:34:00
        Console.WriteLine("   {0}\n", t3.ToString());        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine("   {0}", t4.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}\n", t4.ToString());        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine("   {0}", t5.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}", t5.ToString());          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            t6 = new Time2(27, 74, 99); // invalid values
        } // end try
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        } // end catch

        Console.WriteLine("\nTecle qualquer tecla para finalizar...");
        Console.ReadKey();
    } // end Main
Example #5
0
    static void Main()
    {
        var t1 = new Time2();           // 00:00:00
        var t2 = new Time2(2);          // 02:00:00
        var t3 = new Time2(21, 34);     // 21:34:00
        var t4 = new Time2(12, 25, 42); // 12:25:42
        var t5 = new Time2(t4);         // 12:25:42

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine($"   {t1.ToUniversalString()}"); // 00:00:00
        Console.WriteLine($"   {t1.ToString()}\n");        // 12:00:00 AM

        Console.WriteLine(
            "t2: hour specified; minute and second defaulted");
        Console.WriteLine($"   {t2.ToUniversalString()}"); // 02:00:00
        Console.WriteLine($"   {t2.ToString()}\n");        // 2:00:00 AM

        Console.WriteLine(
            "t3: hour and minute specified; second defaulted");
        Console.WriteLine($"   {t3.ToUniversalString()}"); // 21:34:00
        Console.WriteLine($"   {t3.ToString()}\n");        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine($"   {t4.ToUniversalString()}"); // 12:25:42
        Console.WriteLine($"   {t4.ToString()}\n");        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine($"   {t5.ToUniversalString()}"); // 12:25:42
        Console.WriteLine($"   {t5.ToString()}");          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            var t6 = new Time2(27, 74, 99); // invalid values
        }
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        }
    }
    static void Main()
    {
        var t1 = new Time2();
        var t2 = new Time2(2);
        var t3 = new Time2(21, 34);
        var t4 = new Time2(12, 25, 42);
        var t5 = new Time2(t4);

        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine($"{t1.ToUniversalString()}");
        Console.WriteLine($"{t1.ToString()}\n");

        Console.WriteLine("t2: hour specified; minute and second defaulted");
        Console.WriteLine($"{t2.ToUniversalString()}");
        Console.WriteLine($"{t2.ToString()}\n");

        Console.WriteLine("t3: hour and minute specified; second defaulted");
        Console.WriteLine($"{t3.ToUniversalString()}");
        Console.WriteLine($"{t3.ToString()}\n");

        Console.WriteLine("t4: hour, minute and second defaulted");
        Console.WriteLine($"{t4.ToUniversalString()}");
        Console.WriteLine($"{t4.ToString()}\n");

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine($"{t5.ToUniversalString()}");
        Console.WriteLine($"{t5.ToString()}");


        try
        {
            var t6 = new Time2(27, 74, 99);
        }
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        }

        Console.ReadLine();
    }
    public static void Main()
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(27, 74, 99); // 00:00:00
        Time2 t6 = new Time2(t4);         // 12:25:42

        Console.WriteLine("Constructed with :\n");

        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("    {0}", t1.ToUniversalString());
        Console.WriteLine("    {0}\n", t1.ToString());

        Console.WriteLine("t2: hour specified");
        Console.WriteLine("    {0}", t2.ToUniversalString());
        Console.WriteLine("    {0}\n", t2.ToString());

        Console.WriteLine("t3: hour & minute specified");
        Console.WriteLine("    {0}", t3.ToUniversalString());
        Console.WriteLine("    {0}\n", t3.ToString());

        Console.WriteLine("t4: hour & minute & seconde specified");
        Console.WriteLine("    {0}", t4.ToUniversalString());
        Console.WriteLine("    {0}\n", t4.ToString());

        Console.WriteLine("t5: all invalid arguments");
        Console.WriteLine("    {0}", t5.ToUniversalString());
        Console.WriteLine("    {0}\n", t5.ToString());

        Console.WriteLine("t6: Time2 object t4 specified");
        Console.WriteLine("    {0}", t6.ToUniversalString());
        Console.WriteLine("    {0}\n", t6.ToString());

        Console.ReadLine();
    } // end Main
Example #8
0
    public static void Main( string[] args )
    {
        Time2 t1 = new Time2(); // 00:00:00
          Time2 t2 = new Time2( 2 ); // 02:00:00
          Time2 t3 = new Time2( 21, 34 ); // 21:34:00
          Time2 t4 = new Time2( 12, 25, 42 ); // 12:25:42
          Time2 t5 = new Time2( 27, 74, 99 ); // 00:00:00
          Time2 t6 = new Time2( t4 ); // 12:25:42

          Console.WriteLine( "Constructed with:\n" );
          Console.WriteLine( "t1: all arguments defaulted" );
          Console.WriteLine( "   {0}", t1.ToUniversalString() ); // 00:00:00
          Console.WriteLine( "   {0}\n", t1.ToString() ); // 12:00:00 AM

          Console.WriteLine(
         "t2: hour specified; minute and second defaulted" );
          Console.WriteLine( "   {0}", t2.ToUniversalString() ); // 02:00:00
          Console.WriteLine( "   {0}\n", t2.ToString() ); // 2:00:00 AM

          Console.WriteLine(
         "t3: hour and minute specified; second defaulted" );
          Console.WriteLine( "   {0}", t3.ToUniversalString() ); // 21:34:00
          Console.WriteLine( "   {0}\n", t3.ToString() ); // 9:34:00 PM

          Console.WriteLine( "t4: hour, minute and second specified" );
          Console.WriteLine( "   {0}", t4.ToUniversalString() ); // 12:25:42
          Console.WriteLine( "   {0}\n", t4.ToString() ); // 12:25:42 PM

          Console.WriteLine( "t5: all invalid values specified" );
          Console.WriteLine( "   {0}", t5.ToUniversalString() ); // 00:00:00
          Console.WriteLine( "   {0}\n", t5.ToString() ); // 12:00:00 AM

          Console.WriteLine( "t6: Time2 object t4 specified" );
          Console.WriteLine( "   {0}", t6.ToUniversalString() ); // 12:25:42
          Console.WriteLine( "   {0}", t6.ToString() ); // 12:25:42 PM
    }
Example #9
0
    public static void Main(string[] args)
    {
        Time2 t1 = new Time2();           // 00:00:00
        Time2 t2 = new Time2(2);          // 02:00:00
        Time2 t3 = new Time2(21, 34);     // 21:34:00
        Time2 t4 = new Time2(12, 25, 42); // 12:25:42
        Time2 t5 = new Time2(t4);         // 12:25:42
        Time2 t6;                         // initialized later in the program

        Time2 t44 = new Time2(12, 25, 42);
        Time2 t41 = t4;

        if (t4.Equals(t44))
        {
            Console.WriteLine("No way");
        }
        else
        {
            Console.WriteLine("t4 and t44 point to different objects");
        }

        if (t4.Equals(t41))
        {
            Console.WriteLine("t4 and t41 point to the same object");
        }


        Console.WriteLine("Constructed with:\n");
        Console.WriteLine("t1: all arguments defaulted");
        Console.WriteLine("   {0}", t1.ToUniversalString()); // 00:00:00
        Console.WriteLine("   {0}\n", t1.ToString());        // 12:00:00 AM

        Console.WriteLine(
            "t2: hour specified; minute and second defaulted");
        Console.WriteLine("   {0}", t2.ToUniversalString()); // 02:00:00
        Console.WriteLine("   {0}\n", t2.ToString());        // 2:00:00 AM

        Console.WriteLine(
            "t3: hour and minute specified; second defaulted");
        Console.WriteLine("   {0}", t3.ToUniversalString()); // 21:34:00
        Console.WriteLine("   {0}\n", t3.ToString());        // 9:34:00 PM

        Console.WriteLine("t4: hour, minute and second specified");
        Console.WriteLine("   {0}", t4.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}\n", t4.ToString());        // 12:25:42 PM

        Console.WriteLine("t5: Time2 object t4 specified");
        Console.WriteLine("   {0}", t5.ToUniversalString()); // 12:25:42
        Console.WriteLine("   {0}", t5.ToString());          // 12:25:42 PM

        // attempt to initialize t6 with invalid values
        try
        {
            t6 = new Time2(27, 74, 99); // invalid values
        } // end try
        catch (ArgumentOutOfRangeException ex)
        {
            Console.WriteLine("\nException while initializing t6:");
            Console.WriteLine(ex.Message);
        } // end catch
        Console.WriteLine("Push Enter to end the program");
        string s = Console.ReadLine();
    } // end Main
Example #10
0
 // display the Time2 object in console
 public static void DisplayTime(this Time2 aTime)
 {
     Console.WriteLine(aTime.ToString());
 }
Example #11
0
        } //Format int to String (mm:ss)

        private void SaveButton_Click(object sender, EventArgs e)
        {
            sound.Play(sound.click);
            //Set string for board data
            string num_Move = DataBoard.ListMove.Count.ToString();

            //Set string for game status
            string game_status;

            if (DataBoard.Get_GameOver())
            {
                game_status = "1";
            }
            else
            {
                game_status = "0";
            }
            string[] lines = new string[12 + (2 * DataBoard.ListMove.Count)];

            lines[0]  = Mode ? "1" : "0";
            lines[1]  = Cons.Player1_Name;
            lines[2]  = Cons.Player2_Name;
            lines[3]  = Cons.Player1_score.ToString();
            lines[4]  = Cons.Player2_score.ToString();
            lines[5]  = num_Move;
            lines[6]  = game_status;
            lines[7]  = Time1.ToString();
            lines[8]  = Time2.ToString();
            lines[9]  = DataBoard.Get_Cur_Player().ToString();
            lines[10] = Cons.Player1_avt_num.ToString();
            lines[11] = Cons.Player2_avt_num.ToString();
            for (int i = 0; i < DataBoard.ListMove.Count; i++)
            {
                lines[12 + i * 2]     = DataBoard.ListMove[i].X.ToString();
                lines[12 + i * 2 + 1] = DataBoard.ListMove[i].Y.ToString();
            }

            /*
             *  0 gamemode (1:PVP , 0:PvC)
             *  1 player1_name
             *  2 player2_name
             *  3 player1_score
             *  4 player2_score
             *  5 number of Move
             *  6 game status (is Game end?)
             *  7 player1_time (int)
             *  8 player2_tine (int)
             *  9 curent player (int)
             *  10 player1_avatar_num  (index : 0->9)
             *  11 player2_avatar_num  (index : 0->9)
             *
             *  12 Move[1] X
             *  13 Move[1] Y
             *
             *  15 Move[2] X
             *  16 Move[2] Y
             *  ...
             */
            System.IO.File.WriteAllLines(Application.StartupPath + "Save.txt", lines);

            PauseButton_Click(sender, e);
        }
Example #12
0
        public static void Main(string[] args)
        {
            try
            {
                // Test Case - 1
                // Initializing constructor without parameters
                Time2 t1 = new Time2();
                Console.WriteLine("t1: all arguments defaulted");
                Console.WriteLine(" {0}", t1.ToUniversalString());
                Console.WriteLine(" {0}\n", t1.ToString());

                // Test Case - 2
                // Initializing constructor with one single parameter - hour
                Time2 t2 = new Time2(2);
                Console.WriteLine("Constructed with:\n");
                Console.WriteLine("t2: hour specified; minute and second defaulted");
                Console.WriteLine(" {0}", t2.ToUniversalString());
                Console.WriteLine(" {0}\n", t2.ToString());

                // Test Case - 3
                // Initializing constructor with two parameters - hour, minute
                Time2 t3 = new Time2(21, 34);
                Console.WriteLine("t3: hour and minute specified; second defaulted");
                Console.WriteLine(" {0}", t3.ToUniversalString());
                Console.WriteLine(" {0}\n", t3.ToString());

                // Test Case - 4
                // Initializing constructor with all parameters - hour, minute, second
                Time2 t4 = new Time2(12, 25, 42);
                Console.WriteLine("t4: hour, minute and second specified");
                Console.WriteLine(" {0}", t4.ToUniversalString());
                Console.WriteLine(" {0}\n", t4.ToString());


                // Test Case - 5
                // Initializing constructor with previous object
                Time2 t5 = new Time2(t4);
                Console.WriteLine("t5: Time2 object t4 specified");
                Console.WriteLine(" {0}", t5.ToUniversalString());
                Console.WriteLine(" {0}", t5.ToString());


                // Test Case - 6 (Negative Test Case)
                // Adding invalid values for hour, minute, second
                Time2 t6 = new Time2();
                Console.WriteLine("Running test case #6 - Adding invalid values for hour, minute, second");
                try
                {
                    t6.addtime(25, 120, 120);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                // Resetting the time object t1 to valid values
                t6.SetTime(4, 5, 6);


                // Test Case - 7 (Negative Test Case)
                // Invalid values
                Time2 t7;

                try
                {
                    t7 = new Time2(27, 45, 99);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("\nException while initializing t7:");
                    Console.WriteLine(ex.Message);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }