1 — Furniture shop game

Icodewithben
5 min readNov 20, 2023

--

Create a visual studio windows form app

Create the GUI understand visual studio

Create oop objects

Video for explanation of how to get started on this and understand OOP in terms of a GUI in Visual Studio: https://youtu.be/FlhfnMKfXuM get VS from here Download Visual Studio Tools — Install Free for Windows, Mac, Linux (microsoft.com)

To help practice OOP and GUI development project using Windows Forms in Visual Studio, will focus on creating a game to manage a furniture shop in which you have the opportunity to create lots of classes, use inheritance and encapsulation and polymorphism, but then make the data in each of these classes interactable and updatable.

What the furniture game should do:

Random Customer Purchases:

  • Each turn, the game randomly determines how much money the computer-controlled customer has available to spend.
  • The number of items the customer can buy depends on their budget and the prices of the items.

Shop Overheads and Stock Management:

  • The game includes a fixed overhead cost of £1000 per month for the shop.
  • Additional overheads are calculated as 20% of the retail price of each item in stock. This encourages inventory management, as having too much unsold stock increases costs.

Variable Customer Financial Situations:

  • Occasionally, the computer-controlled customer might inherit money or receive a pay raise, increasing their spending power for a period.
  • This variability adds an element of unpredictability to the game.

Dynamic Pricing Strategy:

  • The shop can adjust the prices of its furniture to encourage sales. However, reducing prices will decrease the profit margin.
  • This aspect introduces strategic decision-making regarding pricing.

Investment and Expansion:

  • The more the shop invests in diverse furniture items, the more options the customer has, potentially increasing sales.
  • Balancing investment in inventory with the risk of increased overheads is a key challenge.

Profit Management:

  • The ultimate goal is to keep the shop profitable despite the overheads, varying customer spending habits, and market dynamics.
  • The game could include a financial statement feature to help players track their shop’s performance.

Game Progression and Difficulty Levels:

  • As the game progresses, new challenges and opportunities can be introduced, such as seasonal demand variations, economic downturns, or competition.
  • Different difficulty levels can adjust factors like customer spending habits, overhead costs, and market trends.

Create a New Windows Forms Project:

  • Open Visual Studio and choose “Create a new project.”
  • Select “Windows Forms App (.NET Framework)” from the list of templates.
  • Name your project (e.g., FurnitureShop) and choose a location to save it.
  • Click “Create” to generate the project.

Creating the GUI:

Make your design in your furniture shop look a bit like this:

With the Form selected you can see the toolbox:

Add the items to make it look like this:

Final design look

Set the label on buttons or other components by editing the Text in the properties:

Set the ID of the component by setting the (Name). This is how you refer to components in the code by using the id, and then you can get the text or you can set its values (like in a listbox):

Designing Basic Classes

  1. Create the `Furniture` Class:
  • Right-click on the project in Solution Explorer, select Add -> Class, and name it `Furniture.cs`.
  • Define properties like `string Name`, `decimal Price`
  • Create some subclasses of Furniture like chair, table, carpet etc. give these different private properties and functions.

Code for furniture:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureShopLesson1
{
class Furniture
{
string name;
int price;
public Furniture(string name, int price)
{
this.name = name;
this.price = price;
}
public string getName()
{
return name;
}
public int getPrice()
{
return price;
}
}
}

Creating the code for the view, watch the video for an explanation but here is the final code for view:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FurnitureShopLesson1
{
public partial class Form1 : Form
{

Furniture[] furnitureItems = new Furniture[100];
int furnitureNum = 0;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void pressButton_Click(object sender, EventArgs e)
{
string name = nameField.Text;
int price = int.Parse(priceField.Text);

if(furnitureNum < 100)
{
Furniture newItem = new Furniture(name, price);
furnitureItems[furnitureNum] = newItem;
furnitureNum++;
furnitureListBox.Items.Add(newItem.getName() + " £" + newItem.getPrice());
}

}
}
}

EXTRA:

1. Create the `Building` Class:

  • Create a Building class that has common properties between them all buildings
  • Extend this to their is a subclass `Shop.cs`.
  • Inside the Shop class, create a list to store Furniture items: `List<Furniture> Inventory`.
  • Create a function called AddInventory, this function will add furniture items to the list of furniture in the shops.
  • Add a new list called Inventory to your Form, and a new button called “Add to Inventory”. Whenever the user clicks the button it will add whatever Item they have chosen from the furniture list, you will need to add some furniture items first.

2. Create the `User` Class and Subclasses:

  • Add a new class `User.cs` with common properties like `string Name` and `decimal Balance`
  • Create two subclasses, `Customer` and `ShopOwner`, that inherit from `User`
  • In `Customer.cs`, add methods specific to a customer (e.g., `BuyFurniture`)
  • In `ShopOwner.cs`, add methods specific to a shop owner (e.g., `StockShop`).
  • Whenever the furniture shop owner clicks “Add to Inventory” button their balance will be deducted by the price of that item
  • Whenever a customer buys and item their balance will be deducted by the price of the item (this is controlled by the computer on each turn), but if they buy an item it is added to their purchase list.

--

--