Apr 20, 2014 at 10:33am UTC
Okay here's my problem. I've made a coding about control a "V" to move around a 21*21 platform. Now I want to "shoot" '*' to the direction (which is downwards). Any idea from you guys ??
Here's my code:
#include <iostream>
#include <cstdlib>
#include <conio.h>
using namespace std;
int main()
{
char command;
char pattern = 'v';
int Add_X = 10, Add_Y = 10;
while (1)
{
system("cls");
cout << "Controls:\nA: Move Left, W: Move Up, S: Move Down, D: Move Right, F: Fire, B: Change" << endl << endl;
for (int i=0;i<=20;i++)
{
cout << "\t\t";
for (int j=0;j<=20;j++)
{
if ((i == Add_Y) && (j == Add_X))
cout << pattern << " ";
else
cout << "_ ";
}
cout << endl;
}
command=getch();
switch (command)
{
case 'a':
case 'A':
if (Add_X!=0)
Add_X--;
break;
case 'D':
case 'd':
if (Add_X!=20)
Add_X++;
break;
case 'S':
case 's':
if (Add_Y!=20)
Add_Y++;
break;
case 'W':
case 'w':
if (Add_Y!=0)
Add_Y--;
break;
case 'Q':
case 'q':
if ((Add_X!=0)&&(Add_Y!=0))
{
Add_X--;
Add_Y--;
}
break;
case 'e':
case 'E':
if ((Add_Y!=0)&&(Add_X!=20))
{
Add_Y--;
Add_X++;
}
break;
case 'c':
case 'C':
if ((Add_Y!=20)&&(Add_X!=20))
{
Add_Y++;
Add_X++;
}
break;
case 'z':
case 'Z':
if ((Add_Y!=20)&&(Add_X!=0))
{
Add_Y++;Add_X--;
}
break;
case 'b':
case 'B':
switch(pattern)
{
case 'v': pattern = '>'; break;
case '>': pattern = '^'; break;
case '^': pattern = '<'; break;
case '<': pattern = 'v'; break;
}
break;
case 'f':
case 'F':
switch(pattern)
{
case 'v':
break;
case '>':
break;
case '^':
break;
case '<':
break;
}
break;
case 'v':
case 'V':
return 0;
break;
}
}
system("pause");
return 0;
}
Thanks a lot for your help. :D