-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from GlockPL/develop
Develop
- Loading branch information
Showing
13 changed files
with
238 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
#include <fstream> | ||
#include <string> | ||
#include <filesystem> | ||
|
||
|
||
class Score | ||
{ | ||
private: | ||
std::string save_file_path = "./score.dat"; | ||
int highScore = 0; | ||
int currentScore = 0; | ||
int level = 1; | ||
public: | ||
Score(/* args */); | ||
~Score(); | ||
int getHighScore(); | ||
int getCurrentScore(); | ||
void setHighScore(int score); | ||
int calculateScore(int linesCleared); | ||
|
||
}; | ||
|
||
Score::Score(/* args */) | ||
{ | ||
if(std::filesystem::exists(save_file_path)) { | ||
std::ifstream rf(save_file_path, std::ios::out | std::ios::binary); | ||
rf.read((char *) &highScore, sizeof(int)); | ||
} | ||
} | ||
|
||
|
||
Score::~Score() | ||
{ | ||
std::ofstream wf(save_file_path, std::ios::out | std::ios::binary); | ||
wf.write((char *) &highScore, sizeof(int)); | ||
} | ||
|
||
void Score::setHighScore(int score) { | ||
highScore = score > highScore ? score : highScore; | ||
} | ||
|
||
int Score::getHighScore() { | ||
return highScore; | ||
} | ||
|
||
int Score::getCurrentScore() { | ||
return currentScore; | ||
} | ||
|
||
int Score::calculateScore(int linesCleared) { | ||
switch (linesCleared) | ||
{ | ||
case 1: | ||
currentScore += 100 * level; | ||
break; | ||
case 2: | ||
currentScore += 300 * level; | ||
break; | ||
case 3: | ||
currentScore += 500 * level; | ||
break; | ||
case 4: | ||
currentScore += 800 * level; | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
setHighScore(currentScore); | ||
|
||
return currentScore; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.