Every time my player moves I want to use my code to relay his xy position via the point struct to a cout for visual display of his coordinates. And I want to do it in one line of flexible code, am I on the right track?
Code:#include <conio.h> #include <iostream> #include "Point.h" template <typename T> T Bound(T val, T min, T max) { if(val < min) return min; if(val > max) return max; return val; } class Player { private: int strength; int dexterity; int intelligence; char direction; int x_location; int y_location; public: Player() { x_location = 0; y_location = 0; } Point move() { direction = _getch(); if (direction == 'w') y_location++; else if(direction == 'a') x_location--; else if(direction == 's') y_location--; else if(direction == 'd') x_location++; x_location = Bound(x_location, -10, 10); y_location = Bound(y_location, -10, 10); Point location; location.x = x_location; location.y = y_location; return location; } };Code:#include "stdafx.h" #include "World.h" #include "Player.h" int _tmain(int argc, _TCHAR* argv[]) { World Adventursaur; Player player; int enemy = 15; do { enemy--; } while(enemy > 0); return 0; }Code:#include "Player.h" class World { public: void get_coordinates(Player player) { player.move(); } };



LinkBack URL
About LinkBacks



