Пример #1
0
        public void displayTableList()             //to display all tables status
        {
            ArrayList tableList = new ArrayList(); //ArrayList to store list of tables

            tableList = readTableFileList();       //reads tables from file to list

            Console.Write("--------------------------------------------------------------------------------");
            Console.WriteLine("DISPLAY ALL TABLES STATUS:");
            Console.Write("--------------------------------------------------------------------------------");

            for (int i = 0; i < tableList.Count; i++) //checks each table
            {
                Console.WriteLine();
                Console.WriteLine("----------------------");
                Console.WriteLine("Table-ID: " + (tableList[i] as table).tableID);
                Console.WriteLine("----------------------");
                if ((tableList[i] as table).gameStatus == 0) //game status i.e. 0->Empty Table, 1->One Player Assigned, 2->Two Players Assigned
                {
                    Console.WriteLine("0 Players Assigned.");
                }
                else if ((tableList[i] as table).gameStatus == 1) //game status i.e. 0->Empty Table, 1->One Player Assigned, 2->Two Players Assigned
                {
                    player p = new player();
                    Console.WriteLine("1 Player Assigned.");

                    string playerOneName = p.fullName((tableList[i] as table).playerOneProperty);
                    Console.WriteLine("1. Player-1 (ID-" + (tableList[i] as table).playerOneProperty + ") " + playerOneName);
                    Console.WriteLine("Start Time:" + (tableList[i] as table).startTimeProperty);
                }
                if ((tableList[i] as table).gameStatus == 2) //game status i.e. 0->Empty Table, 1->One Player Assigned, 2->Two Players Assigned
                {
                    player p = new player();
                    Console.WriteLine("2 Players Assigned.");

                    string playerOneName = p.fullName((tableList[i] as table).playerOneProperty);
                    string playerTwoName = p.fullName((tableList[i] as table).playerTwoProperty);
                    Console.WriteLine("1. Player-1 (ID-" + (tableList[i] as table).playerOneProperty + ") " + playerOneName);
                    Console.WriteLine("2. Player-2 (ID-" + (tableList[i] as table).playerTwoProperty + ") " + playerTwoName);
                    Console.WriteLine("Start Time:" + (tableList[i] as table).startTimeProperty);
                }
            }
        }
Пример #2
0
        public void submitTableResults()           //to submit game results and clear table status
        {
            ArrayList tableList = new ArrayList(); //ArrayList to store list of tables

            tableList = readTableFileList();       //reads tables from file to list

            Console.Write("--------------------------------------------------------------------------------");
            Console.WriteLine("SUBMIT TABLE RESULTS:");
            Console.Write("--------------------------------------------------------------------------------");

            Console.WriteLine("Enter Table-ID:");
            int id = int.Parse(Console.ReadLine());

            for (int i = 0; i < tableList.Count; i++)      //checks each table
            {
                if ((tableList[i] as table).tableID == id) //checks for the required table
                {
                    player p = new player();
                    Console.WriteLine("Select Won User:"******"1. Player-1 (ID-" + (tableList[i] as table).playerOneProperty + ") " + playerOneName);
                    Console.WriteLine("2. Player-2 (ID-" + (tableList[i] as table).playerTwoProperty + ") " + playerTwoName);
                    Console.WriteLine("3. Game Draw.");
                    int choice = int.Parse(Console.ReadLine());
                    if (choice == 1)
                    {
                        p.playerWon((tableList[i] as table).playerOneProperty);  //updates won status of player1
                        p.playerLost((tableList[i] as table).playerTwoProperty); //updates lost status of player2
                    }
                    else if (choice == 2)
                    {
                        p.playerWon((tableList[i] as table).playerTwoProperty);  //updates won status of player2
                        p.playerLost((tableList[i] as table).playerOneProperty); //updates lost status of player1
                    }
                    else if (choice == 3)
                    {
                        p.playerDraw((tableList[i] as table).playerOneProperty, (tableList[i] as table).playerTwoProperty); //updates draw status of both users
                    }
                    else
                    {
                        Console.WriteLine("ERROR!!! Invalid Input.");
                    }
                    (tableList[i] as table).endTimeProperty = DateTime.Now;

                    StreamWriter writeGameLogFile = new StreamWriter("GameLog.txt", true);
                    writeGameLogFile.WriteLine((tableList[i] as table).tableIDProperty);
                    writeGameLogFile.WriteLine((tableList[i] as table).playerOneProperty);
                    writeGameLogFile.WriteLine((tableList[i] as table).playerTwoProperty);
                    writeGameLogFile.WriteLine((tableList[i] as table).startTimeProperty);
                    writeGameLogFile.WriteLine((tableList[i] as table).endTimeProperty);
                    writeGameLogFile.Close();

                    (tableList[i] as table).gameStatus        = 0; //clears table status to empty
                    (tableList[i] as table).playerOneProperty = 0; //clears table player1 to empty
                    (tableList[i] as table).playerTwoProperty = 0; //clears table player2 to empty
                    writeTableFileList(tableList);
                    return;
                }
            }
        }