示例#1
0
        public void RenderLoop()
        {
            string tempStr;
            // Return row index with the optimal item, and set isAgentOptimal as a side effect.
            uint optimalRow = OptimalItem();

            // Refresh the console;
            Console.Clear();

            // Write each row.
            for (uint rowIterate = 0; rowIterate < rowCount; rowIterate++)
            {
                // Write each column of this row.
                for (uint columnIterate = 0; columnIterate < columnCount; columnIterate++)
                {
                    tempStr = gridString[rowIterate, columnIterate, 0];
                    int tempStrLength = 0;

                    switch (gridType[rowIterate, columnIterate])
                    {
                    case RenderGridTypes.GridEmpty:
                        Console.Write(gridString[rowIterate, columnIterate, 0].PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));
                        break;

                    case RenderGridTypes.GridPoints:
                        Console.Write(tempStr);

                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.Write(gamePoints.GetAbbreviation().PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));

                        break;

                    case RenderGridTypes.GridString:
                        for (uint i = 0; i <= gridStringCount[rowIterate, columnIterate]; i++)
                        {
                            Console.ForegroundColor = gridStringColor[rowIterate, columnIterate, i];

                            if (i < gridStringCount[rowIterate, columnIterate])
                            {
                                Console.Write(gridString[rowIterate, columnIterate, i]);
                            }
                            else
                            {
                                Console.Write(gridString[rowIterate, columnIterate, i].PadRight(columnWidth[columnIterate] - tempStrLength, ' '));
                            }

                            tempStrLength += gridString[rowIterate, columnIterate, i].Length;
                        }

                        break;

                    case RenderGridTypes.GridChangeMenu:
                        // Super hack-y quick code. But it works.
                        tempStrLength = 0;

                        for (int j = 0; j <= 1; j++)
                        {
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.Write(gridString[rowIterate, columnIterate, j * 2]);
                            tempStrLength += gridString[rowIterate, columnIterate, j * 2].Length;

                            if (optimalIsAgent)
                            {
                                if (currentMenuInd == 1)
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkGray;
                                }
                                else if (agentPrice[optimalRow].IsGreaterThan(gamePoints))
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                }
                            }
                            else
                            {
                                if (currentMenuInd == 2)
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkGray;
                                }
                                else if (upgraPrice[optimalRow].IsGreaterThan(gamePoints))
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                }
                            }

                            Console.Write(gridString[rowIterate, columnIterate, j * 2 + 1]);
                            tempStrLength += gridString[rowIterate, columnIterate, j * 2 + 1].Length;
                        }

                        Console.Write("".PadRight(columnWidth[columnIterate] - tempStrLength, ' '));

                        break;

                    case RenderGridTypes.GridAgentCount:
                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write(agentCount[rowIterate].GetAbbreviation().PadRight(columnWidth[columnIterate], ' '));

                        break;

                    case RenderGridTypes.GridAgentLabel:
                        Console.ForegroundColor = ConsoleColor.DarkGray;

                        if (agentIsLocked[rowIterate])
                        {
                            string tempQStr = "";

                            foreach (char c in agentLabel[rowIterate])
                            {
                                if (c != ' ')
                                {
                                    tempQStr += "?";
                                }
                                else
                                {
                                    tempQStr += " ";
                                }
                            }

                            Console.Write(tempQStr.PadRight(columnWidth[columnIterate], ' '));
                        }
                        else
                        {
                            Console.Write(gridString[rowIterate, columnIterate, 0].PadRight(columnWidth[columnIterate], ' '));
                        }

                        break;

                    case RenderGridTypes.GridAgentPrice:
                        Console.ForegroundColor = ConsoleColor.White;     // Reset color
                        Console.Write(tempStr);

                        if (gamePoints.IsGreaterThan(agentPrice[rowIterate]))
                        {
                            // If the player can afford this agent.
                            if (rowIterate == optimalRow && optimalIsAgent)
                            {
                                // If this is the most cost efficient agent.
                                Console.ForegroundColor = ConsoleColor.DarkGreen;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.DarkGray;
                            }
                        }
                        else
                        {
                            // If the player cannot afford this agent.
                            if (rowIterate == optimalRow && optimalIsAgent)
                            {
                                // If this is the most cost efficient agent.
                                Console.ForegroundColor = ConsoleColor.DarkYellow;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.DarkRed;
                            }
                        }

                        Console.Write(agentPrice[rowIterate].GetAbbreviation().PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));

                        break;

                    case RenderGridTypes.GridUpgradeCount:
                        Console.Write(tempStr);

                        Console.ForegroundColor = ConsoleColor.DarkGray;
                        Console.Write(upgraCount[rowIterate].GetAbbreviation().PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));

                        break;

                    case RenderGridTypes.GridUpgradeLabel:
                        if (upgraCount[rowIterate].value < 3)
                        {
                            Console.ForegroundColor = ConsoleColor.DarkGray;

                            if (agentIsLocked[rowIterate])
                            {
                                string tempQStr = "";

                                foreach (char c in upgraLabel[rowIterate, (int)upgraCount[rowIterate].value])
                                {
                                    if (c != ' ')
                                    {
                                        tempQStr += "?";
                                    }
                                    else
                                    {
                                        tempQStr += " ";
                                    }
                                }

                                Console.Write(tempQStr.PadRight(columnWidth[columnIterate], ' '));
                            }
                            else
                            {
                                Console.Write(upgraLabel[rowIterate, (int)upgraCount[rowIterate].value].PadRight(columnWidth[columnIterate], ' '));
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.DarkCyan;
                            Console.Write("UPGRADES MAXED");
                        }

                        break;

                    case RenderGridTypes.GridUpgradePrice:
                        Console.ForegroundColor = ConsoleColor.White;     // Reset color
                        Console.Write(tempStr);

                        if (upgraCount[rowIterate].value < 3)
                        {
                            if (gamePoints.IsGreaterThan(upgraPrice[rowIterate]))
                            {
                                // If the player can afford this agent.
                                if (rowIterate == optimalRow && !optimalIsAgent)
                                {
                                    // If this is the most cost efficient agent.
                                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkGray;
                                }
                            }
                            else
                            {
                                // If the player cannot afford this agent.
                                if (rowIterate == optimalRow && !optimalIsAgent)
                                {
                                    // If this is the most cost efficient agent.
                                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.DarkRed;
                                }
                            }

                            Console.Write(upgraPrice[rowIterate].GetAbbreviation().PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));
                        }
                        else
                        {
                            Console.Write(("").PadRight(columnWidth[columnIterate] - tempStr.Length, ' '));
                        }

                        break;

                        // End of switch-case block.
                    }

                    // Reset color.
                    Console.ForegroundColor = ConsoleColor.White;
                }

                // Shift to next row.
                Console.WriteLine();
            }
        }
