aboutsummaryrefslogtreecommitdiff
path: root/world.cpp
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-02 21:23:39 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-02 21:23:39 +0100
commitfb0cdfe743869f6592090e441a071f0904a80634 (patch)
tree60a6caee28ab702efb2a3e72b6cf5644ca1949c1 /world.cpp
parent39dbc1934d506f4b1da32621a8ff7e2e165a0bb0 (diff)
Optimize terminal usage
The ^C-catching stuff will not work on windows; need to look into that
Diffstat (limited to 'world.cpp')
-rw-r--r--world.cpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/world.cpp b/world.cpp
index b74e7cb..0af24a2 100644
--- a/world.cpp
+++ b/world.cpp
@@ -316,14 +316,28 @@ Robot* World::targetbot(const Robot *r){
return *targetbotptr(r);
}
-void World::print() const {
+void World::print(ostream &os) const {
for(int y=0;y<SIZE;y++){
for(int x=0;x<SIZE;x++){
- if(board[y][x]==nullptr)cout<<"..";
- else cout<<string(2,"^>v<"[board[y][x]->heading%4]);
- cout<<' ';
+ if(board[y][x]==nullptr)os<<"..";
+ else os<<string(2,"^>v<"[board[y][x]->heading%4]);
+ os<<' ';
+ }
+ os<<endl;
+ }
+}
+
+void World::print(ScreenBuffer &sb) const {
+ for(int y=0;y<SIZE;y++){
+ sb.moveto(0,y);
+ for(int x=0;x<SIZE;x++){
+ if(board[y][x]==nullptr)sb.printf("..");
+ else {
+ char c="^>v<"[board[y][x]->heading%4];
+ sb.printf("%c%c",c,c);
+ }
+ sb.printf(" ");
}
- cout<<endl;
}
}