Jessie
Jessie
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
ill give that a shot, thx fo the help
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
ok
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
how would i get rid of the static void Main without fucking up everything tho? cuz every time i try to do that it jsut comepletely breaks everything
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
i didnt, i imported a file from a project i used before, i was gonna adapt that file to this project
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
what i want to do is change that, i want ItemShop to be a class while program.cs would be the only thing with a namespace
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
i want to turn ItemShop into its own class so that i can reference it within program.cs
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
thats what i want to do
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
although i could be wrong on that
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
and from what ive been told i cant really alter that i think
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
those didnt use namespaces cuz thats how i was given them
28 replies
CC#
Created by Jessie on 7/18/2023 in #help
❔ Assignment
ItemShop.cs, this is the file i want turned into a public class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ItemShop
{
class Program
{
private static List<Item> items = new List<Item>();

static void Main(string[] args)
{
InsertItem();
Console.WriteLine("Greetings Traveller! Care to take a look at my wares?");
while (true)
{
PrintItem();
string userInput = Console.ReadLine();
Console.Clear();
Console.WriteLine("User Input " + userInput);
//verifies if user input is null or empty or not a number.
if (string.IsNullOrEmpty(userInput) || !userInput.All(char.IsDigit))
{
Console.WriteLine("Sorry, but you choose to buy something i dont have!");
continue;
}
//turns the value the player has inputed from string to int.
int id = int.Parse(userInput) - 1;
//checks if the item consists within the list
if (id < 0 || id >= items.Count)
{
Console.WriteLine("Excuse me? are you messing with me?");
continue;
}
RemoveFromStore(id);
if (items.Count <= 0)
{
Console.WriteLine("Sorry but im out of stock.");
return;
}
}
}

private static void InsertItem()
{
items.Add(new Item("Health Restorative", 5, 25));
items.Add(new Item("Mana Restorative", 5, 25));
items.Add(new Item("Health Restorative EX", 10, 50));
items.Add(new Item("Mana Restorative EX", 10, 50));
items.Add(new Item("Cursed Greatsword", 5, 250));
items.Add(new Item("Battle Axe", 5, 250));
items.Add(new Item("Strange Elixir", 50, 50));
items.Add(new Item("Giant Ring", 1, 2500));
items.Add(new Item("Spell: Wrath of the Gods", 1, 25000));
items.Add(new Item("Spell: Hidden Body", 1, 25000));
}

private static void PrintItem()
{
foreach (var i in items)
{
Console.WriteLine(items.IndexOf(i) + 1 + i.ToString());
}
}

public static void RemoveFromStore(int value)
{
if (items[value].stock.Equals(1))
{
items.RemoveAt(value);
return;
}
items[value].stock--;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ItemShop
{
class Program
{
private static List<Item> items = new List<Item>();

static void Main(string[] args)
{
InsertItem();
Console.WriteLine("Greetings Traveller! Care to take a look at my wares?");
while (true)
{
PrintItem();
string userInput = Console.ReadLine();
Console.Clear();
Console.WriteLine("User Input " + userInput);
//verifies if user input is null or empty or not a number.
if (string.IsNullOrEmpty(userInput) || !userInput.All(char.IsDigit))
{
Console.WriteLine("Sorry, but you choose to buy something i dont have!");
continue;
}
//turns the value the player has inputed from string to int.
int id = int.Parse(userInput) - 1;
//checks if the item consists within the list
if (id < 0 || id >= items.Count)
{
Console.WriteLine("Excuse me? are you messing with me?");
continue;
}
RemoveFromStore(id);
if (items.Count <= 0)
{
Console.WriteLine("Sorry but im out of stock.");
return;
}
}
}

private static void InsertItem()
{
items.Add(new Item("Health Restorative", 5, 25));
items.Add(new Item("Mana Restorative", 5, 25));
items.Add(new Item("Health Restorative EX", 10, 50));
items.Add(new Item("Mana Restorative EX", 10, 50));
items.Add(new Item("Cursed Greatsword", 5, 250));
items.Add(new Item("Battle Axe", 5, 250));
items.Add(new Item("Strange Elixir", 50, 50));
items.Add(new Item("Giant Ring", 1, 2500));
items.Add(new Item("Spell: Wrath of the Gods", 1, 25000));
items.Add(new Item("Spell: Hidden Body", 1, 25000));
}

private static void PrintItem()
{
foreach (var i in items)
{
Console.WriteLine(items.IndexOf(i) + 1 + i.ToString());
}
}

public static void RemoveFromStore(int value)
{
if (items[value].stock.Equals(1))
{
items.RemoveAt(value);
return;
}
items[value].stock--;
}
}
}
Program.cs, this is the main file, i turned it into a comment so that it would not break the code due to the itemshop file
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace InventorySystem
{
class InventorySystem
{
static void Main(string[] args)
{

}
}
}
*/
/*
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace InventorySystem
{
class InventorySystem
{
static void Main(string[] args)
{

}
}
}
*/
28 replies