コード例 #1
0
        public void NewTrade(Travel myUniverse, Player_Stats player, Ship myShip)
        {
            bool   isDone = false;
            string input  = "";

            Console.WriteLine($"Welcome to {myUniverse.GetPlanetName(myUniverse.planetNum)}.");
            Console.WriteLine($"Here is what we have.\n");
            PlanetInv(prices);
            do
            {
                Console.WriteLine("Would you like to buy or sell? Please type buy or sell for selection.");
                Console.WriteLine("If you would like to leave press \"Enter\".");
                input = Console.ReadLine();
                if (input == "")
                {
                    isDone = true;
                }
                else if (input == "Buy" || input == "buy")
                {
                    BuyThings(myShip, player, myUniverse); //Calls the methomakepricesd for buying
                }
                else if (input == "Sell" || input == "sell")
                {
                    SellThings(player, myShip);
                }
                else
                {
                    Console.WriteLine("I don't understand.");
                }
            }while (!isDone);
            Console.WriteLine("Good Luck!");
            return;
        }
コード例 #2
0
        public static void BuySellYN(int val, ref bool action, int buySell, Player_Stats player)
        {
            int    choice;
            string purchaseSell;

            if (buySell == 1)
            {
                purchaseSell = "Purchase";
            }                                                //says buy if buying
            else
            {
                purchaseSell = "Sell";
            }                               // says sell if selling
            Console.WriteLine($"1. {purchaseSell}");
            Console.WriteLine("2. Decline");
            choice = GetInt(2);
            switch (choice)
            {
            case 1:
                if (buySell == 1)
                {
                    if (player.SMoney() < val)
                    {
                        Console.WriteLine("You don't have enough money.");
                        action = false;
                        break;
                    }
                    else
                    {
                        player.ChangeMoney(-val);
                        action = true;
                        break;
                    }
                }
                else
                {
                    player.ChangeMoney(val);
                    action = true;
                    break;
                }

            case 2:
                Console.WriteLine("Well maybe another time.");
                action = false;
                break;

            default:
                Console.WriteLine("Uh... ok, well see you later...");
                action = false;
                break;
            }
            return;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bdmorehead/My-Space-Game
        static void Main(string[] args)
        {

            Ship myShip;
            myShip = new Ship(3, 12, 6, 10, 10); // set ship speed, cargo slots, slot size, fuel tank, and fuel
            Travel myUniverse;
            myUniverse = new Travel(200, 0);
            Player_Stats player;
            player = new Player_Stats(100, 0, 0, 0, 0, 0);
            bool isGameOver = false; //if a game end triggers this will be changed to true
            string input = ""; //Useful for when we want input


            int[,] cargoItems = new int[24, 2] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
                { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
                { 0, 0 }, { 0, 0 }, { 0, 0 } }; //to store type and amount of cargo in slots
コード例 #4
0
        public static bool CheckGameOver(Ship myShip, Travel myUniverse, Player_Stats player)
        {
            int  counter    = 0;
            bool hasCargo   = false;
            bool enoughFuel = false;

            do
            {
                if (myShip.inventory[counter, 1] == 0)
                {
                    hasCargo = false;
                    counter++;
                }
                else
                {
                    hasCargo = true;
                    counter  = myShip.CargoSlots();
                }
            }while (counter < myShip.CargoSlots());

            myUniverse.WhereCanMove(myShip, ref enoughFuel, false);

            if (player.SYears() >= 40)
            {
                Console.WriteLine("After long years trading you've gotten too old to for this and retire.");
                return(true);
            }
            else if (player.SMoney() == 0 && hasCargo == false)
            {
                return(true);
            }
            else if ((player.SMoney() <= 4) && enoughFuel == false)
            {
                return(true);
            }
            return(false);
        }
コード例 #5
0
        public void ShipThings(Player_Stats player)
        {
            int  cost   = 0;
            int  choice = 0;
            bool buy    = false;

            Console.WriteLine("Hello traveler, looking a new ship, some upgrades, or maybe just for fuel?");
            Console.WriteLine("1. Buying a new ship.");
            Console.WriteLine("2. Upgrading my ship's speed.");
            Console.WriteLine("3. Upgrading my ship's cargo space.");
            Console.WriteLine("4. Upgrading my ship's fuel capacity.");
            Console.WriteLine("5. Buy fuel for my ship.");
            Console.WriteLine("0. I was just leaving.");
            Console.WriteLine("Please enter the number of your choice.");
            choice = Utility.GetInt(5);

            switch (choice)
            {
            case 1:
                Console.WriteLine("We have a light cargo ship, a space freighter, and an old refitted battle cruiser");
                Console.WriteLine("The cargo ship is 500 credits, the space freighter is 1000, and the battle cruiser .");
                Console.WriteLine("is 2000. Enter 1 for the cargo ship, 2 for the space freighter, or 3 for the battle cruiser,");
                Console.WriteLine("Enter 0 to exit.");
                choice = Utility.GetInt(3);
                switch (choice)
                {
                case 1:
                {
                    Utility.BuySellYN(500, ref buy, 1, player);
                    if (buy)
                    {
                        ShipUpgrade(3);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                case 2:
                {
                    Utility.BuySellYN(1000, ref buy, 1, player);
                    if (buy)
                    {
                        ShipUpgrade(4);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                case 3:
                {
                    Utility.BuySellYN(2000, ref buy, 1, player);
                    if (buy)
                    {
                        ShipUpgrade(5);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                case 0:
                {
                    Console.WriteLine("See ya around traveler.");
                    break;
                }
                }
                break;

            case 2:
            {
                if (speed % 2 == 1 && speed != 3)
                {
                    Console.WriteLine("I told you once per ship.");
                }
                else
                {
                    Console.WriteLine("Cost is gonna depend on how fast your ship already is.");
                    Console.WriteLine("Also we can only modify the engine once on a ship.");
                    Console.WriteLine($"Warp drives are just too finnicky to mess around with more than that.\n");
                    if (speed == 3)
                    {
                        Console.WriteLine("Nothing is gonna help that hunk of junk, just save up for a new ship.");
                    }
                    else
                    {
                        cost = speed * speed * 15;
                        Console.WriteLine($"That'll be {cost} credits.");
                        Utility.BuySellYN(cost, ref buy, 1, player);
                        if (buy)
                        {
                            ShipUpgrade(1);
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                break;
            }

            case 3:
            {
                Console.WriteLine("We can attatch some extra containers to the superstructure of your ship.");
                Console.WriteLine("Gotta make sure things are attatched properly, don't want things coming");
                Console.WriteLine("loose during warp travel.  The planet you're approaching when it breaks ");
                Console.WriteLine("won't appreciate your clever cost cutting.");
                if (slots == 12)
                {
                    Console.WriteLine("If we attatch anything to that mess you'll be turning into some light speed shrapnel.");
                }
                else if (slotCapacity == 8 || slotCapacity == 12 || slotCapacity == 16)
                {
                    Console.WriteLine("We can't make any more space on that.");
                }
                else
                {
                    cost = (slotCapacity + 2) * ((slotCapacity + 2)) * 5;
                    Console.WriteLine($"That'll be {cost} credits.");
                    Utility.BuySellYN(cost, ref buy, 1, player);
                    if (buy)
                    {
                        ShipUpgrade(2);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }

                break;
            }

            case 4:
            {
                Console.WriteLine("Looking to travel to the farthest reaches.");
                if (fuelUpgrade)
                {
                    Console.WriteLine("We already did that, you'll need a bigger ship to hold more fuel.");
                }
                else
                {
                    cost = (fuelTank + (fuelTank / 2)) * 5;
                    Console.WriteLine($"It will cost {cost}.");
                    Utility.BuySellYN(cost, ref buy, 1, player);
                    if (buy)
                    {
                        ShipUpgrade(6);
                    }
                }
                break;
            }

            case 5:
            {
                Console.WriteLine("Need some fuel huh?");
                if (fuel == fuelTank)
                {
                    Console.WriteLine("Tank's full already");
                }
                else
                {
                    Console.WriteLine("Ok how much do you want to buy?");
                    Console.WriteLine("Enter 0 if you want a full tank.");
                    choice = Utility.GetInt(fuelTank - fuel);
                    if (choice == 0)
                    {
                        cost = (fuelTank - fuel) * 5;
                        Console.WriteLine($"That will cost {cost}.");
                        Utility.BuySellYN(cost, ref buy, 1, player);
                        if (buy)
                        {
                            fuel = fuelTank;
                            Console.WriteLine("Thanks for your business!");
                        }
                    }
                    else
                    {
                        cost = choice * 5;
                        Console.WriteLine($"That will cost {cost}.");
                        Utility.BuySellYN(cost, ref buy, 1, player);
                        if (buy)
                        {
                            Console.WriteLine("Thanks for your business!");
                        }
                    }
                }
                break;
            }

            case 0:
            {
                Console.WriteLine("See ya around traveler.");
                break;
            }
            }
            return;
        }
コード例 #6
0
        public void SellThings(Player_Stats player, Ship myShip)
        {
            bool isGood = false;
            bool buy;
            int  input;
            int  sellAmount;
            int  sumTotal;

            do
            {
                buy = false;
                Console.WriteLine($"What cargo would you like to sell?\n");
                Console.WriteLine("Please enter the slot number of the cargo you wish to sell.");
                Console.WriteLine($"Enter {(myShip.CargoSlots() + 1)} to check your inventory, {myShip.CargoSlots() + 2} to look at the planet's");
                Console.WriteLine("pricing or 0 when you are done."); //what does the player want to do.
                input = Utility.GetInt(myShip.CargoSlots() + 2);
                if (input == (myShip.CargoSlots() + 1))
                {
                    Utility.ShowCargoInv(myShip); //SHOW ME WHAT YOU GOT
                }
                else if (input == myShip.CargoSlots() + 2)
                {
                    PlanetInv(prices); //how much are things worth?
                }
                else if (input == 0)
                {
                    Console.WriteLine("See ya around traveler."); //leaving
                    isGood = true;
                }
                else if (input < 0 || input > myShip.CargoSlots()) //why are you talking nonsense
                {
                    Console.WriteLine("Uh... ok, well see you later...");
                    isGood = true;
                }
                else if (myShip.inventory[(input - 1), 1] == 0) // nothing there to sell
                {
                    Console.WriteLine($"That container is empty.\n");
                }
                else
                {
                    input--;
                    Console.WriteLine($"Alright that has {myShip.inventory[(input), 1]} units of {Utility.CargoName(myShip.inventory[(input), 0])}.");
                    Console.WriteLine($"How much would you like to sell?");
                    sellAmount = Utility.GetInt(myShip.inventory[input, 1]);
                    if (sellAmount == 0)
                    {
                        Console.WriteLine("It's fine if you don't want to sell.");
                        isGood = true;
                    }
                    else
                    {
                        sumTotal = prices[myShip.inventory[input, 0]] * sellAmount;
                        Console.WriteLine($"I'll give you {sumTotal} credits for that much.");
                        Utility.BuySellYN(sumTotal, ref buy, 2, player);
                        if (buy)
                        {
                            Console.WriteLine("Pleasure doing business with you.");
                            if (sellAmount == myShip.inventory[input, 1])
                            {
                                myShip.inventory[input, 0] = 0;
                                myShip.inventory[input, 1] = 0;
                            }
                            else
                            {
                                myShip.inventory[input, 1] -= sellAmount;
                            }
                            isGood = true;
                        }
                        else
                        {
                            Console.WriteLine("Well I can't offer you more than that.");
                            isGood = true;
                        }
                    }
                }
            }while (!isGood);
            return;
        }
コード例 #7
0
        public void BuyThings(Ship myShip, Player_Stats player, Travel myUniverse)
        {
            int  cargoWhere     = 0;
            int  itemAmount     = 0;
            int  currentItemBuy = 0;
            bool isGood         = false;
            bool buy            = false;

            cost = 0;
            do
            {
                if (checkInventorySlot(myShip, ref cargoWhere))
                {
                    if (myShip.inventory[cargoWhere, 0] != 0) //if slot isn't empty need to buy same thing
                    {
                        Console.WriteLine($"You want to buy more {Utility.CargoName(myShip.inventory[cargoWhere, 0])}.");
                        Console.WriteLine("How much do you want to buy?");
                        itemAmount = Utility.GetInt(myShip.SlotSize());
                        if (itemAmount == 0)
                        {
                            Console.WriteLine("Decided not to buy huh.");
                            isGood = true;
                        }
                        else if ((itemAmount + myShip.inventory[cargoWhere, 1]) > myShip.SlotSize()) //if the amount you want more than fills it you can't buy
                        {
                            Console.WriteLine("There isn't enough space");
                            isGood = true;
                        }
                        else// this is where buying happens when you already have the item
                        {
                            cost = prices[myShip.inventory[cargoWhere, 0]] * itemAmount;
                            Console.WriteLine($"That will cost {cost}.");
                            Utility.BuySellYN(cost, ref buy, 1, player); //call the buying thing
                            if (buy)                                     //you bought something
                            {
                                Console.WriteLine("Thank you for your business.");
                                isGood = true;
                            }
                            cost = 0;
                        }
                    }
                    else //slot is empty, what do you want?
                    {
                        Console.WriteLine("What do you want to buy?");
                        Console.WriteLine("Press 0 to exit.");
                        currentItemBuy = Utility.GetInt(9);
                        if (currentItemBuy == 0) //you want to leave
                        {
                            Console.WriteLine("It's ok if you don't want to buy anything.");
                            isGood = true;
                        }
                        else //initial buying an item, something you don't already own
                        {
                            Console.WriteLine("How much to you want to buy?");
                            itemAmount = Utility.GetInt(myShip.SlotSize());
                            if (itemAmount == 0)
                            {
                                Console.WriteLine("Decided not to buy huh."); // 0 means buy nothing
                                isGood = true;
                            }
                            else if (itemAmount > myShip.SlotSize())
                            {
                                Console.WriteLine("There isn't enough space"); // you can't fit more than slotsize
                            }
                            else
                            {
                                cost = itemAmount * prices[currentItemBuy];
                                Console.WriteLine($"The cost is {cost}.");
                                Utility.BuySellYN(cost, ref buy, 1, player);
                                if (buy)
                                {
                                    myShip.inventory[cargoWhere, 1] = itemAmount;
                                    myShip.inventory[cargoWhere, 0] = currentItemBuy;
                                    cost   = 0;
                                    isGood = true;
                                }
                                else
                                {
                                    Console.WriteLine("Mayber another time.");
                                    cost   = 0;
                                    isGood = true;
                                }
                            }
                        }
                    }
                }
            }while (!isGood);
            return;
        }
コード例 #8
0
ファイル: Travel.cs プロジェクト: MichaelHopkins7/Space-Game
        public void MovingTo(Ship myShip, Player_Stats player, Trading makeMoney)
        {
            int    destNum; //going to planet #
            int    wSpeed;  // warp factor holder
            double speed;   //speed in light years
            bool   isGood      = false;
            bool   closePlanet = false;
            int    input       = 0;

            do
            {
                Console.WriteLine("Where would you like to go?");
                WhereCanMove(myShip, ref closePlanet, true);
                Console.WriteLine("Enter the number for where you would like to go.");
                Console.WriteLine($"Or enter {numberOfPlanets + 1} to leave."); //ask where to go Earth is 0 so max+1
                destNum = Utility.GetInt(numberOfPlanets + 1);                  //get input
                if (destNum == numberOfPlanets + 1)
                {
                    Console.WriteLine("You decide not to leave.");
                    isGood = true;
                }
                else if (closePlanet == false)
                {
                    Console.WriteLine("You don't have enough fuel to get anywhere.");
                    isGood = true;
                }
                else if (Distance(destNum) > myShip.Fuel() && planetNum != destNum)
                {
                    Console.WriteLine($"That is not close enough. Please select a planet on the list. Or {numberOfPlanets + 1} to leave.");
                }
                else if (planetNum != destNum)
                {
                    Console.WriteLine("What warp speed do you want to travel at?");
                    Console.WriteLine($"Your current ship's maximum speed is {myShip.Speed()}.");
                    wSpeed = Utility.GetInt(myShip.Speed());
                    if (wSpeed == 0)
                    {
                        Console.WriteLine("You decide not to leave.");
                        isGood = false;
                    }
                    else
                    {
                        speed      = Math.Pow(wSpeed, (10 / 3.0)) + Math.Pow((10 - wSpeed), (-11 / 3.0));
                        travelTime = Distance(destNum) / speed;
                        convertTime(travelTime);
                        Console.Write("It will take: ");
                        Console.Write($"{tripYears} Years, ");
                        Console.Write($"{tripWeeks} Weeks, ");
                        Console.Write($"{tripDays} Days, ");
                        Console.Write($"and {tripHours} Hours.");
                        Console.WriteLine("Would you like to travel?");
                        input = Utility.GetInt(2);
                        if (input == 1)
                        {
                            player.AddDistance(Distance(destNum));
                            Console.WriteLine($"You have arrived at {GetPlanetName(destNum)}.");
                            player.AddTime(tripYears, tripWeeks, tripDays, tripHours);
                            tripYears = 0;
                            tripWeeks = 0;
                            tripDays  = 0;
                            tripHours = 0;
                            myShip.UseFuel(Distance(destNum)); //uses the fuel
                            planetNum = destNum;
                            isGood    = true;
                            makeMoney.MakePrices(universe, planetNum);
                        }
                        else
                        {
                            Console.WriteLine("You decided not to leave.");
                            isGood = true;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("You decided not to leave.");
                    isGood = true;
                }
            }while (!isGood);
            return;
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: MichaelHopkins7/Space-Game
        static void Main(string[] args)
        {
            Ship myShip;

            myShip = new Ship(3, 12, 6, 10, 10); // set ship speed, cargo slots, slot size, fuel tank, and fuel
            Travel myUniverse;

            myUniverse = new Travel(200, 0);
            Player_Stats player;

            player = new Player_Stats(100, 0, 0, 0, 0, 0);
            int[] prices = new int[10] {
                0, 11, 3, 8, 12, 7, 4, 14, 10, 9
            };
            Trading makeMoney  = new Trading(prices, 0);
            bool    isGameOver = false; //if a game end triggers this will be changed to true
            int     input;              //Useful for when we want input


            Console.WriteLine("The Space Game");
            Console.WriteLine("After a lifetime of wandering between planets you have finally decided to pursue your fortune in the interplanetary trade industry.");
            Console.WriteLine("Earth is your home and starting planet. You will embark from here to start exploring new routes to new planets.");
            System.Threading.Thread.Sleep(10000);
            Console.Clear();
            Console.WriteLine("With your life savings(100 credits) and a brand new ship you head out to make your fortune. ");
            Console.WriteLine("Welcome to the beginning of your space trading adventure.");
            System.Threading.Thread.Sleep(6000);
            Console.Clear();
            Console.WriteLine("Rules for the game:");
            Console.WriteLine("You will have 40 years to acquire as much wealth as possible and become the greatest trader of all time.");
            Console.WriteLine("Trade Routes: Plan appropriate and ensure that you find the best routes for moving around the galaxy.");
            Console.WriteLine("Time: This is your greatest enemy, learn to manipulate it to give you the advantage.");
            Console.WriteLine("Trade: Start early and trade often to be successful.");
            Console.WriteLine("Game Over Criteria: The game will end if you lose all of your fortune, quit the game, or you survive for 40 years.");
            System.Threading.Thread.Sleep(15000);
            Console.Clear();

            do
            {
                Console.WriteLine("What would you like to do?");
                Console.WriteLine("1. Trade");
                Console.WriteLine("2. Travel");
                Console.WriteLine("3. Take care of my ship.");
                Console.WriteLine("4. Check Status");
                Console.WriteLine("0. Quit");
                input = Utility.GetInt(4);
                switch (input)
                {
                case 1:
                {
                    makeMoney.NewTrade(myUniverse, player, myShip);
                    break;
                }

                case 2:
                {
                    myUniverse.MovingTo(myShip, player, makeMoney);
                    break;
                }

                case 3:
                {
                    myShip.ShipThings(player);
                    break;
                }

                case 4:
                {
                    player.Status(myUniverse, myShip);
                    break;
                }

                case 0:
                {
                    isGameOver = true;
                    break;
                }
                }

                if (!isGameOver)
                {
                    isGameOver = Utility.CheckGameOver(myShip, myUniverse, player);
                }
            }while (!isGameOver);
            player.Status(myUniverse, myShip);
            Console.ReadLine();
        }