Skip to content

Commit ae8a1b3

Browse files
committed
Implemented local best score
1 parent 3578876 commit ae8a1b3

File tree

9 files changed

+48
-76
lines changed

9 files changed

+48
-76
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/Debug/*
44
/Release/*
55

6-
/libraries/SFML-2.5.1/*
6+
/libraries/*
7+
*.txt

Blockodu.sln

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.32126.315
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Blockodu", "Blockodu.vcxproj", "{3697C652-B6CA-499B-A6B6-6BFCBF770134}"
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Blockudoku", "Blockodu.vcxproj", "{3697C652-B6CA-499B-A6B6-6BFCBF770134}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10-
Debug|x64 = Debug|x64
1110
Debug|x86 = Debug|x86
12-
Release|x64 = Release|x64
1311
Release|x86 = Release|x86
1412
EndGlobalSection
1513
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16-
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Debug|x64.ActiveCfg = Debug|x64
17-
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Debug|x64.Build.0 = Debug|x64
1814
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Debug|x86.ActiveCfg = Debug|Win32
1915
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Debug|x86.Build.0 = Debug|Win32
20-
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Release|x64.ActiveCfg = Release|x64
21-
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Release|x64.Build.0 = Release|x64
2216
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Release|x86.ActiveCfg = Release|Win32
2317
{3697C652-B6CA-499B-A6B6-6BFCBF770134}.Release|x86.Build.0 = Release|Win32
2418
EndGlobalSection

Blockodu.vcxproj

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@
99
<Configuration>Release</Configuration>
1010
<Platform>Win32</Platform>
1111
</ProjectConfiguration>
12-
<ProjectConfiguration Include="Debug|x64">
13-
<Configuration>Debug</Configuration>
14-
<Platform>x64</Platform>
15-
</ProjectConfiguration>
16-
<ProjectConfiguration Include="Release|x64">
17-
<Configuration>Release</Configuration>
18-
<Platform>x64</Platform>
19-
</ProjectConfiguration>
2012
</ItemGroup>
2113
<PropertyGroup Label="Globals">
2214
<VCProjectVersion>16.0</VCProjectVersion>
@@ -40,19 +32,6 @@
4032
<WholeProgramOptimization>true</WholeProgramOptimization>
4133
<CharacterSet>Unicode</CharacterSet>
4234
</PropertyGroup>
43-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
44-
<ConfigurationType>Application</ConfigurationType>
45-
<UseDebugLibraries>true</UseDebugLibraries>
46-
<PlatformToolset>v142</PlatformToolset>
47-
<CharacterSet>Unicode</CharacterSet>
48-
</PropertyGroup>
49-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
50-
<ConfigurationType>Application</ConfigurationType>
51-
<UseDebugLibraries>false</UseDebugLibraries>
52-
<PlatformToolset>v142</PlatformToolset>
53-
<WholeProgramOptimization>true</WholeProgramOptimization>
54-
<CharacterSet>Unicode</CharacterSet>
55-
</PropertyGroup>
5635
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
5736
<ImportGroup Label="ExtensionSettings">
5837
</ImportGroup>
@@ -64,25 +43,13 @@
6443
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
6544
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
6645
</ImportGroup>
67-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
68-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69-
</ImportGroup>
70-
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
71-
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72-
</ImportGroup>
7346
<PropertyGroup Label="UserMacros" />
7447
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7548
<LinkIncremental>true</LinkIncremental>
7649
</PropertyGroup>
7750
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7851
<LinkIncremental>false</LinkIncremental>
7952
</PropertyGroup>
80-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
81-
<LinkIncremental>true</LinkIncremental>
82-
</PropertyGroup>
83-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
84-
<LinkIncremental>false</LinkIncremental>
85-
</PropertyGroup>
8653
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
8754
<ClCompile>
8855
<WarningLevel>Level3</WarningLevel>
@@ -96,7 +63,7 @@
9663
<SubSystem>Console</SubSystem>
9764
<GenerateDebugInformation>true</GenerateDebugInformation>
9865
<AdditionalLibraryDirectories>$(SolutionDir)\libraries\SFML-2.5.1\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
99-
<AdditionalDependencies>winmm.lib;sfml-system-s-d.lib;ws2_32.lib;sfml-network-s-d.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;sfml-audio-s-d.lib;opengl32.lib;gdi32.lib;sfml-window-s-d.lib;freetype.lib;sfml-graphics-s-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
66+
<AdditionalDependencies>winmm.lib;sfml-system-s-d.lib;opengl32.lib;gdi32.lib;sfml-window-s-d.lib;freetype.lib;sfml-graphics-s-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
10067
</Link>
10168
</ItemDefinitionGroup>
10269
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -109,6 +76,8 @@
10976
<ConformanceMode>true</ConformanceMode>
11077
<AdditionalIncludeDirectories>$(SolutionDir)\libraries\SFML-2.5.1\include\;$(SolutionDir)\include\</AdditionalIncludeDirectories>
11178
<MultiProcessorCompilation>true</MultiProcessorCompilation>
79+
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
80+
<FloatingPointModel>Fast</FloatingPointModel>
11281
</ClCompile>
11382
<Link>
11483
<SubSystem>Console</SubSystem>
@@ -119,34 +88,6 @@
11988
<AdditionalDependencies>winmm.lib;sfml-system-s.lib;ws2_32.lib;sfml-network-s.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;sfml-audio-s.lib;opengl32.lib;gdi32.lib;sfml-window-s.lib;freetype.lib;sfml-graphics-s.lib;%(AdditionalDependencies)</AdditionalDependencies>
12089
</Link>
12190
</ItemDefinitionGroup>
122-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
123-
<ClCompile>
124-
<WarningLevel>Level3</WarningLevel>
125-
<SDLCheck>true</SDLCheck>
126-
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
127-
<ConformanceMode>true</ConformanceMode>
128-
</ClCompile>
129-
<Link>
130-
<SubSystem>Console</SubSystem>
131-
<GenerateDebugInformation>true</GenerateDebugInformation>
132-
</Link>
133-
</ItemDefinitionGroup>
134-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
135-
<ClCompile>
136-
<WarningLevel>Level3</WarningLevel>
137-
<FunctionLevelLinking>true</FunctionLevelLinking>
138-
<IntrinsicFunctions>true</IntrinsicFunctions>
139-
<SDLCheck>true</SDLCheck>
140-
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
141-
<ConformanceMode>true</ConformanceMode>
142-
</ClCompile>
143-
<Link>
144-
<SubSystem>Console</SubSystem>
145-
<EnableCOMDATFolding>true</EnableCOMDATFolding>
146-
<OptimizeReferences>true</OptimizeReferences>
147-
<GenerateDebugInformation>true</GenerateDebugInformation>
148-
</Link>
149-
</ItemDefinitionGroup>
15091
<ItemGroup>
15192
<ClCompile Include="src\block.cpp" />
15293
<ClCompile Include="src\game.cpp" />

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ Although precompiled binaries are only available for Windows, the code is cross
77

88
## Building the game
99
1. Clone/download the repo
10-
2. Download SFML 2.5.1 32-bit VS 2017 (from [here](https://www.sfml-dev.org/download/sfml/2.5.1/))
11-
3. Unzip and place the contents in the `libraries` folder.
10+
2. Enter the repo directory
11+
3. Create a folder named `libraries`
12+
4. Download SFML 2.5.1 32-bit VS 2017 (from [here](https://www.sfml-dev.org/download/sfml/2.5.1/))
13+
5. Unzip and place the contents in the `libraries` folder.
1214
(Note: the path should look like this: `repo/libraries/SFML-2.5.1`)
13-
4. Open `Blockudoku.sln` (originally made with Visual Studio 2019)
14-
5. Select the desired configuration (Debug/Release) and build!
15+
6. Windows - Open `Blockudoku.sln` (originally made with Visual Studio 2019)
16+
7. Windows - Select the desired configuration (Debug/Release) and build!

include/score.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class Score : Drawable
1515

1616
float timePlayed = 0;
1717

18+
unsigned localBest = 0;
19+
1820
unsigned score = 0, placed = 0, completionSquares = 0, completionLines = 0;
1921
bool gameLost = false;
2022

include/utilities.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#pragma once
22

3+
#include <sstream>
4+
35
namespace trueRandom
46
{
57
int getNumberInBetween(unsigned a, unsigned b);
68
}
79

810
namespace files
911
{
12+
std::stringstream getFileContents(const std::string& fileName);
1013

14+
void writeToFile(const std::string& text, const std::string& fileName, bool overwrite = true);
1115
}

src/pickupBoard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool PickupBoard::canAnyBlocksBePlaced() {
3838
pickupableBlocks[i]->setOpacity(255);
3939
}
4040
else
41-
pickupableBlocks[i]->setOpacity(160);
41+
pickupableBlocks[i]->setOpacity(128);
4242
}
4343

4444
return canAnyBePlaced;

src/score.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "spacing.h"
55
#include "colors.h"
6+
#include "utilities.h"
67

78
Score::Score() {
89
theFont.loadFromFile("resources/font.ttf");
@@ -27,7 +28,7 @@ void Score::draw(sf::RenderWindow& window) {
2728
}
2829
else {
2930
std::string endGameStatsString = "Game lost, stats: \n Score: " + std::to_string(score) +
30-
"\n Local best: " +
31+
"\n Local best: " + std::to_string(localBest) +
3132
"\n Network best: " +
3233
"\n Blocks used: " + std::to_string(placed) +
3334
"\n Squares: " + std::to_string(completionSquares) +
@@ -49,6 +50,12 @@ void Score::draw(sf::RenderWindow& window) {
4950
void Score::setGameLost() {
5051
gameLost = true;
5152
timePlayed = theClock.getElapsedTime().asSeconds();
53+
54+
auto stream = files::getFileContents("resources/userData.txt");
55+
stream >> localBest;
56+
57+
if (score > localBest)
58+
files::writeToFile(std::to_string(score), "resources/userData.txt");
5259
}
5360

5461
bool Score::getGameState() {

src/utilities.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "utilities.h"
33

44
#include <random>
5+
#include <fstream>
56

67
int trueRandom::getNumberInBetween(unsigned a, unsigned b) {
78
static std::random_device rd; // obtain a random number from hardware
@@ -10,4 +11,24 @@ int trueRandom::getNumberInBetween(unsigned a, unsigned b) {
1011
std::uniform_int_distribution<> distr(a, b); // define the range
1112

1213
return distr(gen);
14+
}
15+
16+
std::stringstream files::getFileContents(const std::string& fileName) {
17+
std::ifstream fin(fileName);
18+
19+
std::stringstream theStream;
20+
theStream << fin.rdbuf();
21+
22+
return theStream;
23+
}
24+
25+
void files::writeToFile(const std::string& text, const std::string& fileName, bool overwrite) {
26+
std::ofstream fout;
27+
28+
if (overwrite)
29+
fout.open(fileName);
30+
else
31+
fout.open(fileName, std::ios_base::app);
32+
33+
fout << text;
1334
}

0 commit comments

Comments
 (0)