示例#2
0
        private uint OptimalItem()
        {
            uint          returnRow  = 0;
            MassiveNumber tempNumber = new MassiveNumber();

            tempNumber.echelon = 1;
            tempNumber.value   = -1;

            for (uint i = 0; i < rowCount; i++)
            {
                // Find the most cost efficient item.
                if (!agentIsLocked[i])
                {
                    // Divide each Agent's price by its income rate.
                    MassiveNumber calcNumber = new MassiveNumber();
                    calcNumber.value   = agentPrice[i].value;
                    calcNumber.echelon = agentPrice[i].echelon;

                    calcNumber.value = calcNumber.Div(agentPointsRate[i].value, agentPointsRate[i].echelon);
                    calcNumber.UpdateEchelon();

                    // If this is the shortest time to break even.
                    if ((!calcNumber.IsGreaterThan(tempNumber)) || tempNumber.value == -1)
                    {
                        returnRow          = i;
                        optimalIsAgent     = true;          // Side effect.
                        tempNumber.value   = calcNumber.value;
                        tempNumber.echelon = calcNumber.echelon;
                    }

                    // Do not consider upgrades for agents that do not exist.
                    if (agentCount[i].value > 0)
                    {
                        if (upgraCount[i].value < 3)
                        {
                            // Divide each Upgrade's price by its immediate income rate.
                            MassiveNumber calcNumber2 = new MassiveNumber();
                            calcNumber2.value   = upgraPrice[i].value;
                            calcNumber2.echelon = upgraPrice[i].echelon;

                            MassiveNumber UpgradeIncome = new MassiveNumber();
                            UpgradeIncome.value = agentCount[i].Mult(upgraIncomeMult[i] + 1, 1);
                            UpgradeIncome.UpdateEchelon();

                            calcNumber2.value = UpgradeIncome.Div(upgraPrice[i].value, upgraPrice[i].echelon);
                            calcNumber2.UpdateEchelon();

                            // If this is the shortest time to break even.
                            if (!calcNumber2.IsGreaterThan(tempNumber))
                            {
                                returnRow          = i;
                                optimalIsAgent     = false;     // Side effect.
                                tempNumber.value   = calcNumber2.value;
                                tempNumber.echelon = calcNumber2.echelon;
                            }
                        }
                    }
                }
            }

            return(returnRow);
        }
示例#3
0
        // Method for player input thread.
        #region

        static void PlayerInput()
        {
            while (!exitCheck)
            {
                int inputIndex;

                // Player controls
                while (Console.KeyAvailable)
                {
                    Console.ReadKey(false);
                }

                ConsoleKeyInfo playerInput = Console.ReadKey();

                if (Char.IsNumber(playerInput.KeyChar))
                {
                    // Get array index from digit input.
                    inputIndex = (int)(Char.GetNumericValue(playerInput.KeyChar) + 9) % 10;
                    MassiveNumber itemCost = new MassiveNumber();

                    if (RenderWindow.currentMenuInd == 1)
                    {
                        itemCost = agentObjsArr[inputIndex].GetPrice();
                    }
                    else if (RenderWindow.currentMenuInd == 2)
                    {
                        itemCost = upgraObjsArr[inputIndex].GetPrice();
                    }

                    // If the player has sufficient points
                    if (gamePoints.IsGreaterThan(itemCost))
                    {
                        // Update the console values.
                        if (RenderWindow.currentMenuInd == 1)
                        {
                            // Increment the agent that the user inputs.
                            agentObjsArr[inputIndex].count.value = agentObjsArr[inputIndex].count.Add(1, 1);
                            agentObjsArr[inputIndex].count.UpdateEchelon();
                            agentObjsArr[inputIndex].UpdatePrice();

                            // Decrease the player's points bank.
                            gamePoints.value = gamePoints.Sub(itemCost.value, itemCost.echelon);
                            gamePoints.UpdateEchelon();
                        }
                        else if (RenderWindow.currentMenuInd == 2)
                        {
                            // If the upgrade is available.
                            if (upgraObjsArr[inputIndex].count.value <= upgraObjsArr[inputIndex].maxCount)
                            {
                                // Increment the upgrade that the user inputs.
                                upgraObjsArr[inputIndex].count.value = upgraObjsArr[inputIndex].count.Add(1, 1);
                                upgraObjsArr[inputIndex].count.UpdateEchelon();
                                upgraObjsArr[inputIndex].UpdatePrice();

                                // Decrease the player's points bank.
                                gamePoints.value = gamePoints.Sub(itemCost.value, itemCost.echelon);
                                gamePoints.UpdateEchelon();
                            }
                        }
                    }
                }
                else
                {
                    switch (playerInput.Key)
                    {
                    case ConsoleKey.Spacebar:
                        gamePoints.value = gamePoints.Add(1, 1);
                        gamePoints.UpdateEchelon();

                        // Attempt to unlock every locked agent.
                        UnlockAgents();

                        break;

                    case ConsoleKey.S:
                        FileIO.SaveGame();
                        break;

                    case ConsoleKey.L:
                        FileIO.LoadGame();
                        break;

                    case ConsoleKey.RightArrow:
                        RenderWindow.ChangeMenu(RenderWindow.currentMenuInd + 1);
                        break;

                    case ConsoleKey.LeftArrow:
                        RenderWindow.ChangeMenu(RenderWindow.currentMenuInd - 1);
                        break;

                    case ConsoleKey.X:
                        exitCheck = true;

                        break;
                    }
                }

                // Prevent both threads from updating simultaneously.
                lock (raceConditionLocker)
                {
                    UpdateConsole();
                    SharedResource--;
                }

                Thread.Sleep(30);
            }

            if (exitCheck)
            {
                Console.Clear();
                Console.WriteLine("Thank you for playing! Your final total of money earned was: " + gamePoints.GetAbbreviation());
                Console.ReadKey();
            }
        }