Computer Science > STUDY GUIDE > Texas A&M University - CSCE 121main.cpp (All)
#include <iostream> #include <fstream> #include <string> #include "helper.h" using std::cin, std::cout, std::endl, std::string, std::ifstream; /** * Creates internal representation of dungeon ma... p. * @param fileName File name of dungeon map representation. * @param width Width of dungeon map. * @param height Height of dungeon map. * @param currX Player's starting x-position on dungeon map. * @param currY Player's starting y-position on dungeon map. * @return 2D dynamic array representation of dungeon map with player's location. */ // STEP 1: Write code for createMap(...) function here. int** createMap(const string fileName,int& width,int& height,int& currX,int& currY){ // create array std::ifstream ifs(fileName); if (!ifs.is_open()) { cout << "ERROR: unable to open: " << fileName << endl; ifs.close(); return nullptr; }else{ int temp; ifs >> width; ifs >> height; ifs >> currX; ifs >> currY; int** array = new int*[height]; for( int i = 0; i < width; i++){ array[i] = new int[width]; } for( int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ ifs >> temp; array[j][i] = temp; if ( j == currX && i == currY){ array[j][i] = TILE_PLAYER; } } [Show More]
Last updated: 2 years ago
Preview 1 out of 4 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Apr 04, 2021
Number of pages
4
Written in
This document has been written for:
Uploaded
Apr 04, 2021
Downloads
0
Views
82
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·