public void Render(RenderWindow rWindow) { rWindow.Draw(sprite); }
// 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(); } }