Winform RPG Tutorial
“WinForms RPG Story Game App”
Level: Beginner
Objective:
In this assignment, you will create a Windows Forms application (WinForms) that functions as an interactive RPG story game. The app will allow users to navigate through a text-based story, display images, and interact with choices. The information will be stored in a text file, which the app will read from and write to. This project introduces file handling, UI development, variables, functions, lists, and arrays in Visual Studio.
Step 1: Project Theme & Team Formation
Choose Your App Theme:
App Concept: Your task is to create an interactive “RPG Story Game App” where users can progress through a story by reading text and making choices. The app will also display images based on the story and allow users to save and modify the story text.
Example Theme Ideas:
- A space adventure where users explore planets and make key decisions.
- A medieval fantasy quest where players choose their path.
- A cyberpunk mystery with links to evidence images.
Team Formation:
Form a team and assign roles:
- Story Writer: Designs the narrative and flow.
- UI Designer: Creates the layout and interactions.
- Programmer: Implements the logic and functionality.
- Media Manager: Adds images and other resources.
Use a whiteboard to organize your tasks and plan deadlines.
Step 2: Understanding Variables, Functions, Lists, and Arrays
Before implementing the code, you must understand key programming concepts:
- Variables: Store data (e.g., strings, numbers).
- Functions: Reusable blocks of code.
- Lists & Arrays: Store multiple values in an ordered format.
Step 3: Start Your Visual Studio Project
Open Visual Studio:
- Create a Windows Forms App (.NET Framework) project.
- Name it based on your story theme (e.g., “RPGStoryApp”).
Set Up Your Project Structure:
- Create a folder named Assets for images.
- Add a text file named story.txt in the project directory.
- Save your project frequently.
Step 4: Implement the Code with Guided Errors
story.txt
[Title] The Lost Artifact
[Intro] You are an adventurer searching for the legendary Lost Artifact. Your journey begins in the ancient ruins.
[Image] https://example.com/ruins.jpg
[Choice] Explore the temple > temple
[Choice] Search the nearby forest > forest
[Section] temple
[Text] You step into the dark temple, torches flickering on the walls. You hear a strange noise echoing through the halls.
[Image] https://example.com/temple.jpg
[Choice] Follow the sound > sound
[Choice] Light a torch and proceed cautiously > cautious
[Section] forest
[Text] The dense forest surrounds you. Strange symbols are carved into the trees. A hidden path lies ahead.
[Image] https://example.com/forest.jpg
[Choice] Follow the hidden path > path
[Choice] Examine the carvings > carvings
[Section] sound
[Text] You follow the sound and discover an underground chamber. Inside, a golden artifact glows on a pedestal.
[Image] https://example.com/chamber.jpg
[Choice] Take the artifact > take
[Choice] Leave the chamber > leave
[Section] cautious
[Text] You move cautiously and find a hidden lever on the wall. Pulling it reveals a secret passage.
[Image] https://example.com/passage.jpg
[Choice] Enter the passage > passage
[Choice] Ignore and continue > continue
[Section] path
[Text] The path leads you to an ancient stone door covered in vines. It appears to be locked.
[Image] https://example.com/door.jpg
[Choice] Try to open the door > door
[Choice] Go back to the ruins > back
[Section] carvings
[Text] The carvings depict a prophecy about the Lost Artifact. They reveal the location of a hidden key.
[Image] https://example.com/carvings.jpg
[Choice] Search for the key > key
[Choice] Ignore and continue exploring > explore
Example Code with Missing Elements
using System;
using System.IO;
using System.Windows.Forms;
using System.Collections.Generic; // Needed for Lists
namespace RPGStoryApp
{
public partial class MainForm : Form
{
// Here is an error: Variable not declared
// Declare a string variable to store the file path
private string filePath = "story.txt";
// Here is an error: List of story text is missing
// Create a list to store lines of the story
private List<string> storyLines;
public MainForm()
{
InitializeComponent();
LoadStory(); // Here is an error: Function LoadStory() is missing. Implement it below.
}
private void LoadStory()
{
if (File.Exists(filePath))
{
storyLines = new List<string>(File.ReadAllLines(filePath));
storyTextBox.Text = string.Join("\n", storyLines);
}
else
{
storyTextBox.Text = "No story found. Please create one.";
}
}
private void SaveStory()
{
// Here is an error: The function is not updating storyLines before saving
storyLines = new List<string>(storyTextBox.Lines);
File.WriteAllText(filePath, string.Join("\n", storyLines));
MessageBox.Show("Story saved successfully!");
}
private void ShowImageFromLink()
{
// Here is an error: A function needs to extract image links from text
foreach (string line in storyTextBox.Lines)
{
if (line.StartsWith("[Image] "))
{
string url = line.Replace("[Image] ", "");
System.Diagnostics.Process.Start(url);
}
}
}
private void nextButton_Click(object sender, EventArgs e)
{
// Here is an error: Function ShowImageFromLink() should be called
ShowImageFromLink();
}
private void saveButton_Click(object sender, EventArgs e)
{
// Here is an error: Function SaveStory() should be called
SaveStory();
}
}
}
Step 5: Debug the Application
Find and Fix Errors:
- Declare missing variables.
- Implement missing functions.
- Fix incorrect function calls.
- Correct list usage.
Testing Steps:
- Run the application and verify that the text file loads correctly.
- Test the Save feature by editing the text and saving.
- Add an image link like
[Image] http://example.com/image.jpg
in the text file and test if it opens in the browser.
Debugging Tips:
- Use
MessageBox.Show()
to display variable values for troubleshooting. - Ensure the
story.txt
file is located in the correct directory.
Step 6: Add Enhancements
Adding More Multimedia:
- Sounds: Use
System.Media.SoundPlayer
to add background music. - Multiple Images: Extend the
ShowImageFromLink()
method to handle multiple images.
Implementing Choices & Branching:
- Modify the text file format to include
[Choice]
tags. - Based on user selection, update
storyTextBox
accordingly.
Step 7: Create a Tutorial Presentation
Prepare a PowerPoint presentation covering:
- App Overview: What the app does.
- User Flowchart: How users navigate the story.
- UI Design: Screenshots and explanations.
- Code Explanation: Key logic in the app.
- Enhancements: Ideas for future improvements.
Step 8: Final Submission
Save & Zip Project:
- Ensure your project runs without errors.
- Zip the entire project folder.
- Include a
README.txt
explaining how to use the app.
Upload to Canvas & Discord:
- Submit the project on Canvas.
- Share screenshots or a short demo video in your team’s Discord channel.
Evaluation Criteria:
Category | Check list |
---|---|
Functionality | |
UI Design | |
Code Quality | |
Creativity | |
Collaboration | |
Debugging Effort | |
Documentation | |
Fun Factor | |
Team Formation |