123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /* This file is part of Invaders.
- *
- * Copyright (C) 2020 LCM.
- * You may use, distribute and modify Invaders under the terms of the
- * GPLv3 license, available at <https://www.gnu.org/licenses/\>.
- */
- #include "pic.hpp"
- //char** picture;
- pic::pic(int w, int h) : body(w,h){
- picture = new char* [height];
- for(int i=0; i<height; ++i)
- picture[i] = new char[w];
- clear();
- }
- pic::~pic()
- {
- delete [] picture;
- }
- void pic::loadpicture(const char* nome)
- {
- ifstream input(nome);
- char c;
- if(!nome){
- input.close();
- }
- else{
- for(int i=0; i<height; i++) //rows
- for(int j=0; j<width; j++){ //columns
- c = input.get(); // get character from file
- if(c!='\n') picture[i][j]=c;
- if(c=='\n') j--;
- }
-
- input.close();
- }
-
- }
- void pic::clear(){
- for(int i=0; i<height; i++)
- for(int j=0; j<width; j++)
- picture[i][j]=' ';
- }
- void pic::set_values(int W, int H){
- width=W;
- height=H;
- }
- void pic::print(){
- for(int i=0; i<height; i++){
- for(int j=0; j<width; j++)
- cout << picture[i][j];
- cout << endl;
- }
- }
|