Skip to content

Commit

Permalink
v1.1 hotfix
Browse files Browse the repository at this point in the history
saves with different dimensions (like 4x8 or 7x5) weren't working
  • Loading branch information
k3rielit committed Nov 28, 2020
1 parent 839084a commit a9b3135
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
21 changes: 8 additions & 13 deletions 2048-csharp-cli/2048-csharp-cli/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,27 +251,22 @@ public void Load() {
string fileName = Console.ReadLine();
List<string> file = File.Exists($@"saves\{fileName}.2s") ? File.ReadAllLines($@"saves\{fileName}.2s").ToList() : new List<string>();
// Load
if (fileName != "" && string.Join("",file).Length > 0 && file.Count()-1 >= 4 && file.Count()-1<=8) {
if (fileName != "" && string.Join("",file).Length > 0 && file.Count()-1 >= 4 && file.Count()-1 <= 8) {
int openedScore = 0;
bool valid = int.TryParse(file[0], out openedScore);
file.RemoveAt(0);
int[,] ValuesOpened = new int[file.Count(),file.Count()];
int[,] ValuesOpened = new int[file.Count(),file.First().Split(';').Count()];

int row = 0;
foreach (string line in file) {
int col = 0;
valid = valid && line.Length>0 && line.Split(';').Count() == file.Count();
while(col<file.Count() && valid) {
for(byte row = 0; row <= ValuesOpened.GetUpperBound(0); row++) {
for (byte col = 0; col <= ValuesOpened.GetUpperBound(1) && col < file[row].Split(';').Count(); col++) {
double currentValue = 0;
valid = double.TryParse(line.Split(';')[col], out currentValue) && valid; // try to parse each read item, and if it's possible,
while (currentValue > 2) { // check if it's a possible game number by halving with 2 until it reaches 2.
valid = double.TryParse(file[row].Split(';')[col], out currentValue) && valid; // try to parse each read item, and if it's possible,
while (currentValue > 2) { // check if it's a possible game number by halving with 2 until it reaches 2.
currentValue /= 2;
}
valid = (currentValue == 2 || currentValue == 0) && valid; // setting the valid boolean to true only if it was true before,
ValuesOpened[row, col] = valid ? int.Parse(line.Split(';')[col]) : 0; // to avoid exploits, and set it to false at any incorrect data
col++;
valid = (currentValue == 2 || currentValue == 0) && valid; // setting the valid boolean to true only if it was true before,
ValuesOpened[row, col] = valid ? int.Parse(file[row].Split(';')[col]) : 0; // to avoid exploits, and set it to false at any incorrect data
}
row++;
}

Values = valid ? ValuesOpened : Values; // set the tiles to the new one if the opened file is valid, else keep the current one
Expand Down
12 changes: 7 additions & 5 deletions 2048-csharp-wpf/2048/2048.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<IsWebBootstrapper>true</IsWebBootstrapper>
<PublishUrl>D:\Repos\publishes\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<Install>false</Install>
<InstallFrom>Web</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<AutorunEnabled>true</AutorunEnabled>
<InstallUrl>https://github.com/ahurkatolto/2048/</InstallUrl>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
Expand Down

0 comments on commit a9b3135

Please sign in to comment.