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
f4fb010f
Commit
f4fb010f
authored
1 year ago
by
Alrik Appelfeldt
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
3b34a114
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
+128
-0
128 additions, 0 deletions
Uppgift-3-Spel/main.cc
with
128 additions
and
0 deletions
Uppgift-3-Spel/main.cc
0 → 100644
+
128
−
0
View file @
f4fb010f
#include
"ghost.h"
#include
"given.h"
#include
<string>
#include
<iostream>
#include
<iomanip>
#include
<sstream>
#include
<vector>
#include
<cctype>
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:
Pacman
pacman
;
vector
<
Ghost
*>
all_ghosts
;
Ghost_Tester
()
:
pacman
{}
,
all_ghosts
{}
{
all_ghosts
.
push_back
(
new
Clyde
(
"orange"
,
Point
{
5
,
5
}));
all_ghosts
.
push_back
(
new
Blinky
(
"red"
,
Point
{
6
,
6
}));
all_ghosts
.
push_back
(
new
Pinky
(
"pink"
,
Point
{
7
,
7
}))
;
}
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
;
}
}
}
//fixa följande funltion
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
;
}
};
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