Skip to content

Commit

Permalink
Added basic saves
Browse files Browse the repository at this point in the history
  • Loading branch information
TraceEntertains committed May 5, 2022
1 parent b830f5e commit 84bf6d7
Show file tree
Hide file tree
Showing 11 changed files with 566 additions and 22 deletions.
405 changes: 405 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
2 changes: 1 addition & 1 deletion Encounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
Expand Down
24 changes: 12 additions & 12 deletions Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
32 changes: 26 additions & 6 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,47 @@ 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();
Clear();
WriteLine("You wander around in the fields till you find a creature.");
}
}
}
}
26 changes: 26 additions & 0 deletions SaveManager.cs
Original file line number Diff line number Diff line change
@@ -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<Player>(save);
save.Close();
return player;
}

public static void SaveGame(Player player)
{
File.WriteAllText(Directory.GetCurrentDirectory() + "\\save.json", JsonSerializer.Serialize(player));
}
}
}
9 changes: 9 additions & 0 deletions Shop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}

}
}
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 41 additions & 2 deletions Text Based Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C8A118DD-F815-4EC5-BD2A-277A8EB2B875}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Text_Based_Game</RootNamespace>
<AssemblyName>Text Based Game</AssemblyName>
<RootNamespace>Generic_Text_Based_RPG_Epic_Edition</RootNamespace>
<AssemblyName>Generic Text-Based RPG - Epic Edition</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -34,8 +36,36 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=6.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Json.6.0.3\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -54,10 +84,19 @@
<Compile Include="Player.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SaveManager.cs" />
<Compile Include="Shop.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\System.Text.Json.6.0.3\build\System.Text.Json.targets" Condition="Exists('packages\System.Text.Json.6.0.3\build\System.Text.Json.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\System.Text.Json.6.0.3\build\System.Text.Json.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\System.Text.Json.6.0.3\build\System.Text.Json.targets'))" />
</Target>
</Project>
25 changes: 25 additions & 0 deletions Text Based Game.sln
Original file line number Diff line number Diff line change
@@ -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
Binary file modified obj/Debug/Text Based Game.csproj.AssemblyReference.cache
Binary file not shown.
12 changes: 12 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net472" />
<package id="System.Buffers" version="4.5.1" targetFramework="net472" />
<package id="System.Memory" version="4.5.4" targetFramework="net472" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net472" />
<package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net472" />
<package id="System.Text.Json" version="6.0.3" targetFramework="net472" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages>

0 comments on commit 84bf6d7

Please sign in to comment.