Xavistian

Herencia Aviones

Sep 20th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. //LaNeta.h
  2. #pragma once
  3. #include "Nave.h"
  4.  
  5. class CLaNeta :
  6.     public CNave
  7. {
  8. public:
  9.     CLaNeta();
  10.     void Mostrar();
  11.     void Ocultar();
  12.     ~CLaNeta();
  13. };
  14. //LaNeta.cpp
  15. #include "stdafx.h"
  16.  
  17. CLaNeta::CLaNeta()
  18. {
  19.     x = 10;
  20.     y = 10;
  21.     dx = 2;
  22.     color = 11;
  23.     ancho = 13;
  24.     alto = 3;
  25. }
  26. void CLaNeta::Mostrar()
  27. {
  28.     Console::ForegroundColor = (ConsoleColor)color;
  29.     Console::SetCursorPosition(x, y);
  30.     cout << "    __!__    ";
  31.     Console::SetCursorPosition(x, y+1);
  32.     cout << "_____(_)_____";
  33.     Console::SetCursorPosition(x, y+2);
  34.     cout << "   !  !  !   ";
  35. }
  36. void CLaNeta::Ocultar()
  37. {
  38.     Console::ForegroundColor = (ConsoleColor)color;
  39.     Console::SetCursorPosition(x, y);
  40.     cout << "             ";
  41.     Console::SetCursorPosition(x, y + 1);
  42.     cout << "             ";
  43.     Console::SetCursorPosition(x, y + 2);
  44.     cout << "             ";
  45. }
  46. CLaNeta::~CLaNeta()
  47. {
  48. }
  49. //Avion.h
  50. #pragma once
  51. #include "stdafx.h"
  52.  
  53. class CAvion :public CNave
  54. {
  55. public:
  56.     CAvion(int px, int py);
  57.     void Mostrar();
  58.     void Ocultar();
  59.     ~CAvion();
  60. };
  61. //CAvion.cpp
  62. #include "stdafx.h"
  63.  
  64. CAvion::CAvion(int px, int py):CNave()
  65. {
  66.     x = px;
  67.     y = py;
  68.     ancho = 11;
  69.     alto = 3;
  70.     color = 10;
  71. }
  72. void CAvion::Mostrar()
  73. {
  74.     Console::ForegroundColor = (ConsoleColor)color;
  75.     Console::SetCursorPosition(x, y);
  76.     cout << "-----------";
  77.     Console::SetCursorPosition(x, y + 1);
  78.     cout << "_/__(_)__\\_";
  79.     Console::SetCursorPosition(x, y + 2);
  80.     cout << "   ./ \\.   ";
  81. }
  82. void CAvion::Ocultar()
  83. {
  84.     Console::SetCursorPosition(x, y);
  85.     cout << "           ";
  86.     Console::SetCursorPosition(x, y + 1);
  87.     cout << "           ";
  88.     Console::SetCursorPosition(x, y + 2);
  89.     cout << "           ";
  90. }
  91. CAvion::~CAvion()
  92. {
  93. }
  94. //Nave.h
  95. #pragma once
  96.  
  97. class CNave
  98. {
  99. protected:
  100.     int x, y, ancho, alto, dx, dy, color;
  101. public:
  102.     CNave();
  103.     void Mover();
  104.     ~CNave();
  105. };
  106. //Nave.cpp
  107. #include "stdafx.h"
  108.  
  109. CNave::CNave()
  110. {
  111.     dx = 1;
  112.     dy = 0;
  113. }
  114.  
  115. void CNave::Mover()
  116. {
  117.     if (x + dx < 0 || x + dx + ancho>79)
  118.     {
  119.         dx *= -1;
  120.     }
  121.     x += dx;
  122. }
  123.  
  124. CNave::~CNave()
  125. {
  126. }
  127. //
  128. stadfx.h
  129. // stdafx.h : include file for standard system include files,
  130. // or project specific include files that are used frequently, but
  131. // are changed infrequently
  132. //
  133.  
  134. #pragma once
  135. #include <iostream>
  136. #include <conio.h>
  137. #include <string>
  138. #include "Nave.h"
  139. #include "Avion.h"
  140. #include "LaNeta.h"
  141. using namespace System;
  142. using namespace std;
  143. // TODO: reference additional headers your program requires here
  144.  
  145. //MAIN
  146. // ConsoleApplication1.cpp : main project file.
  147.  
  148. #include "stdafx.h"
  149.  
  150. int main()
  151. {
  152.     CAvion*obj = new CAvion(15,15);
  153.     CLaNeta*obj2 = new CLaNeta();
  154.     while (1)
  155.     {
  156.         obj->Mostrar();
  157.         obj2->Mostrar();
  158.         _sleep(50);
  159.         obj->Ocultar();
  160.         obj2->Ocultar();
  161.         obj->Mover();
  162.         obj2->Mover();
  163.     }
  164.     return 0;
  165. }
Advertisement
Add Comment
Please, Sign In to add comment