C++ :: How To Move A Ghost In PacMan Game Randomly Around The Maze

Oct 1, 2014

I have tried rand() for x and y positions of ghost but does not work. it moves but not randomly it follows same path every time I run the code.

View 2 Replies


ADVERTISEMENT

C++ :: Pacman Game - Move Smiley In Code Automatically And Stop Screen Flickering?

Dec 26, 2013

So far I have managed to write the code for a simple game (resembling to "Pacman") :P. Now what I want is to move the smiley in the upper left-hand corner of the map "automatically" when the program runs and also want it to change it's direction to up or down when it touches the wall.

Also the screen is flickering when the program runs (due to re-printing the whole array?). I want to stop this flicker. Somebody suggested to use 'gotoxy' function.

Here's my code :

#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;
void display (char array [10][25] , int row , int column) {

[Code] .....

View 8 Replies View Related

C/C++ :: How To Make Object Move In A Maze

Apr 29, 2013

What c++ code can be used to make an 'X' move through a maze. I have some code, but I'm not sure where to go from there. I have divided the program into three files, A header file, a main file and a .cpp implementation file.

In my implementation file I have:

#include "Maze.h"  
Maze::Maze() {  
} void Maze::mazeTraversal(char maze[][COLS], int row, int col, int direction) {
    enum Direction {DOWN, RIGHT, UP, LEFT};  
    switch(option)

[Code] ....

View 1 Replies View Related

C++ :: Read In A Maze File To Move Smiley Face Around In - Stuck On A For Loop Entry

Mar 7, 2013

I am trying to get this code eventually to read in a maze file to move the smiley face around in. But right now my current snag is the yes or no to enter the for loop.

#include <iostream>
#include <windows.h>
#include <conio.h>
#include <time.h>
using namespace std;
int main() {
int name;
char ans;

[Code] .....

View 3 Replies View Related

C++ :: Getting Multiple Objects To Move Randomly At A Designated Number Of Intervals

Jan 9, 2015

I have a piece of code which gets multiple objects to move randomly at a designated number of intervals. I want to create a function which calculates the distance between each pair of points after that number of steps. so the distance between object 1 and object 2, object 1 and object 3, ..., object 1 and object N. then object 2 and object 3, object 2 and object 4, ..., object 2 and object N. then then object 3 and object 4, object 3 and object 5, ..., object 3 and object N and so on until the distance between all the pairs of points have been calculated.

#include <ctime>
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<fstream>
#include<vector>

using namespace std;

double dist(int a, int b);
int X(int x1, int x2);
int Y(int y1, int y1);

[Code] ....

View 4 Replies View Related

C :: Force Move In Checkers Game

Dec 6, 2013

I am doing a checkers program in C and were not allowed to use standard C99. Things are going relatively well so far. I have 2d array that acts as a matrix for my board and have ways to check if a space is empty and if it is occupied by a specific players chip.

Right now I have a giant messy method that I will split up sooner or later but Im just trying to understand and build the logic. It looks like this:

Code:
void isValidMove(int origin, int dest, int player) {
int rowDiff = abs(origin%8 - dest%8);
int possibleMoveLeftUp = origin - 9;
int possibleMoveLeftDown = origin + 9;
int possibleMoveRightUp = origin - 7;

[Code] ....

So although its not pretty i think the logic is sound. I can tell whether or not a player is attempting to make a move or a jump. I haven't implemented make_move() yet but thats no problems. My biggest deal is that I need to find a way to tell the user he has to jump if its available. I feel like this is a very difficult task for me to grasp and is more about algorithm logic and math then the C language which is what the course is for.

So, how I could loop through all of a specific players chips and see if that player has an available jump. Also if he does then the jump has to be taken and then checked again as if there is another legal jump then it needs to be taken as well until their are no jumps left. Of course there could be 2 routes available, but I think I could deal with that if I just could come up with a reasonable way of checking....

View 2 Replies View Related

C++ ::  How To Move A Ball Continuously In 2D Scrolling Game

Dec 29, 2013

The situation is , I have a ball which should move on a flat horizontal surface which i have created in a display of 800 x 400 . Right now!I am able to make it move left or right in direction using key inputs at a fixed speed.

But I want to make it move horizontally at a constant velocity without using keys. Like in copter game.

It should be able to move automatically , towards the right side.

Increment x position by speed variable does the trick but When I used it with keys I used to limit the movement like.

ball.x += ball.speed;
if(ball.x > 750)
ball.x = 750; // because my screen width is 800.

[URL] .... < this video will show what I really want to do with the ball

If you saw the game video in the link i gave, the ball kept moving with constant velocity. But it never went out of bound. What is keeping it from not getting out of display screen. Instead! its moving continuously... but stays almost at the center of screen. How?

View 7 Replies View Related

C/C++ :: Game Of Fifteen - Swap Move Not Showing On Screen

May 26, 2014

I am having problems with my game of fifteen. I have implemented the swap> I know the swap takes place[using GDB] but the swap does not show on the screen even if GDB says it has taken place. I am getting no errors from the move function so I know that something is taking place. I was thinking that the problem may be in the draw function but it looks okay to me. I have looked at this over and over but I don't know why the draw is not printing the move to the screen.

#define _XOPEN_SOURCE 500
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// board's minimal dimension
#define MIN 3
// board's maximal dimension
#define MAX 9

[Code] ....

View 14 Replies View Related

C++ :: For Loop In Hangman Game - Read A Word From Text File Randomly And Matches It With Definition

Jun 26, 2014

Ok here I have a program that reads a word from a text file randomly and matches it with the definition. The user has to guess what the word is according to the definition.

I'm having trouble with my for loop, I'm not getting any errors. But I just know something is off.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;
int main(){
int number;
int count = 0;
int numOfGuess = 0;

[Code] ...

This is words.txt:

apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 1 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: Logic Error - Maze Not Displaying

Jan 24, 2014

So I have a program where I solve a maze using stacks. So my display_maze function take two parameters and displays the maze according to where the x coordinate and y coordinate are.

I have an error during my move function, as my maze doesn't display for some reason

void Player::player_move() {
Stack stack;
Maze maze;
Lock taken;
// Monster monster;

stack.push_values();

[Code] ....

It should be displaying, because after debugging I discovered the problem isn't with the display_maze function.

View 1 Replies View Related

C/C++ :: Right Hand Maze Not Working Properly

Nov 1, 2014

I am creating a right hand maze solution, and it actually works for the most part, but it gets stuck at the sixth spot and will not proceed any further. I cannot seem to find my error even though I know it's probably a small one in my code, here is what I have at the moment:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>

[Code].....

View 6 Replies View Related

C/C++ :: Maze Solver Is Not Backtracking Correctly?

Mar 15, 2014

I'm working on a homework problem where we are given a class of functions to traverse a maze and must use those functions to recursively find the end.

The problem I'm having is when the function backtracks it doesn't reset the whole path it came from.

Here is my function that I have created

void solveMaze(Maze M, int path[][MAX])
{
// << overwritten to print the maze out
cout<<M;

[Code].....

View 7 Replies View Related

C++ :: Find Area Of Room In A Given Square Maze

Apr 1, 2013

Area of the room. Your task is to write a program that will find the area of room in a given square maze.

Note. Use recursion for solving this problem.

Input:
First line contains only one number N (3 <= N <= 10).The number that describes the size of the square maze.
On the next N lines maze itself is inputed ('.' - empty cell,'*' - wall).
And the last line contains two numbers - the row and column of the cell in the room those area you need to find.It is guaranteed that given cell is empty and that the maze is surrounded by walls on all sides.

Output:
Output only one number - total amount of empty cells in the selected room.

View 8 Replies View Related

C/C++ :: Word Maze - Find String In Vector

Mar 4, 2015

This program is to solve a word maze and find the number of words in the maze from a dictionary file.

The program runs, but stops by finding 1,2 and 3 letter words.

#include<iostream>
#include<vector>
#include<fstream>
#include<algorithm>
#include<string>
using namespace std;
int main() {
vector <string> dict,forward,reverse;

[Code] .....

I also tried to find words using the entire vector as a container, the synopsis code that also did not work is below

while(j<dict.size()) {
if(dict[j].size()>2) {
if (std::find(forward.begin(), forward.end(), dict[j]) != forward.end()) {
cout<<"found word "<<dict[j]<<endl;

[Code] ....

Attached File(s)

dumpling2.txt (2.54K)

Dictionary.txt (718.34K)

View 13 Replies View Related

C++ :: Shortest Path Maze Solver Algorithm

Mar 26, 2014

I'm working on a maze solving program. So far I got the program to solve a maze using the recursive backtracking algorithm. I represent the maze as vector<vector<Square>> where Square is an enum that contains the kind of square (empty, wall, etc.). I use a class Point that contains 2 ints which are used for subscripting the vector of vectors. I have a Point begin and Point end. Now I want the program to solve the maze using the shortest path. I can either use the A* algorithm, Dijkstra's algorithm, or the breadth first search algorithm.

View 6 Replies View Related

C++ :: Simple Recursive Maze Algorithm And Counting Steps

Jun 1, 2013

My maze algorithm must be able to count total steps. He is not allowed to "jump" from a deadend back to the cross-way he originally came from.

Code:
int R2D2Turbo::findIt(Labyrinth* incLab, int x, int y){
if ((x == incLab->getExit().x) && (y == incLab->getExit().y))
{
return 1;

[Code] .....

Due to the nature of recursive algoirthms, he jumps instead of moving the way back from the deadend one by one... The only solutions I could think of are way overloaded...

View 3 Replies View Related

C/C++ :: Reading From File To Construct A Pointer Based Maze?

Nov 29, 2014

I'm trying to read a "pointer-based" maze .txt. The first letter in each row corresponds to the room letter...then the letters that follow are North node, East node, South node, and West node respectively. The asterisk indicates an empty room or not a valid option.

Here is what I have come up with, what is happening is after the file is parsed by read_maze it is calling my is_empty function indicating that there is no maze because it doesn't go into the else statement here.

I've attached a sample input file:

 maze.txt (130bytes)
Number of downloads: 19

We can't assume the rooms will be in order alphabetically A - Z, We are expecting a maximum of 12 rooms and there is a space between each letter or asterisk.

void Maze::read_maze(string FileName){

string line;
ifstream inStream;
inStream.open(FileName.c_str());
int test = inStream.peek();
int i = 0;
if (!(inStream.fail())){
while (!inStream.eof() && test != EOF){

[code]....

View 5 Replies View Related

Visual C++ :: Can't Make Maze Work Correctly With Arrays

Apr 30, 2014

I have to make a maze with arrays, but i cant seem to move down or up or at all. Here is what I have so far

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

[Code].....

View 5 Replies View Related

C++ :: Game Design Practice For Accessing Container Of Game Objects

Dec 21, 2014

I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.

The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.

How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?

View 4 Replies View Related

C++ :: Program For Calculating Total Price Of Game Station And Game

Sep 13, 2014

I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.

View 7 Replies View Related

C :: Max / Min Value In Randomly Produced Array

May 10, 2014

I am very much a beginner at C and a large amount of it still tends to go over my head, I've created a 2d array which its size is generated from user input and filled with random integers. Next I need to locate the maximum and minimum figures in the integer and as dull..This is the code I have so far

Code:

#include <stdio.h>#include <stdlib.h>
int main ()
{
int firstDimension, secondDimension, firstDimensionIndex, secondDimensionIndex,index;
int **table;
}

[code]....

View 2 Replies View Related

C++ :: How To Iterate Through A For Loop Randomly

Apr 5, 2013

So I have a vector that I want to iterate through randomly, and by random I mean that each element is only accessed once but I don't want to shuffle the vector because the vector elements are large. So I want this functionality:

std::vector<SomeLargeObjectWithoutACopyConstructor> myvec;
// ...fill myvec
std::random_shuffle(myvec.begin(),myvec.end());
for (auto& value : myvec)
{
// do stuff
}

Only I don't want to do this because the object type has no copy constructor and is large, so I don't want to shuffle the vector, just the iteration path. Is there a simple and efficient way of iterating randomly through a vector while ensuring that each object is only accessed once?

View 3 Replies View Related

C++ :: Loop Randomly Until Get All Seven Numbers

Nov 13, 2013

Is it possible to loop randomly. For example

for ( int i = 0; i<= 6 ; i++ )

I don't want i to acsend from 0 to 6 but i want it to get all numbers randomly. For example

first time r = 5 second time r = 2 and so on

until it gets all the seven numbers

View 4 Replies View Related

C/C++ :: Randomly Moving Characters

Jan 6, 2015

I am making a game and I am attempting to get the zombies to move randomly but for the life of me, I simply don't have the knowledge with srand to do it

#include <iostream>
#include <windows.h>
#include <time.h>

[Code].....

View 13 Replies View Related

C++ :: Getting Sum Of Two Randomly Generated Numbers

Feb 15, 2015

I can't get the sum of two randomly generated numbers - I don't believe the program is adding wrong what I think might be happening is upon hitting enter its adding two new randomly generated numbers -

Code:
// Program functions as a math tutor
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main() {
// Constants
const int Min_Value = 1;

[Code] .....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved