Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDIU20
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cpp-programmering
TDIU20
Commits
3b34a114
Commit
3b34a114
authored
1 year ago
by
Alrik Appelfeldt
Browse files
Options
Downloads
Patches
Plain Diff
Delete main.cc
parent
2b907291
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Uppgift-3-Spel/main.cc
+0
-112
0 additions, 112 deletions
Uppgift-3-Spel/main.cc
with
0 additions
and
112 deletions
Uppgift-3-Spel/main.cc
deleted
100644 → 0
+
0
−
112
View file @
2b907291
#include
"ghost.h"
#include
<string>
#include
<iostream>
#include
<iomanip>
#include
<sstream>
using
namespace
std
;
/*
Ledning och Tips:
- Modifiera stukturen till en header-fil och en implementationsfil
- Utöka 'run()' och 'draw_map()' med övrig funktionalitet.
- Lägg alla spöken i en lämplig behållare som en datamedlem.
- Bryt ut stora kodblock till egna funktioner.
- Använd hjälpfunktioner för att undvika duplicering av kod.
- Tänk på att varje funktion inte borde vara längre än 25 rader.
*/
class
Ghost_Tester
{
public:
Ghost_Tester
()
:
pacman
{}
{
}
void
run
()
{
while
(
true
)
{
draw_map
();
cout
<<
"> "
;
string
line
{};
getline
(
cin
,
line
);
istringstream
iss
{
line
};
string
command
{};
iss
>>
command
;
if
(
command
==
"pos"
)
{
Point
new_pos
{};
iss
>>
new_pos
.
x
>>
new_pos
.
y
;
pacman
.
set_position
(
new_pos
);
}
else
if
(
command
==
"dir"
)
{
}
else
if
(
command
==
"quit"
)
{
break
;
}
}
}
private
:
/*
En hjälpfunktion som avgör vilka två tecken som ska ritas ut för en given position på
spelplanen.
*/
string
to_draw
(
Point
const
&
curr_pos
)
{
string
to_draw
{
" "
};
if
(
pacman
.
get_position
()
==
curr_pos
)
{
to_draw
[
1
]
=
'@'
;
}
return
to_draw
;
}
/*
En hjälpfunktion för att rita ut spelplanen för testprogrammet.
Itererar över varje rad och column i kartan. Index för raderna är flippade för att placera
y = 0 längst ned.
Varje punkt i kartan ritas som två tecken eftersom ett tecken i terminalen är ca dubbelt så
högt som det är brett.
*/
void
draw_map
()
{
cout
<<
"+"
<<
setfill
(
'-'
)
<<
setw
(
WIDTH
*
2
)
<<
"-"
<<
"+
\n
"
;
for
(
int
y
{
HEIGHT
-
1
};
y
>=
0
;
--
y
)
{
cout
<<
"|"
;
for
(
int
x
{};
x
<
WIDTH
;
++
x
)
{
cout
<<
to_draw
(
Point
{
x
,
y
}
);
}
cout
<<
"|
\n
"
;
}
cout
<<
"+"
<<
setfill
(
'-'
)
<<
setw
(
WIDTH
*
2
)
<<
"-"
<<
"+"
<<
endl
;
}
Pacman
pacman
;
};
int
main
()
{
Ghost_Tester
gt
{};
gt
.
run
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment