Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
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; using Engine; namespace SuperAdventure { public partial class SuperAdventure : Form { private Player _player; private Monster _currentMonster; private HealingPotion _healingPotion; public SuperAdventure() { InitializeComponent(); _player = new Player(10, 10, 20, 0); MoveTo(World.LocationByID(World.LOCATION_ID_HOME)); _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1)); _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_HEALING_POTION), 1)); UpdateInventoryListInUI(); //shows weapon at the beginning, if any UpdatePotionListInUI(); //shows potion at the beginning, if any UpdatePlayerStats(); //shows current stats at the beginning } private void btnNorth_Click(object sender, EventArgs e) { MoveTo(_player.CurrentLocation.LocationToNorth); } private void btnEast_Click(object sender, EventArgs e) { MoveTo(_player.CurrentLocation.LocationToEast); } private void btnSouth_Click(object sender, EventArgs e) { MoveTo(_player.CurrentLocation.LocationToSouth); } private void btnWest_Click(object sender, EventArgs e) { MoveTo(_player.CurrentLocation.LocationToWest); } public void MoveTo(Location newLocation) { if (!_player.HasRequiredItemToEnterThisLocation(newLocation)) { ScrollToBottomOfMessages(); rtbMessages.Text += "You must have a/an " + newLocation.ItemRequiredToEnter.Name + " to enter this location." + Environment.NewLine; return; } //Update the player's current location _player.CurrentLocation = newLocation; //Show/hide available movement buttons btnNorth.Visible = (newLocation.LocationToNorth != null); btnEast.Visible = (newLocation.LocationToEast != null); btnSouth.Visible = (newLocation.LocationToSouth != null); btnWest.Visible = (newLocation.LocationToWest != null); //Display current location name and description rtbLocation.Text = newLocation.Name + Environment.NewLine; rtbLocation.Text += newLocation.Description + Environment.NewLine; //Does the location have a quest? if (newLocation.QuestAvailableHere != null) { //see if the player already has the quest, and if they've completed it bool playerAlreadyHasQuest = _player.HasThisQuest(newLocation.QuestAvailableHere); bool playerAlreadyHasCompletedQuest = _player.CompletedThisQuest(newLocation.QuestAvailableHere); //See if the player already has the quest if (playerAlreadyHasQuest) { //if the player has not completed the quest yet if (!playerAlreadyHasCompletedQuest) { //See if the player has all the items needed to complete the quest bool playerHasAllTheItemsToCompleteQuest = _player.HasAllQuestCompletionItems(newLocation.QuestAvailableHere); if (playerHasAllTheItemsToCompleteQuest) { //display message ScrollToBottomOfMessages(); rtbMessages.Text += Environment.NewLine; ScrollToBottomOfMessages(); rtbMessages.Text += "You complete the " + "«" + newLocation.QuestAvailableHere.Name + "»" + " quest." + Environment.NewLine; //remove quest items from inventory _player.RemoveQuestCompletionItems(newLocation.QuestAvailableHere); //give quest rewards ScrollToBottomOfMessages(); rtbMessages.Text += "You receive: " + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardExperiencePoints.ToString() + " experience points" + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardGold.ToString() + " gold" + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.RewardItem.Name + Environment.NewLine; rtbMessages.Text += Environment.NewLine; _player.ExperiencePoints += newLocation.QuestAvailableHere.RewardExperiencePoints; _player.Gold += newLocation.QuestAvailableHere.RewardGold; //Add reward item to the player's inventory _player.AddItemToInventory(newLocation.QuestAvailableHere.RewardItem); //mark the quest as completed _player.MarkQuestCompleted(newLocation.QuestAvailableHere); //Update UI text UpdateInventoryListInUI(); UpdatePotionListInUI(); lblGold.Text = _player.Gold.ToString(); lblExperience.Text = _player.ExperiencePoints.ToString(); } } } else { //the player does not already have the quest //display messages ScrollToBottomOfMessages(); rtbMessages.Text += "You receive the " + "«" + newLocation.QuestAvailableHere.Name + "»" + " quest." + Environment.NewLine; rtbMessages.Text += newLocation.QuestAvailableHere.Description + Environment.NewLine; rtbMessages.Text += "To complete it, return with: " + Environment.NewLine; foreach (QuestCompletionItem qci in newLocation.QuestAvailableHere.QuestCompletionItems) { if (qci.Quantity == 1) { ScrollToBottomOfMessages(); rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.Name + Environment.NewLine; } else { ScrollToBottomOfMessages(); rtbMessages.Text += qci.Quantity.ToString() + " " + qci.Details.NamePlural + Environment.NewLine; } } ScrollToBottomOfMessages(); rtbMessages.Text += Environment.NewLine; //Add the quest to the player quest's list _player.Quests.Add(new PlayerQuest(newLocation.QuestAvailableHere)); } } //Does the location have a monster? if (newLocation.MonsterLivingHere != null) { ScrollToBottomOfMessages(); rtbMessages.Text += "You see a " + newLocation.MonsterLivingHere.Name + "." + Environment.NewLine; //make a new monster, using the values from the standard monster in the World.Monster list Monster standardMonster = World.MonsterByID(newLocation.MonsterLivingHere.ID); _currentMonster = new Monster(standardMonster.ID, standardMonster.Name, standardMonster.MaximumDamage, standardMonster.RewardExperiencePoints, standardMonster.RewardGold, standardMonster.CurrentHitPoints, standardMonster.MaximumHitPoints); foreach (LootItem lootItem in standardMonster.LootTable) { _currentMonster.LootTable.Add(lootItem); } cboWeapons.Visible = true; btnUseWeapon.Visible = true; } else { _currentMonster = null; cboWeapons.Visible = false; btnUseWeapon.Visible = false; } //refresh player's inventory list UpdateInventoryListInUI(); //refresh player's quest list UpdateQuestListInUI(); //refresh player's weapons combobox UpdateWeaponsListInUI(); //refresh player's potion combobox UpdatePotionListInUI(); } private void UpdateInventoryListInUI() { dgvInventory.RowHeadersVisible = false; dgvInventory.ColumnCount = 2; dgvInventory.Columns[0].Name = "Name"; dgvInventory.Columns[0].Width = 209; dgvInventory.Columns[1].Name = "Quantity"; dgvInventory.Rows.Clear(); foreach (InventoryItem inventoryItem in _player.Inventory) { if (inventoryItem.Quantity > 0) { dgvInventory.Rows.Add(new[] { inventoryItem.Details.Name, inventoryItem.Quantity.ToString() }); } } } private void UpdateQuestListInUI() { dgvQuests.RowHeadersVisible = false; dgvQuests.ColumnCount = 2; dgvQuests.Columns[0].Name = "Name"; dgvQuests.Columns[0].Width = 209; dgvQuests.Columns[1].Name = "Cleared?"; dgvQuests.Rows.Clear(); foreach (PlayerQuest playerQuest in _player.Quests) { if (playerQuest.IsCompleted) { dgvQuests.Rows.Add(new[] { playerQuest.Details.Name, "Yes" }); } else { dgvQuests.Rows.Add(new[] { playerQuest.Details.Name, "No" }); } } } private void UpdateWeaponsListInUI() { List<Weapon> weapons = new List<Weapon>(); foreach (InventoryItem inventoryItem in _player.Inventory) { if (inventoryItem.Details is Weapon) { if (inventoryItem.Quantity > 0) { weapons.Add((Weapon)inventoryItem.Details); } } } if (weapons.Count == 0) { //the player has no weapons, hide the combobox and "use" button cboWeapons.Visible = false; btnUseWeapon.Visible = false; } else { cboWeapons.DataSource = weapons; cboWeapons.DisplayMember = "Name"; cboWeapons.ValueMember = "ID"; cboWeapons.SelectedIndex = 0; } } private void UpdatePotionListInUI() { List<HealingPotion> healingPotions = new List<HealingPotion>(); foreach (InventoryItem inventoryItem in _player.Inventory) { if (inventoryItem.Details is HealingPotion) { if (inventoryItem.Quantity > 0) { healingPotions.Add((HealingPotion)inventoryItem.Details); } } } if (healingPotions.Count == 0) { //the player does not have any potions, hide the combobox and "use button cboPotions.Visible = false; btnUsePotion.Visible = false; } else { cboPotions.Visible = true; btnUsePotion.Visible = true; cboPotions.DataSource = healingPotions; cboPotions.DisplayMember = "Name"; cboPotions.ValueMember = "ID"; cboPotions.SelectedIndex = 0; } } private void UpdatePlayerStats() { // Refresh player information and inventory controls lblHitPoints.Text = _player.CurrentHitPoints.ToString(); lblGold.Text = _player.Gold.ToString(); lblExperience.Text = _player.ExperiencePoints.ToString(); lblLevel.Text = _player.Level.ToString(); } private void btnUseWeapon_Click(object sender, EventArgs e) { //get the currently selected weapon from cboWeapons combobox Weapon currentWeapon = (Weapon)cboWeapons.SelectedItem; //Determine the amount of damage to do to the monster int damageToMonster = RandomNumberGenerator.NumberBetween(currentWeapon.MinimumDamage, currentWeapon.MaximumDamage); //apply damage to monster's currenthitpoints _currentMonster.CurrentHitPoints -= damageToMonster; //display message ScrollToBottomOfMessages(); rtbMessages.Text += "You hit the " + _currentMonster.Name + " for " + damageToMonster.ToString() + " points." + Environment.NewLine; //check if the monster is dead if (_currentMonster.CurrentHitPoints <= 0) { //Monster is dead ScrollToBottomOfMessages(); rtbMessages.Text += Environment.NewLine; rtbMessages.Text += "You defeated the " + _currentMonster.Name + "." + Environment.NewLine; btnUseWeapon.Visible = false; cboWeapons.Visible = false; //Give player experience for killing the monster _player.ExperiencePoints += _currentMonster.RewardExperiencePoints; ScrollToBottomOfMessages(); rtbMessages.Text += "You receive " + _currentMonster.RewardExperiencePoints.ToString() + " experience points." + Environment.NewLine; //Give player gold for killing the monster _player.Gold += _currentMonster.RewardGold; if (_currentMonster.RewardGold == 1) { ScrollToBottomOfMessages(); rtbMessages.Text += "You get " + _currentMonster.RewardGold.ToString() + " piece of gold." + Environment.NewLine; } else { ScrollToBottomOfMessages(); rtbMessages.Text += "You get " + _currentMonster.RewardGold.ToString() + " pieces of gold." + Environment.NewLine; } //get random loot items from the monster List<InventoryItem> lootedItems = new List<InventoryItem>(); //Add items to the lootedItems list, comparing a random number to the drop percentage foreach (LootItem lootItem in _currentMonster.LootTable) { if (RandomNumberGenerator.NumberBetween(1, 100) <= lootItem.DropPercentage) { lootedItems.Add(new InventoryItem(lootItem.Details, 1)); } } //if no items were randomly selected, then add the default loot item(s) if (lootedItems.Count == 0) { foreach (LootItem lootItem in _currentMonster.LootTable) { if (lootItem.IsDefaultItem) { lootedItems.Add(new InventoryItem(lootItem.Details, 1)); } } } //add the looted items to the player's inventory foreach (InventoryItem inventoryItem in lootedItems) { _player.AddItemToInventory(inventoryItem.Details); if (inventoryItem.Quantity == 1) { ScrollToBottomOfMessages(); rtbMessages.Text += "You loot " + inventoryItem.Quantity.ToString() + " " + inventoryItem.Details.Name + Environment.NewLine; } else { ScrollToBottomOfMessages(); rtbMessages.Text += "You loot " + inventoryItem.Quantity.ToString() + inventoryItem.Details.NamePlural + Environment.NewLine; } } //refresh player information and inventory controls UpdatePlayerStats(); UpdateInventoryListInUI(); UpdateWeaponsListInUI(); UpdatePotionListInUI(); _currentMonster = null; } else { //monster is still alive //determine the amount of damage the monster does to the player int damageToPlayer = RandomNumberGenerator.NumberBetween(1, _currentMonster.MaximumDamage); //display message ScrollToBottomOfMessages(); rtbMessages.Text += "The " + _currentMonster.Name + " did " + damageToPlayer.ToString() + " points of damage." + Environment.NewLine; //subtract damage from player _player.CurrentHitPoints -= damageToPlayer; //refresh player data in UI lblHitPoints.Text = _player.CurrentHitPoints.ToString(); if (_player.CurrentHitPoints <= 0) { ScrollToBottomOfMessages(); rtbMessages.Text += "The " + _currentMonster.Name + " killed you." + Environment.NewLine; ResetByDeath(); } } } private void btnUsePotion_Click(object sender, EventArgs e) { //get the currently selected potion from the combobox HealingPotion potion = (HealingPotion)cboPotions.SelectedItem; //Add healing amount to the player's current hit points _player.CurrentHitPoints += potion.AmountToHeal; //current hit points cannot exceed player's max hit points if (_player.CurrentHitPoints > _player.MaximumHitPoints) { _player.CurrentHitPoints = _player.MaximumHitPoints; } //remove the potion from the player's inventory foreach (InventoryItem ii in _player.Inventory) { if (ii.Details.ID == potion.ID) { ii.Quantity--; break; } } //display message ScrollToBottomOfMessages(); rtbMessages.Text += "You drink a " + potion.Name + " that replenishes " + potion.AmountToHeal.ToString() + " hit points." + Environment.NewLine; if (_currentMonster != null) { //monster gets their turn to attack //determine the amount of damage the monster does to the player int damageToPlayer = RandomNumberGenerator.NumberBetween(0, _currentMonster.MaximumDamage); //display message ScrollToBottomOfMessages(); rtbMessages.Text += "The " + _currentMonster.Name + " did " + damageToPlayer.ToString() + " points of damage." + Environment.NewLine; //subtract damage from player _player.CurrentHitPoints -= damageToPlayer; if (_player.CurrentHitPoints <= 0) { ScrollToBottomOfMessages(); rtbMessages.Text += "The " + _currentMonster.Name + " killed you." + Environment.NewLine; ResetByDeath(); } } //refresh player data in UI lblHitPoints.Text = _player.CurrentHitPoints.ToString(); UpdateInventoryListInUI(); UpdatePotionListInUI(); } public void ResetByDeath() { List<PlayerQuest> previousQuests = _player.Quests; List<InventoryItem> previousInventory = _player.Inventory; List<InventoryItem> itemsToEnterPlaces = new List<InventoryItem>(); foreach (InventoryItem ii in previousInventory) { foreach (Location location in World.Locations) { if(location.ItemRequiredToEnter != null) { if(ii.Details == location.ItemRequiredToEnter) { itemsToEnterPlaces.Add(ii); //stores items that are required to enter locations } } } } _player = new Player(_player.CurrentHitPoints, _player.MaximumHitPoints, 20, _player.ExperiencePoints); _player.CurrentHitPoints = _player.MaximumHitPoints; _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_RUSTY_SWORD), 1)); _player.Inventory.Add(new InventoryItem(World.ItemByID(World.ITEM_ID_HEALING_POTION), 1)); foreach(InventoryItem item in itemsToEnterPlaces) { _player.Inventory.Add(item); //keeps only items that are required to enter places } _player.Quests = previousQuests; //keeps quest list and quests done when you die UpdateInventoryListInUI(); UpdatePotionListInUI(); UpdateQuestListInUI(); MoveTo(World.LocationByID(World.LOCATION_ID_HOME)); UpdatePlayerStats(); ScrollToBottomOfMessages(); rtbMessages.Text += Environment.NewLine + Environment.NewLine + Environment.NewLine; } private void ScrollToBottomOfMessages() { rtbMessages.SelectionStart = rtbMessages.Text.Length; rtbMessages.ScrollToCaret(); } } }
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
C | 1 min ago
[SQL] Same IP coun...
Pawn | 20 min ago
ASCII tree printer...
C++ | 28 min ago
ATM
Java | 28 min ago
Untitled
C++ | 30 min ago
Untitled
C++ | 32 min ago
Untitled
C | 42 min ago
Untitled
Ruby | 43 min ago
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!