Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
1
142GameCenter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nelson Phillips
142GameCenter
Commits
fcbdfbab
Commit
fcbdfbab
authored
Mar 11, 2019
by
Konrad McClure
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.cs.wallawalla.edu:philne/142gamecenter
parents
91e3b5f0
97b8f0e2
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
278 additions
and
5 deletions
+278
-5
Testings/Kyle's Folder/2048Data.txt
Testings/Kyle's Folder/2048Data.txt
+6
-0
Testings/Kyle's Folder/SL2048.cpp
Testings/Kyle's Folder/SL2048.cpp
+43
-0
Testings/Kyle's Folder/SL2048.h
Testings/Kyle's Folder/SL2048.h
+22
-0
Testings/Kyle's Folder/SLSnake.cpp
Testings/Kyle's Folder/SLSnake.cpp
+41
-0
Testings/Kyle's Folder/SLSnake.h
Testings/Kyle's Folder/SLSnake.h
+22
-0
Testings/Kyle's Folder/SaveLoad.cpp
Testings/Kyle's Folder/SaveLoad.cpp
+24
-0
Testings/Kyle's Folder/SaveLoad.h
Testings/Kyle's Folder/SaveLoad.h
+23
-5
Testings/Kyle's Folder/Scores.h
Testings/Kyle's Folder/Scores.h
+26
-0
Testings/Kyle's Folder/main.cpp
Testings/Kyle's Folder/main.cpp
+64
-0
Testings/Kyle's Folder/snakedata.txt
Testings/Kyle's Folder/snakedata.txt
+7
-0
No files found.
Testings/Kyle's Folder/2048Data.txt
0 → 100644
View file @
fcbdfbab
NAME SCORE DATE
Kyle2 10000 2/23/19
kyle4 2334 2/26/19
Kyle3 2000 2/24/19
Kyle1 1000 2/22/19
Kyle 100 2/22/19
\ No newline at end of file
Testings/Kyle's Folder/SL2048.cpp
0 → 100644
View file @
fcbdfbab
#include "SL2048.h"
void
SL2048
::
LoadContainers
(){
ifstream
fin
;
fin
.
open
(
"2048Data.txt"
);
if
(
!
fin
.
is_open
()){
cerr
<<
"Could not open file.
\n
"
;
exit
(
0
);
}
string
blank
;
string
name
,
date
;
int
score
;
fin
>>
blank
;
fin
>>
blank
;
fin
>>
blank
;
//until file is empty load into conatiners
while
(
fin
>>
name
){
//prep variables to store
fin
>>
score
;
fin
>>
date
;
//put into vector
Scores
newScore
(
name
,
score
,
date
);
scores
.
push_back
(
newScore
);
}
cout
<<
endl
<<
scores
.
size
()
<<
endl
;
fin
.
close
();
}
void
SL2048
::
updateFile
(){
ofstream
fout
;
fout
.
open
(
"2048Data.txt"
,
ofstream
::
out
|
ofstream
::
trunc
);
//delete file contents
fout
<<
"NAME"
<<
"
\t
"
<<
"SCORE"
<<
"
\t
"
<<
"DATE
\n
"
;
for
(
auto
scoresFull
:
scores
){
fout
<<
scoresFull
.
getName
()
<<
"
\t
"
<<
scoresFull
.
getScore
()
<<
"
\t
"
<<
scoresFull
.
getDate
()
<<
endl
;
}
fout
.
close
();
}
Testings/Kyle's Folder/SL2048.h
0 → 100644
View file @
fcbdfbab
#ifndef SL2048_H
#define SL2048_H
#include <fstream>
#include <vector>
#include "SaveLoad.h"
#include "Scores.h"
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
using
namespace
std
;
class
Scores
;
class
SL2048
:
public
SaveLoad
{
public:
void
LoadContainers
();
void
updateFile
();
};
#endif
\ No newline at end of file
Testings/Kyle's Folder/SLSnake.cpp
0 → 100644
View file @
fcbdfbab
#include "SLSnake.h"
void
SLSnake
::
LoadContainers
(){
ifstream
fin
;
fin
.
open
(
"snakedata.txt"
);
if
(
!
fin
.
is_open
()){
cerr
<<
"Could not open file.
\n
"
;
exit
(
0
);
}
string
blank
;
string
name
,
date
;
int
score
;
fin
>>
blank
;
fin
>>
blank
;
fin
>>
blank
;
//read from file intil it isempty
while
(
fin
>>
name
){
fin
>>
score
;
fin
>>
date
;
//put into vector
Scores
newScore
(
name
,
score
,
date
);
scores
.
push_back
(
newScore
);
}
fin
.
close
();
}
void
SLSnake
::
updateFile
(){
ofstream
fout
;
//delete date in snake data file
fout
.
open
(
"snakedata.txt"
,
ofstream
::
out
|
ofstream
::
trunc
);
//update file
fout
<<
"NAME"
<<
"
\t
"
<<
"SCORE"
<<
"
\t
"
<<
"DATE
\n
"
;
for
(
auto
scoresFull
:
scores
){
fout
<<
scoresFull
.
getName
()
<<
"
\t
"
<<
scoresFull
.
getScore
()
<<
"
\t
"
<<
scoresFull
.
getDate
()
<<
endl
;
}
fout
.
close
();
}
\ No newline at end of file
Testings/Kyle's Folder/SLSnake.h
0 → 100644
View file @
fcbdfbab
#ifndef SLSnake_H
#define SLSnake_H
#include <fstream>
#include <vector>
#include "SaveLoad.h"
#include "Scores.h"
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
using
namespace
std
;
class
Scores
;
class
SLSnake
:
public
SaveLoad
{
public:
void
LoadContainers
();
void
updateFile
();
};
#endif
\ No newline at end of file
Testings/Kyle's Folder/SaveLoad.cpp
0 → 100644
View file @
fcbdfbab
#include "SaveLoad.h"
bool
SaveLoad
::
sortAscending
(
Scores
score1
,
Scores
score2
){
return
score1
.
getScore
()
>
score2
.
getScore
();
}
void
SaveLoad
::
sortByScore
(){
sort
(
scores
.
begin
(),
scores
.
end
(),
sortAscending
);
}
void
SaveLoad
::
pushBackNewScoreAndSort
(
Scores
Score
){
scores
.
push_back
(
Score
);
sortByScore
();
}
void
SaveLoad
::
displayScores
(){
cout
<<
"Rank Name Score Date
\n
"
;
int
i
=
1
;
for
(
auto
score
:
scores
){
cout
<<
i
++
<<
"
\t
"
<<
score
.
getName
()
<<
"
\t
"
<<
score
.
getScore
()
<<
"
\t
"
<<
score
.
getDate
()
<<
endl
;
}
}
\ No newline at end of file
Testings/Kyle's Folder/SaveLoad.h
View file @
fcbdfbab
...
...
@@ -2,15 +2,33 @@
#define SAVELOAD_H
#include <fstream>
#include <vector>
#include "Scores.h"
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
using
namespace
std
;
class
Scores
;
class
SaveLoad
{
public:
virtual
void
LoadContainers
()
=
0
;
virtual
void
updateFile
()
=
0
;
//add new data into file
void
pushBackNewScoreAndSort
(
Scores
Score
);
void
sortByScore
();
static
bool
sortAscending
(
Scores
,
Scores
);
//display scores in the bash
void
displayScores
();
protected:
vector
<
Scores
>
scores
;
};
#endif
\ No newline at end of file
Testings/Kyle's Folder/Scores.h
0 → 100644
View file @
fcbdfbab
#ifndef SCORES_H
#define SCORES_H
#include <iostream>
#include <string>
using
namespace
std
;
class
Scores
{
public:
Scores
(
string
name
,
int
score
,
string
date
){
this
->
name
=
name
;
this
->
score
=
score
;
this
->
date
=
date
;
}
//accessors
string
getName
(){
return
name
;}
int
getScore
(){
return
score
;}
string
getDate
(){
return
date
;}
private:
string
name
,
date
;
int
score
;
};
#endif
Testings/Kyle's Folder/main.cpp
0 → 100644
View file @
fcbdfbab
#include "SaveLoad.h"
#include "Scores.h"
#include <cstring>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include "SL2048.h"
#include "SLSnake.h"
using
namespace
std
;
int
main
(){
//check for valid username
char
userName
[
3
];
SLSnake
second
;
second
.
LoadContainers
();
while
(
userName
!=
"quit"
){
cout
<<
"Enter a username with a length of 3 characters
\n
"
;
while
(
strlen
(
userName
)
!=
3
){
try
{
cin
>>
userName
;
if
(
strlen
(
userName
)
!=
3
){
throw
runtime_error
(
"Invalid Input. Username must be 3 characters long
\n
"
);
}
}
catch
(
runtime_error
&
except
){
cout
<<
except
.
what
();
}
}
//here is a temporary score input system
//in the final project the score will be taken automatically from the system.
int
score
;
cin
>>
score
;
cout
<<
endl
;
//enter date
char
date
[
8
];
cout
<<
"Enter date in --/--/-- format.
\n
ie. 3/9/19
\n
"
;
cin
>>
date
;
Scores
score1
(
userName
,
score
,
date
);
second
.
pushBackNewScoreAndSort
(
score1
);
second
.
updateFile
();
second
.
displayScores
();
}
return
0
;
}
// SL2048 first;
// first.LoadContainers();
// first.sortByScore();
// first.updateFile();
//
// Scores score1("BND" , 6564, "3/9/19");
// second.pushBackNewScoreAndSort(score1);
// second.updateFile();
\ No newline at end of file
Testings/Kyle's Folder/snakedata.txt
0 → 100644
View file @
fcbdfbab
NAME SCORE DATE
Mal 54234 3/11/19
BVB 9240 3/9/19
BND 6564 3/9/19
CDS 6544 3/9/19
NKV 5453 3/9/19
KAL 2434 3/10/19
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment