Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TablePrinter.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include<cstdlib>
- #define ROWS 10
- #define COLUMNS 10
- using namespace std;
- struct sprite{
- int x;
- int y;
- int id;
- };
- void PrintTable(void);
- struct sprite PlaceCharacter(void);
- struct sprite MoveCharacter(struct sprite pacman);
- int table[ROWS][COLUMNS] = {0};
- int _tmain(int argc, _TCHAR* argv[])
- {
- struct sprite pacman;
- PrintTable();
- system("PAUSE");
- pacman = PlaceCharacter();
- system("CLS");
- PrintTable();
- pacman = MoveCharacter(pacman);
- system("CLS");
- PrintTable();
- system("PAUSE");
- return 0;
- }
- void PrintTable(void)
- {
- int i,j;
- for (i=0;i<ROWS;i++)
- {
- for (j=0;j<COLUMNS;j++)
- {
- cout << table[i][j] << " ";
- }
- cout << endl;
- }
- }
- struct sprite PlaceCharacter(void)
- {
- struct sprite pacman;
- int i,j;
- do
- {
- cout << "Give me the row: " ;
- cin >> i;
- }while(i<0 || i>ROWS-1);
- do
- {
- cout << "Give me the column: " ;
- cin >> j;
- }while(j<0 || j>COLUMNS-1);
- pacman.x = i;
- pacman.y = j;
- pacman.id = 1;
- table[pacman.x][pacman.y] = pacman.id;
- return pacman;
- }
- struct sprite MoveCharacter(struct sprite pacman)
- {
- int move;
- int i = pacman.x;
- int j = pacman.y;
- do
- {
- cout << "Give me the move using your numpad (5 to stay still): " ;
- cin >> move;
- }while(move<1 || move>9);
- switch (move)
- {
- case 1:
- table[i][j] = 0;
- pacman.x = i+1;
- pacman.y = j-1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 2:
- table[i][j] = 0;
- pacman.x = i+1;
- pacman.y = j;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 3:
- table[i][j] = 0;
- pacman.x = i+1;
- pacman.y = j+1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 4:
- table[i][j] = 0;
- pacman.x = i;
- pacman.y = j-1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 5:
- table[i][j] = pacman.id;
- break;
- case 6:
- table[i][j] = 0;
- pacman.x = i;
- pacman.y = j+1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 7:
- table[i][j] = 0;
- pacman.x = i-1;
- pacman.y = j-1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 8:
- table[i][j] = 0;
- pacman.x = i-1;
- pacman.y = j;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- case 9:
- table[i][j] = 0;
- pacman.x = i-1;
- pacman.y = j+1;
- table[pacman.x][pacman.y] = pacman.id;
- break;
- default:
- cout << "Invalid Move!";
- break;
- }
- return pacman;
- }
Advertisement
Add Comment
Please, Sign In to add comment