예제 #1
0
        // Relationship operation:
        public bool IsGreaterThan(MassiveNumber argNum)
        {
            bool returnBool;

            if ((this.echelon > argNum.echelon) || (this.echelon == argNum.echelon && this.value >= argNum.value))
            {
                returnBool = true;
            }
            else
            {
                returnBool = false;
            }

            return(returnBool);
        }
예제 #2
0
        // Method for game loop thread.
        #region

        static void GameLoop()
        {
            while (!exitCheck)
            {
                // Loop through all agents to increase the player's points bank.
                for (uint i = 0; i < 10; i++)
                {
                    if (!agentObjsArr[i].isLocked)
                    {
                        if (agentObjsArr[i].count.value > 0)
                        {
                            MassiveNumber tempNumber = new MassiveNumber();

                            // Evaluate agents.
                            tempNumber.value = tempNumber.Add(agentObjsArr[i].pointsRate.Mult((agentObjsArr[i].count.value), agentObjsArr[i].count.echelon), agentObjsArr[i].pointsRate.echelon);
                            tempNumber.UpdateEchelon();

                            // Evaluate upgrades.
                            if (upgraObjsArr[i].count.value > 0)
                            {
                                tempNumber.value = tempNumber.Mult(upgraObjsArr[i].count.Mult(upgraObjsArr[i].incomeMultiplier, upgraObjsArr[i].count.echelon) + 1, 1);
                                tempNumber.UpdateEchelon();
                            }

                            gamePoints.value = gamePoints.Add(tempNumber.value, tempNumber.echelon);
                            gamePoints.UpdateEchelon();
                        }
                    }
                }

                RenderWindow.gamePoints = gamePoints;
                gamePoints.UpdateEchelon();

                lock (raceConditionLocker)
                {
                    // Attempt to update the console.
                    UpdateConsole();
                    SharedResource++;

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

                // Loop every second.
                Thread.Sleep(1000);
            }
        }
예제 #3
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);
        }
