Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- char matrix[11][11];
- void initialize()
- {
- for(int d = 0; d < 11; d++)
- {
- for(int q = 0; q < 11; q++)
- {
- matrix[d][q] = '*';
- }
- }
- matrix[5][5] = 'X';
- }
- void draw()
- {
- for(int x = 0; x < 10; x++)
- {
- for(int z = 0; z < 10; z++)
- {
- cout << matrix[x][z] << " ";
- }
- cout << endl;
- }
- }
- void input()
- {
- //77 = right arrow
- //72 = up arrow
- char variable;
- int c = 0;
- int m = 0;
- int breaking = 0;
- for(c = 0; c < 10; c++)
- {
- for(m = 0; m < 10; m++)
- {
- if(matrix[c][m] == 'X')
- {
- breaking = 1;
- break;
- }
- }
- if(breaking == 1)
- break;
- }
- variable = getch();
- if(variable == 77)
- {
- matrix[c][m] = '*';
- matrix[c][m + 1] = 'X';
- }
- else if(variable == 72)
- {
- matrix[c][m] = '*';
- matrix[c - 1][m] = 'X';
- }
- else if(variable == 75)
- {
- matrix[c][m] = '*';
- matrix[c][m - 1] = 'X';
- }
- else if(variable == 80)
- {
- matrix[c][m] = '*';
- matrix[c + 1][m] = 'X';
- }
- }
- int main()
- {
- initialize();
- while(1)
- {
- draw();
- input();
- system("cls");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement