From 84bf6d79d7da2cfd011775035745201591f37d3f Mon Sep 17 00:00:00 2001 From: Adam Woodruff Date: Thu, 5 May 2022 17:08:07 -0400 Subject: [PATCH] Added basic saves --- .gitignore | 405 ++++++++++++++++++ App.config | 10 +- Encounters.cs | 2 +- Player.cs | 24 +- Program.cs | 32 +- SaveManager.cs | 26 ++ Shop.cs | 9 + Text Based Game.csproj | 43 +- Text Based Game.sln | 25 ++ ... Based Game.csproj.AssemblyReference.cache | Bin 1212 -> 11 bytes packages.config | 12 + 11 files changed, 566 insertions(+), 22 deletions(-) create mode 100644 .gitignore create mode 100644 SaveManager.cs create mode 100644 Text Based Game.sln create mode 100644 packages.config diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1d96e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,405 @@ +# Created by https://www.toptal.com/developers/gitignore/api/visualstudio +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/visualstudio \ No newline at end of file diff --git a/App.config b/App.config index 56efbc7..7d84477 100644 --- a/App.config +++ b/App.config @@ -1,6 +1,14 @@ - + + + + + + + + + \ No newline at end of file diff --git a/Encounters.cs b/Encounters.cs index 7bf8606..af47ceb 100644 --- a/Encounters.cs +++ b/Encounters.cs @@ -66,7 +66,7 @@ public static void Combat(Enemy enemy) WriteLine("====================="); WriteLine("Potions: " + currentPlayer.potion + " Health: " + currentPlayer.health); string input = ReadKey(true).Key.ToString().ToLower(); - if (input == "a" || input == "attack") + if (input == "a") { // Attack WriteLine(""); diff --git a/Player.cs b/Player.cs index 26818cb..c45624e 100644 --- a/Player.cs +++ b/Player.cs @@ -8,21 +8,21 @@ namespace Text_Based_Game { public class Player { - Random rand = new Random(); + Random rand { get; set; } = new Random(); - public string name; - public int coins = 0; - public int health = 10; // Default Health = 10 - public int damage = 1; // Default Damage = 1 - public int armorValue = 0; - public int potion = 5; - public int weaponValue = 1; // Default weaponValue = 1 + public string name { get; set; } + public int coins { get; set; } = 0; + public int health { get; set; } = 10; // Default Health = 10 + public int damage { get; set; } = 1; // Default Damage = 1 + public int armorValue { get; set; } = 0; + public int potion { get; set; } = 5; + public int weaponValue { get; set; } = 1; // Default weaponValue = 1 - public int nextLevel = 10; - public int level = 1; - public int xp = 0; + public int nextLevel { get; set; } = 10; + public int level { get; set; } = 1; + public int xp { get; set; } = 0; - public int mods = 0; + public int mods { get; set; } = 0; public int GetHealth() { diff --git a/Program.cs b/Program.cs index d98e806..fb65b08 100644 --- a/Program.cs +++ b/Program.cs @@ -18,22 +18,42 @@ static void Main(string[] args) FirstEncounter firstEncounter = new FirstEncounter(); firstEncounter.StartBattle(); - while(mainLoop) + while (mainLoop) { Encounters.RandomEncounter(); } } - + static void Start() { - WriteLine("Text-Based Game\n"); + Clear(); + WriteLine("Generic Text Based RPG - Epic Edition\n"); + WriteLine("(N)ew Game"); + WriteLine("(L)oad Game"); + string input = ReadKey(true).Key.ToString().ToLower(); + if (input == "n") + { + NewGame(); + } + else if (input == "l") + { + currentPlayer = SaveManager.LoadGame(); + Shop.RunShop(currentPlayer); + Clear(); + } + } + + static void NewGame() + { + Clear(); + WriteLine("Generic Text Based RPG - Epic Edition\n"); Write("Name (Optional): "); currentPlayer.name = ReadLine(); Clear(); WriteLine("You awake in a bright field. You're feeling dazed and having trouble remembering what happened.\n"); - if(currentPlayer.name == "") + if (currentPlayer.name == "") WriteLine("You can't even remember your own name..."); - else + else WriteLine("You remember that your name is " + currentPlayer.name + "."); WriteLine("(Press any key to continue)"); ReadKey(); @@ -41,4 +61,4 @@ static void Start() WriteLine("You wander around in the fields till you find a creature."); } } -} +} \ No newline at end of file diff --git a/SaveManager.cs b/SaveManager.cs new file mode 100644 index 0000000..67a405c --- /dev/null +++ b/SaveManager.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Text_Based_Game +{ + public class SaveManager + { + public static Player LoadGame() + { + FileStream save = File.OpenRead(Directory.GetCurrentDirectory() + "\\save.json"); + Player player = JsonSerializer.Deserialize(save); + save.Close(); + return player; + } + + public static void SaveGame(Player player) + { + File.WriteAllText(Directory.GetCurrentDirectory() + "\\save.json", JsonSerializer.Serialize(player)); + } + } +} diff --git a/Shop.cs b/Shop.cs index 3d2cfbb..fc5c9ec 100644 --- a/Shop.cs +++ b/Shop.cs @@ -34,6 +34,7 @@ public static void RunShop(Player player) WriteLine("(S)tats"); WriteLine("====================="); WriteLine("(E)xit"); + WriteLine("Save and (Q)uit"); WriteLine("====================="); string input = ReadKey(true).Key.ToString().ToLower(); @@ -58,7 +59,14 @@ public static void RunShop(Player player) StatsScreen(player); } else if (input == "e") + { break; + } + else if (input == "q") + { + SaveManager.SaveGame(Program.currentPlayer); + Environment.Exit(0); + } } } @@ -92,6 +100,7 @@ static void StatsScreen(Player player) WriteLine("====================="); WriteLine(" Player Stats "); WriteLine("====================="); + WriteLine("Player Name: " + player.name); WriteLine("Current Health: " + player.health); WriteLine("Coins: " + player.coins); WriteLine("Weapon Strength: " + player.weaponValue); diff --git a/Text Based Game.csproj b/Text Based Game.csproj index a8143cb..daa31ec 100644 --- a/Text Based Game.csproj +++ b/Text Based Game.csproj @@ -7,12 +7,14 @@ AnyCPU {C8A118DD-F815-4EC5-BD2A-277A8EB2B875} Exe - Text_Based_Game - Text Based Game + Generic_Text_Based_RPG_Epic_Edition + Generic Text-Based RPG - Epic Edition v4.7.2 512 true true + + AnyCPU @@ -34,8 +36,36 @@ 4 + + packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll + + + packages\System.Text.Json.6.0.3\lib\net461\System.Text.Json.dll + + + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + @@ -54,10 +84,19 @@ + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Text Based Game.sln b/Text Based Game.sln new file mode 100644 index 0000000..21fba97 --- /dev/null +++ b/Text Based Game.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32228.343 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Text Based Game", "Text Based Game.csproj", "{C8A118DD-F815-4EC5-BD2A-277A8EB2B875}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C8A118DD-F815-4EC5-BD2A-277A8EB2B875}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8A118DD-F815-4EC5-BD2A-277A8EB2B875}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8A118DD-F815-4EC5-BD2A-277A8EB2B875}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8A118DD-F815-4EC5-BD2A-277A8EB2B875}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {13DF82DF-C141-49D4-8E22-FE292E60F933} + EndGlobalSection +EndGlobal diff --git a/obj/Debug/Text Based Game.csproj.AssemblyReference.cache b/obj/Debug/Text Based Game.csproj.AssemblyReference.cache index 661843ab622f16d0d86f086b4814548d0f0adbf9..f5e894aea93a73e58fa9d4feab241bc197ee1a40 100644 GIT binary patch literal 11 QcmeZu3JP{+WMlvW01Ze1dH?_b literal 1212 zcmeZu3JP{+WaMOEU|>viwu%WT%1 + + + + + + + + + + + \ No newline at end of file