Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this code for my pacman game how would i change the color of the walls to blue and the color of the food to

Using this code for my pacman game how would i change the color of the walls to blue and the color of the food to yellow please and thank you

(This code uses visual studios open framework )

pacman.cpp

#include

#include //for timing

#include //for getch();

#include //for puts(" ")

#include //for clear screen

#include //for initializing srand() function

#include"pacman.h"

using namespace std;

int foodEaten;

#define up 72 //*

#define down 80 //*

#define left 75 //*==> Defining Arrow Input keys for User

#define right 77 //*

#define esc 27 //*

#define enter 13 //*

void game::initializeRandom()

{

srand(time(NULL));

}

void game::MainMenu() //******MAIN MENU FUNCTION******

{

do

{

system("cls");

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* UPPER WAAL IN MENU

cout << waal; //*

} //*

cout << " \tWECLOME TO [PAC-MAN A>

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* LOWER WAAL IN MENU

cout << waal; //*

} //*

cout << " 1==>\tHit Enter to Start the Game" << endl; //*

cout << " 2==>\tChoose Game Mode OR Enemy Speed Press 2" << endl; //*

cout << " 3==>\tPress Escape to Exit the Game" << endl; //*

chm = _getch(); //INPUT USER CHOICE TO CONTINUE OR EXIT

if (chm == '2')

{

do

{

system("CLS");

cout << " *** Press Escape to Go Back *** ";

cout << " 1==>\t TO PLAY SCORE MODE PRESS 1" << endl; //* OPTIONS

cout << " 2==>\t TO PLAY CLASSIC MODE PRESS 2" << endl; //*

cout << " 3==>\t TO CHANGE ENEMY SPEED PRESS 3" << endl; //*

chm1 = _getch();

if (chm1 == '1')

{

ghostMode = 0;

cout << " \t*** SCORE MODE ACTIVATED *** ";

}

if (chm1 == '2')

{

cout << " \t*** CLASSIC MODE ACTIVATED ";

}

if (chm1 == '3')

{

ghostSpeed = 2;

cout << " \t*** ENEMY SPEED REDUCED *** ";

}

// if(chm1!='1'||chm1!='2'||chm1!='3'||chm1!='4')

// {

// cout<<"Wrong Choice";

// }

} while (chm1 != esc);

}

if (chm == '3') //HELP GUIDE FROM OPTION CHOICE 3

{

system("CLS");

do

{

chm1 = _getch();

} while (chm1 != esc);

} //CHOICE 3 BRACKET CLOSE

if (chm == '3') //ABOUT FROM OPTION 4

{

system("CLS");

do

{

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* LOWER WAAL IN MENU

cout << waal; //*

} //*

cout << endl;

chm1 = _getch();

} while (chm1 != esc);

} //OPTION 4 BRACKET CLOSE

if (chm == esc)

{

exit(1);

}

system("cls");

} while (chm != enter);

}

void game::showScore() //******SHOW SCORE FUNCTION******

{

cout << " \t\t\t\t************* \t\t\t\tScore is::" << score << " \t\t\t\t************* ";

cout << " Food Eaten=" << foodEaten << endl;

}

void game::makePacMap() //******MAKING PAC-MAP FUNCTION******

{ //makePacMap bracket start

for (x = 0; x<15; x++) //making pac map [X] is Row & [Y] is Column

{

for (y = 0; y<40; y++)

{

pac[x][y] = food; //FILLING MAP WITH FOOD

if (y == 3 || y == 10 || y == 15 || y == 20 || y == 25 || y == 30 || y == 35)

{

pac[x][y] = null;

}

if (x == 12 || x == 9 || x == 3)

{

pac[x][y] = null;

}

if (x == 12 && y == 4 || x == 12 && y == 5) //*

{ //* blocking

pac[x][y] = x_axis; //*

} //*

if (y == 9 && x == 5 || y == 9 && x == 4)

{

pac[x][y] = y_axis;

}

if (x == 12 && y == 30 || x == 12 && y == 31 || x == 12 && y == 32 || x == 12 && y == 33)

{ //* blocking

pac[x][y] = x_axis; //*

} //*

if (x == 7 && y == 16 || x == 7 && y == 24) //Bonus Food

{ //Bonus Food

pac[x][y] = bonusFood; //Bonus Food

} //Bonus Food

if (x == 1 && y == 36 || x == 13 && y == 4) //Bonus Food

{ //Bonus Food

pac[x][y] = bonusFood; //Bonus Food

}

if (y == 18 || y == 22)

{

pac[x][y] = y_axis; //MAKING VERTICAL FREE WAY WAAL

if (x == 4 || x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10)

{ //making FREE SPACE

pac[x][y] = null;

}

}

if (y == 1 && x == 8 || y == 2 && x == 8 || y == 3 && x == 8) //*

{ //*

pac[x][y] = x_axis; //*

} //* Making left side inside waal

if (y == 1 && x == 5 || y == 2 && x == 5 || y == 3 && x == 5) //*

{ //*

pac[x][y] = x_axis; //*

} //*

if (y == 38 && x == 8 || y == 37 && x == 8 || y == 36 && x == 8) //*

{ //*

pac[x][y] = x_axis; //*

} //* Making right side inside waal

if (y == 38 && x == 5 || y == 37 && x == 5 || y == 36 && x == 5) //*

{ //*

pac[x][y] = x_axis; //*

} //*

if (x == 3 && y == 7 || x == 3 && y == 8 || x == 3 && y == 9 || x == 3 && y == 10) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //waal

//* LEFT SIDE UP LINE //waal

if (x == 3 && y == 11 || x == 3 && y == 12 || x == 3 && y == 13 || x == 3 && y == 14) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //waal

//waal

if (x == 10 && y == 7 || x == 10 && y == 8 || x == 10 && y == 9 || x == 10 && y == 10) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //* LEFT SIDE DOWN LINE //waal

if (x == 11 && y == 11 || x == 11 && y == 12 || x == 11 && y == 13 || x == 11 && y == 14) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //waal

if (x == 3 && y == 26 || x == 3 && y == 27 || x == 3 && y == 28 || x == 3 && y == 29) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //* RIGHT SIDE UP LINE //waal

if (x == 3 && y == 30 || x == 3 && y == 31 || x == 3 && y == 32 || x == 3 && y == 33) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //waal

if (x == 11 && y == 26 || x == 11 && y == 27 || x == 11 && y == 28 || x == 11 && y == 29) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //* RIGHT SIDE DOWN LINE //waal

if (x == 10 && y == 30 || x == 10 && y == 31 || x == 10 && y == 32 || x == 10 && y == 33) //waal

{ //waal

pac[x][y] = x_axis; //waal

} //waal

if (x == 5 && y == 14 || x == 6 && y == 14 || x == 7 && y == 14 || x == 8 && y == 14) //box

{ //BOX LEFT //box

pac[x][y] = y_axis; //box

} //box

if (x == 5 && y == 26 || x == 6 && y == 26 || x == 7 && y == 26 || x == 8 && y == 26) //box

{ //BOX RIGHT //box

pac[x][y] = y_axis; //box

} //box

//box

if (x == 5 && y == 15 || x == 5 && y == 16 || x == 5 && y == 17 || x == 5 && y == 18) //box

{ //BOX UP-LEFT //box

pac[x][y] = x_axis; //box

} //box

if (x == 5 && y == 22 || x == 5 && y == 23 || x == 5 && y == 24 || x == 5 && y == 25) //box

{ //BOX UP-RIGHT //box

pac[x][y] = x_axis; //box

} //box

//box

if (x == 9 && y == 15 || x == 9 && y == 16 || x == 9 && y == 17 || x == 9 && y == 18) //box

{ //BOX DOWN //box

pac[x][y] = x_axis; //box

} //box

if (x == 9 && y == 14) //box

{ //BOX DOWN //box

pac[x][y] = x_axis; //box

} //box

if (x == 9 && y == 19 || x == 9 && y == 20 || x == 9 && y == 21 || x == 9 && y == 22) //box

{ //BOX DOWN //box

pac[x][y] = x_axis; //box

} //box

if (x == 9 && y == 23 || x == 9 && y == 24 || x == 9 && y == 25 || x == 9 && y == 26) //box

{ //box

pac[x][y] = x_axis; //box

} //box

if (x == 14 || y == 39 || x == 0 || y == 0) //MAKING MAIN MAP BOUNDARY

{

pac[x][y] = waal;

}

if (x == 0 && y == 20 || y == 19 || y == 21 || x == 14 && y == 20)

{ //VERTICAL WAAL FREE WAY

pac[x][y] = null;

}

if (y == 0 && x == 7 || x == 6 || y == 39 && x == 7)

{ //HORIZONTAL WAAL FREE WAY

pac[x][y] = null;

}

} //Making PAC-MAP FOR LOOP X BRACKET CLOSE

} //Making PAC-MAP FOR LOOP Y BRACKET CLOSE

cout << " ";

} //makePacMap bracket close