예제 #4
0
        // Constructor
        public RenderWindow(uint argRows, uint argColumns)
        {
            // Variable values:
            #region

            rowCount    = argRows + 1;
            columnCount = argColumns + 1;

            #endregion

            // Declare arrays:
            #region

            gridString      = new string[rowCount, columnCount, 4];
            gridStringCount = new uint[rowCount, columnCount];
            gridStringColor = new ConsoleColor[rowCount, columnCount, 4];

            gridType = new RenderGridTypes[rowCount, columnCount];
            gridCol  = new ConsoleColor[rowCount, columnCount];

            gamePoints    = new MassiveNumber();
            displayPoints = new MassiveNumber();

            agentPointsRate = new MassiveNumber[rowCount];

            agentIsLocked = new bool[rowCount];

            agentLabel = new string[rowCount];
            upgraLabel = new string[rowCount, 3];

            columnWidth = new int[columnCount];

            for (uint i = 0; i < columnCount; i++)
            {
                columnWidth[i] = 25;
            }

            for (uint i = 0; i < rowCount; i++)
            {
                agentCount[i] = new MassiveNumber();
                agentPrice[i] = new MassiveNumber();
                upgraCount[i] = new MassiveNumber();
                upgraPrice[i] = new MassiveNumber();

                agentPointsRate[i] = new MassiveNumber();
                agentIsLocked[i]   = true;
            }

            #endregion

            // Hardcoded values:
            #region

            optimalIsAgent = true;

            currentMenuInd = 1;     // 1 -> Agents
                                    // 2 -> Upgrades
            menuPages = 2;

            columnWidth[0] = 8;     // Empty
            columnWidth[1] = 30;    // Legend
            columnWidth[2] = 7;     // Agent Keys
            columnWidth[3] = 25;    // Agent Count
            columnWidth[4] = 17;    // Agent Price
                                    // Agent Label

            agentLabel[0] = "Stone Harvester";
            agentLabel[1] = "Coal Miner";
            agentLabel[2] = "Iron Miner";
            agentLabel[3] = "Drill Operator";
            agentLabel[4] = "Steel Drill Operator";
            agentLabel[5] = "Diamond Drill Operator";
            agentLabel[6] = "Blast Miner";
            agentLabel[7] = "Demolitionist";
            agentLabel[8] = "Demolition Expert";
            agentLabel[9] = "Crypto Miner";

            upgraLabel[0, 0] = "Better Grip Gloves";
            upgraLabel[0, 1] = "Morale Boost";
            upgraLabel[0, 2] = "Automated Stone Grabbing System";
            upgraLabel[1, 0] = "Sharper pickaxes";
            upgraLabel[1, 1] = "Morale Boost";
            upgraLabel[1, 2] = "Coffee";
            upgraLabel[2, 0] = "Sturdier Pickaxes";
            upgraLabel[2, 1] = "Morale Boost";
            upgraLabel[2, 2] = "Energy Drinks";

            upgraLabel[3, 0] = "Wireless Drills";
            upgraLabel[3, 1] = "Extended Battery Life";
            upgraLabel[3, 2] = "Dual-Bit Drills";
            upgraLabel[4, 0] = "Reinforced Drills";
            upgraLabel[4, 1] = "Battery Cell Array";
            upgraLabel[4, 2] = "Quad-Bit Drills";
            upgraLabel[5, 0] = "Lighter Drills";
            upgraLabel[5, 1] = "Portable Reactors";
            upgraLabel[5, 2] = "Omni-Bit Drills";

            upgraLabel[6, 0] = "Increased Potency";
            upgraLabel[6, 1] = "Faster Fuse Time";
            upgraLabel[6, 2] = "Cluster Explosive";
            upgraLabel[7, 0] = "Recursive Explosive Mining";
            upgraLabel[7, 1] = "Compact Explosive Mining";
            upgraLabel[7, 2] = "Hypersonic Explosive Mining";
            upgraLabel[8, 0] = "Thermobaric Explosive License";
            upgraLabel[8, 1] = "Anti-Matter Explosive License";
            upgraLabel[8, 2] = "Red Matter Explosive License";

            upgraLabel[9, 0] = "Faster Processors";
            upgraLabel[9, 1] = "Liquid Cooling";
            upgraLabel[9, 2] = "Overclocking";

            for (int i = 0; i < gridStringColor.GetLength(0); i++)
            {
                for (int j = 0; j < gridStringColor.GetLength(1); j++)
                {
                    for (int k = 0; k < gridStringColor.GetLength(2); k++)
                    {
                        gridStringColor[i, j, k] = ConsoleColor.White;
                    }
                }
            }

            for (uint i = 0; i < rowCount; i++)
            {
                for (uint j = 0; j < columnCount; j++)
                {
                    // Default to blank grid.
                    gridStringCount[i, j] = 0;
                    gridType[i, j]        = RenderGridTypes.GridEmpty;
                    gridString[i, j, 0]   = "";

                    // Write info
                    #region

                    if (j == 0 && i == 0)
                    {
                        gridType[i, j]           = RenderGridTypes.GridString;
                        gridStringColor[i, j, 1] = ConsoleColor.Gray;
                        gridStringCount[i, j]    = 1;

                        gridString[i, j, 0] = "Exit: ";
                        gridString[i, j, 1] = "X";
                    }

                    #endregion

                    // Write legend column.
                    #region

                    if (j == 1)
                    {
                        // Center these rows relative to the agents' rows.
                        if (i == rowCount / 2 - 1)
                        {
                            gridType[i, j]      = RenderGridTypes.GridPoints;
                            gridString[i, j, 0] = "Profits: ";
                        }
                        else if (i == rowCount / 2)
                        {
                            gridType[i, j]           = RenderGridTypes.GridString;
                            gridStringColor[i, j, 1] = ConsoleColor.Cyan;
                            gridStringCount[i, j]    = 2;

                            gridString[i, j, 0] = "Press ";
                            gridString[i, j, 1] = "Spacebar";
                            gridString[i, j, 2] = " to dig";
                        }
                        else if (i == rowCount / 2 + 1)
                        {
                            gridType[i, j]        = RenderGridTypes.GridChangeMenu;
                            gridStringCount[i, j] = 3;

                            gridString[i, j, 0] = "Press ";
                            gridString[i, j, 1] = "<-";
                            gridString[i, j, 2] = " or ";
                            gridString[i, j, 3] = "->";
                        }
                    }

                    #endregion

                    // Write key press column
                    #region

                    if (j == 2)
                    {
                        gridType[i, j]           = RenderGridTypes.GridString;
                        gridStringColor[i, j, 0] = ConsoleColor.Gray;
                        gridStringColor[i, j, 2] = ConsoleColor.Gray;
                        gridStringCount[i, j]    = 2;

                        gridString[i, j, 0] = "[";
                        gridString[i, j, 1] = "" + ((int)(i + 11) % 10);
                        gridString[i, j, 2] = "]";
                    }

                    #endregion

                    // Write agents price column.
                    #region

                    if (j == 3)
                    {
                        gridString[i, j, 0] = "Price: ";
                        gridType[i, j]      = RenderGridTypes.GridAgentPrice;
                    }

                    #endregion

                    // Write agents count column.
                    #region

                    if (j == 4)
                    {
                        if (i == 0)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 1)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 2)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 3)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 4)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 5)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 6)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 7)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 8)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                        else if (i == 9)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentCount;
                        }
                    }

                    #endregion

                    // Write agents label column.
                    #region

                    if (j == 5)
                    {
                        gridString[i, j, 0] = (agentLabel[i]);

                        if (i == 0)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 1)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 2)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 3)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 4)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 5)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 6)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 7)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 8)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                        else if (i == 9)
                        {
                            gridType[i, j] = RenderGridTypes.GridAgentLabel;
                        }
                    }

                    #endregion
                }
            }

            #endregion
        }
예제 #5
0
        // Exponentiation operation:
        public MassiveNumber Pow(double argExponent)
        {
            // Instantiate and initialize variables.
            MassiveNumber returnNumber = new MassiveNumber();

            returnNumber.value   = 1;
            returnNumber.echelon = 1;

            MassiveNumber fractionNumber = new MassiveNumber();

            fractionNumber.value   = 1;
            fractionNumber.echelon = 1;

            double fractionExpo = argExponent % 1d;

            // If the exponent is not an integer.
            if (fractionExpo > 0)
            {
                fractionNumber.value   = this.value;
                fractionNumber.echelon = this.echelon;

                // (x*1,000) ^ y = (x)^y * (10^3)^y
                fractionNumber.value = Math.Pow(fractionNumber.value, fractionExpo);
                fractionNumber.UpdateEchelon();

                for (int i = 0; i < fractionNumber.echelon + 1; i++)
                {
                    fractionNumber.value *= Math.Pow(10, fractionExpo);
                    fractionNumber.UpdateEchelon();
                }
            }

            returnNumber.value   = this.value;
            returnNumber.echelon = this.echelon;

            // x^4 = ( x*x*x*x )
            if ((uint)argExponent > 1)
            {
                for (uint i = 1; i < (uint)argExponent; i++)
                {
                    returnNumber.value = returnNumber.Mult(this.value, this.echelon);
                    returnNumber.UpdateEchelon();

                    if (i < (uint)argExponent - 1)
                    {
                        returnNumber.echelon *= returnNumber.echelon;
                    }
                }
            }
            else
            {
                if ((uint)argExponent > 1)
                {
                    // Mult at least once
                    returnNumber.value = returnNumber.Mult(returnNumber.value, 1);
                    returnNumber.UpdateEchelon();
                }
            }

            // Mult whole exponentiated value to fractional exponentiated value.
            // This method is equivalent to:
            // x^4.5 = ( x*x*x*x ) * ( x^0.5 )

            if (argExponent >= 1)
            {
                if (fractionExpo > 0)
                {
                    returnNumber.value = returnNumber.Mult(fractionNumber.value, fractionNumber.echelon);
                }
            }
            else
            {
                returnNumber.value = fractionNumber.value;
            }

            returnNumber.UpdateEchelon();

            return(returnNumber);
        }
예제 #6
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();
            }
        }