void game::showPacMap() //******OUTPUT PAC-MAP FUNCTION******

{ //showPacMap bracket start

// cout<<"[gamingumar.blogspot.com] ";

for (y = 0; y<15; y++)

{

cout << "\t\t";

for (x = 0; x<40; x++)

{

if (chkStart == 0)

{

pac[yi][xi] = '<';

}

cout << pac[y][x];

chkStart++;

}

cout << endl;

}

} //showPacMap bracket close

void game::countDown() //******COUNT DOWN FUNCTION******

{

//60000 = 60000-100

stopWatch = stopWatch - 100;

sec = stopWatch / 1000;

cout << " \tTime Left [" << sec << "]" << endl;

}

void game::calFood() //******CALCULATE FOOD FUNCTION******

{

for (x = 0; x<15; x++)

{

for (y = 0; y<40; y++)

{

if (pac[x][y] == food || pac[x][y] == bonusFood)

{

foodCount++;

}

}

}

cout << "Food in The Map is=" << foodCount << endl;

}

void game::downBody() //******COMMON THINGS IN GAME FUNCTION******

{

if (sec == timeUp || input == enter || foodEaten == foodCount || pac[yi][xi] == enemy)

{ //IF THESE CONDITION ARE TRUE, SHOW MESSAGE & RESET GAME

if (sec == timeUp)

{

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* UPPER WAAL IN MESSAGE

cout << waal; //*

} //*

cout << " \t:::TIME UP,,, GAME OVER:::"; //WHEN TIME IS UP GAME WILL OVER

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* LOWER WAAL IN MESSAGE

cout << waal; //*

} //*

}

if (foodEaten == foodCount)

{

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* UPPER WAAL IN MESSAGE

cout << waal; //*

} //*

cout << " \t:::CONGRATULATIONS,,, YOU WON:::"; //WHEN PAC-MAN HAVE EATEN ALL THE FOOD

//YOU WON THE GAME

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* LOWER WAAL IN MESSAGE

cout << waal; //*

} //*

}

if (pac[yi][xi] == enemy)

{

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* UPPER WAAL IN MESSAGE

cout << waal; //*

} //*

cout << " \t:::GHOST ATE YOU,,, GAME OVER:::"; //WHEN GHOST ATE YOU GAME WILL OVER

cout << " \t"; //*

for (j = 0; j<40; j++) //*

{ //* LOWER WAAL IN MESSAGE

cout << waal; //*

} //*

}

showScore();

stopWatch = reset;

chkStart = 0; foodEaten = -1;

yi = 10; xi = 20;

score = 0;

cout << " \t\tENTER 1 TO GO TO MAIN MENU ";

cout << " \t\tENTER 2 TO EXIT GAME ";

cout << "Enter Your Choice=";

cin >> ch;

if (ch == 1) //This is Main Menu if choice is 1 continue the game

{

MainMenu();

makePacMap();

showPacMap();

pacmanMove();

// ghost();

}

if (ch == 2) //This is Main Menu if choice is 2 exit the game

{

exit(1);

}

else

{

if (ch != 2 || ch != 3)

{

MainMenu();

}

}

}

/* if(pac[yi][xi]==enemy) //LIVES LEFT COUNTER

{

lives--;

cout<<"lives Left=" <

Sleep(delay*60);

cout<<"lives Left=" <

}*/

if (sec != timeUp || foodEaten != foodCount || pac[yi][xi] != enemy)

{

showScore();

showPacMap();

countDown();

// ghost();

Sleep(delay); //controlling the speed of Pacman

system("CLS"); //clears the previous screen

if (ghostMode == 1)

{

if (delay += ghostSpeed)// && ghostMode==1)

{

ghost(yi, xi);

}

}

}

}

void game::pacmanMove() //******MOVING PAC-MAN FUNCTION******

{ //pacmanMove bracket start

do

{ //pacmanMove do bracket start

cout << endl;

input = _getch(); //Direction Input of Pacman

switch (input) //choosing the direction using case

{ //switch bracket start

case right: //***MOVING RIGHT SIDE CODE***

{ //case right bracket

while (!_kbhit())

{

if (xi == xiLimit)

{

pac[yi][xi] = null;

xi = xiStart;

}

if (pac[yi][xi + 1] == food) //*

{ //*

pac[yi][xi + 1] = '<'; //*

pac[yi][xi] = null; //*=====>Right Side Food Eating

xi++; //*

score++; //*

foodEaten++; //*

}

if (pac[yi][xi + 1] == waal)

{

downBody(); //if it is waal do nothing except timer

}

if (pac[yi][xi + 1] == null) //if next is nothing

{

pac[yi][xi + 1] = '<';

pac[yi][xi] = null;

xi++;

}

if (pac[yi][xi + 1] == bonusFood) //if next is bonus food

{

pac[yi][xi + 1] = '<';

pac[yi][xi] = null;

xi++;

score += 200;

foodEaten++;

}

downBody();

}

break;

} //case right bracket close

case left: //***MOVING LEFT SIDE CODE***

{ //case left bracket start

while (!_kbhit())

{ //left while bracket start

if (xi == xiStart) //if Pac-Map Limit riched

{

pac[yi][xi] = null;

xi = xiLimit;

}

if (pac[yi][xi - 1] == food) //if next is food

{

pac[yi][xi - 1] = '>';

pac[yi][xi] = null;

xi--;

score++;

foodEaten++;

}

if (pac[yi][xi - 1] == waal) //if next is waal

{

downBody();

}

if (pac[yi][xi - 1] == null) //if next is nothing

{

pac[yi][xi - 1] = '>';

pac[yi][xi] = null;

xi--;

}

if (pac[yi][xi - 1] == bonusFood) //if next is bonus food

{

pac[yi][xi - 1] = '>';

pac[yi][xi] = null;

xi--;

score += 200;

foodEaten++;

}

downBody();

} //left while bracket close

break;

} //case left bracket close

case up: //***MOVING TOWARDS UP CODE***

{ //case up bracket start

while (!_kbhit())

{ //up while bracket start

if (yi == yiStart) //if Pac-Map Limit riched

{

pac[yi][xi] = null;

yi = yiLimit;

}

if (pac[yi - 1][xi] == food) //if next is food

{

pac[yi][xi] = null;

pac[yi - 1][xi] = 'V';

yi--;

score++;

foodEaten++;

}

if (pac[yi - 1][xi] == waal) //if next is waal

{

downBody();

}

if (pac[yi - 1][xi] == null) //if next is nothing

{

pac[yi - 1][xi] = 'V';

pac[yi][xi] = null;

yi--;

}

if (pac[yi - 1][xi] == bonusFood) //if next is bonus food

{

pac[yi - 1][xi] = 'V';

pac[yi][xi] = null;

yi--;

score += 200;

foodEaten++;

}

downBody();

} //up while bracket close

break;

} //case up bracket close

case down: //***MOVING DOWN WARDS CODE***

{ //case down bracket start

while (!_kbhit())

{ //down while bracket start

if (yi == yiLimit) //if Pac-Map Limit riched

{

pac[yi][xi] = null;

yi = yiStart;

}

if (pac[yi + 1][xi] == food) //if next is food

{

pac[yi][xi] = null;

pac[yi + 1][xi] = '^';

yi++;

score++;

foodEaten++;

}

if (pac[yi + 1][xi] == waal) //if next is waal

{

downBody();

}

if (pac[yi + 1][xi] == null) //if next is nothing

{

pac[yi + 1][xi] = '^';

pac[yi][xi] = null;

yi++;

}

if (pac[yi + 1][xi] == bonusFood) //if next is bonus food

{

pac[yi + 1][xi] = '^';

pac[yi][xi] = null;

yi++;

score += 200;

foodEaten++;

}

downBody();

} //down while bracket close

break;

} //case down bracket close

case enter:

{

downBody();

}

default:

{

showPacMap();

cout << " \tGAME PAUSED ";

}

} //switch bracket close

} //do bracket close

while (input != esc); //IF ESCAPE KEY IS PRESSED CLOSE THE GAME

} //pacmanMove bracket close

void game::ghost(int tmp1, int tmp2) //******ENEMY GHOST FUNCTION******

{ //GHOST FUNCTION BRACKET START

pac[t1][t2] = pac[tmp1][tmp2]; //SAVING GHOST POSITION TEMPORARY

pac[ey][ex] = enemy;

ey = tmp1;

ex = tmp2;

pac[ey][ex] = pac[tmp1][tmp2];

if (pac[t1][t2] == food)

{

pac[ey][ex] = food;

}

else

{

if (pac[t1][t2] == null)

{

pac[ey][ex] = null;

}

}

}

void game::moveRandom()

{

}

pacman.h

#ifndef pacheadH

#define pacheadH

class game

{

public:

int chkStart, score, x, y, counter, ex, ey, chooseEnemyWay, mainCh, lives;

int yi, xi, xiStart, yiStart, yiLimit, xiLimit, t1, t2, ghostMode;

int ch, ch1, foodCount, foodEated, chk, null, x_axis, y_axis, j;

float delay, stopWatch, sec, reset, timeUp, ghostSpeed;

char input, pac[15][40], food, bonusFood, waal, enemy;

char chm, chm1; //Options from Main Menu

void makePacMap();

void showPacMap();

void pacmanMove();

void showScore();

void downBody(); //it will output & call common functions

void MainMenu();

void countDown();

void calFood();

void ghost(int tmp1, int tmp2);

void moveRandom();

void initializeRandom();

game() //CONSTRUCTOR INITIALIZING VALUES

{

// cout<<" \tGame Constructor Called";

chkStart = 0; score = 0; counter = 0; //chkStart will see if its the first time you have started game

food = '.'; null = '\0';

foodCount = -1; foodEated = 0; //total food count which includes bonus + simple food

yi = 10; xi = 20; //initializing the starting point of PAC-MAN

yiLimit = 14; xiLimit = 39; //PAC-MAP limit is the max 2D Array Size

xiStart = 0; yiStart = 0; //if PAC-MAN reaches end of the Map & there is no waal

//then it will come to the start of the array

timeUp = 0.0; lives = 3;

bonusFood = 157; //Special Food Item

enemy = 'X';//238; //Enemy or Ghost

waal = 219; //This is the main Waal Character ASCII value

x_axis = 205; y_axis = 186; //These are the ASCII of inner waals of the map

ghostSpeed = 0.5; ghostMode = 0;

ey = 10; ex = 19;

// ex=16; ey=8; //Enemy/Ghost Starting Point Location

delay = 40; //This is time delay used in my Stop Watch & timing

stopWatch = 60000; reset = 60000; //This is starting time of Stop Watch

t1 = 10; t2 = 19;

}

~game()

{

// cout<<" \tGame Destructor Called";

}

};

#endif

Source1.cpp

#include

#include"pacman.h"

#include

#include

#define esc 27

#define enter 13

using namespace std;

void main()

{

game pacman;

// do

// {

// pacman.initializeRandom();

pacman.MainMenu();

pacman.showScore();

pacman.makePacMap();

pacman.calFood();

pacman.showPacMap();

pacman.pacmanMove();

cout << "Press Escape Key to Exit Game" << endl;

// pacman.mainCh=getch();

// }

// while(pacman.mainCh!=esc || pacman.mainCh==enter);

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions

Question

Which ethical behaviors do I want to improve the most?

Answered: 1 week ago

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

2. Define communication.

Answered: 1 week ago