C++ :: Tic Tac Toe Game - Applying OOP And Arrays

Sep 25, 2012

Objective : Code a game allowing two human players to play tictactoe.

Create 2 classes:
-Create a 3 x 3, 2-D array board class to play the game.
-Player; has a private string name data member and a method that reads the players’ row and column selections from the keyboard.

Create 2 player objects from this class. Name the players Orestes and Xerxes.

Think carefully about board and player classes responsibilities and how they interaction with one another. The players do not collaborate with one another but they collaborate with the board.

My Problem : The program compiles with the header file, but it the displaying is wrong as you will see when you enter your row and column.

Sources
Header file:

Code:
#include <iostream>
#include <string>
using namespace std;
class Board {
public:
void display(char Z[][3], int row, int col);

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Game Freezes When Applying Surface From One Object Onto Another?

May 28, 2013

Been trying to figure out why my program freezes. I know exactly what line of code is causing it, but I can't figure out WHY it's causing it. It compiles fine, there are no errors returned, and then the game just stalls and I have to ctrl+alt+del to kill it.

Anyway, what I have set up is something like this:

main.cpp
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "SDL_image.h"
#include "SDL_rotozoom.h"

[Code]....

This is the line of code that's freezing the program. Simply put, so that you don't really have to go through it piece by piece, what I have done is:

*each player gets their own drawing surface called PlayScreen
*each player gets an array of 360 drawing surfaces called ShipPic. These are to keep the game from having to render the rotation pics of the ship on the fly.
*Get_Ship clips the requested ship picture out of the ship sprite sheet and puts it in ShipPic[0] for the original angle.
*the original picture is rotated by 1 degree and put into the 360 ShipPic slots.
*when the player rotates their ship, the angle changes, and it calls the ShipPic with the same number as the player's angle and places it on the screen.

All of this works perfectly.

Then, in Player::draw_screen(), I have it set up so that each player looks at all the other players and gets their distance. If they're within range, it takes the other player's picture rotated by the other player's angle and puts it on the current player's PlayScreen. This is where it freezes.

I've checked for NULL pictures, I've checked to be sure the angle is between 0 and 359, nothing makes any difference. I know it's reading the other player's information since I can output all of the player's X & Y coordinates, angles, the width/height of their pictures, etc. on each other's screens. So they're definitely talking.

To test the code, I've changed it from

Apply_Surface(ShipX, ShipY, p[i].ShipPic[(int)p[i].angle], PlayScreen);
to
Apply_Surface(ShipX, ShipY, p[ID].ShipPic[(int)p[ID].angle], PlayScreen);

And it works perfectly, placing the player's OWN picture in for the other players. So the function works. It's just when I try to take another player's picture and place it on the current player's screen that it freezes.

I've tried quite a few different ideas, such as creating a temp drawing surface to blit the other player's picture onto, but again, it freezes as soon as I try using the other player's pictures.

View 5 Replies View Related

C# :: Snake Game Using 2D Arrays

Jun 1, 2014

I'm trying to make a simple snake game in C# using 2 Dimensional Arrays . I have a grid of labels. I am having problems with differentiating the head of the snake from the rest of it's body. Also I need generating 2 random numbers and filling them inside my array.

I don't know how to place random food on my array. This is because the food can't be placed on the location of the snake. Which brings me to my other problem which is keeping track of the snake and updating it. I don't know what structure to use and How to actually do the above methods. I've tried looking at a lot of sample snake projects but they don't have arrays in them.

View 14 Replies View Related

C++ :: Saving Huge Arrays For Game?

Nov 3, 2013

I have been coding a while on a 2D random terrain game. How would I go about saving the maps? I have an array for blocks, lighting, background and background lighting. The lighting is done in real-time, so exclude that.

But with two 32000x3200 arrays, I still need to store 204800000 separate numbers in a file. Oh god. How can I have this? I could write down the separate numbers, but...yeah.

If it matters, this is made in freeglut.

View 2 Replies View Related

C :: Creating Match-3 (Candy Crush) Game Using Arrays

Mar 6, 2015

I'm supposed to create a "game" that is similar to Candy Crush or Bejeweled. The assignment takes in a .txt file that contains a matrix of values from 1-5 and then assigns each value to a spot in a [10][10] array. Then an Escape Code function prints out colored pixels in place of the number values for each spot, creating a "game board" looking output. Finally, the program is supposed to look for any matches of 3 same-colored pixels and replace them with a white pixel and "XX". Then the program prints the corrected game board with the matches X'd out.

I have it mostly coded, but I've encountered a couple of issues.

1.) I am supposed to label the columns and rows 0-9, and while I have no problem coding the labels for the columns using printf( ), when I try to print the row labels I get a random string of numbers.

2.) I replaced the matches with white pixels by reassigning the value in the array to 7, for which the ANSI Escape Code is white. However, I'm unsure about how to print the "XX" in the same spot.

Here is the input(.txt) file and the output of the program so far:

And here is what I have coded at this point:

Code:
#include <stdio.h>
void printEscapeCode(int c);
int main(void)
{
/* Declare an image array to be gameboard */
int gameboard[10][10];
/* Declare variables and load in how many rows and columns */
int Nrows;
Nrows = 0;

[code]....

View 2 Replies View Related

C++ :: Making Arrays For Equipping Weapons In Simple RPG Game

Feb 26, 2014

I have a sword(25 damage), spear(20 damage), arrow(15 damage), dagger(10 damage) and knife(5 damage). I want to make a class for them so that I can equip one of them in battle and use them to inflict damage.

View 1 Replies View Related

C/C++ :: Madd Libs Game - How To Store Inputted Strings Or Values To Arrays

Nov 11, 2014

My assignment is writing Madd Libs game. I still do not understand how to store inputted strings or values to arrays. I need explanation of collecting inputted data to arrays.

#include "stdafx.h"
#include<stdio.h>
//#include<string.h>
int main(void) {
char string[37] = {''};
char adjective1[15];

[Code] ....

View 14 Replies View Related

C/C++ :: Applying Texture To Sphere?

Apr 19, 2015

I am currently trying to apply a texture to a sphere I made, and have been following various tutorials. My program no longer crashes (used to be a problem but I figured it out), but the texture isn't being applied to the sphere. I used glut and SOIL to do this, but I am pretty sure that I am missing some necessary code from my own program for the textures to work. Because my program is a bit different from the tutorials though, I can't figure out what it is that I am missing. Below is what I have written to this point. It all compiles, and it successfully displays two objects (a sphere, and a pyramid), but neither object has textures, the pyramid simply has the colors it was set with (supposed to, I want to texture map the sphere first), while the sphere is a solid blue. What am I missing or what do I need to move?

#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

[code]....

View 9 Replies View Related

C/C++ :: Applying Limit To Recursive Depth?

Jul 9, 2014

I wrote this code, but now need to apply a limit to the recursive depth. This is the format that I have to use. How would I pass a limit so that it stops after a given number? I'm just confused about where to apply it.

int compute_edit_distance(char *string1, char *string2, int i, int j, int limit) {
if (strlen(string1) == i) return strlen(string2) - j;
if (strlen(string2) == j) return strlen(string1) - i;
if (string1[i] == string2[j]) return compute_edit_distance(string1, string2, i + 1, j + 1, limit);

[Code] .....

View 4 Replies View Related

C# :: Applying Dijkstra Algorithm To Graphs?

Jan 30, 2015

I'm attempting to build a tool for a Minecraft mod called Thaumcraft. In it, there are various aspects of magic that are used in a little research minigame; basically, you have to link Aspect A to Aspect B by the aspects either used to make them, or the aspects that use them in their creation. I figured the easiest way to find a path from A to B would be to relate them via graph object, the code for which I found here, minus the IEnumerable<T> dependency on the Graph<T> class itself, because that requires I build an IEnumerator<T> class and it seems difficult I can do without.

Must be between MinSteps and MaxSteps (say, between 3 and 5 steps).Must use either a source aspect (as in, the current aspect requires it to be built), or a destination aspect (as in, the current aspect is used in its creation).An aspect requires two other aspects of a lower tier to create it.The only exceptions to the above rule are the Primal aspects, which require no aspects to build them.

Here's my Aspect class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace Pathfinder

[code].....

View 2 Replies View Related

C/C++ :: Applying Heat Flux On A Surface

Apr 21, 2014

I am trying to write udf for heat flux on X-Y plane in Fluent having the formula

Q(Y) = (0.304)/(deltaY + deltaY/2)^-3
Where deltaY = 50cm and
Y = 10m

but I am unable to do it. Can write udf for heat flux? Y is the length on Y-axis and X whixh is equal to 5m is length on X-axis. Q is heat flux goes through X-Y plane in Z direction. Geometry is a cube with dimension 10*5*0.005 all are in meters.

View 1 Replies View Related

C++ :: Applying Bubble Sort On Linked List

Feb 27, 2015

I'm trying to apply a bubble sort on a linked list. It works in the first traversal, but then after the code cPtr = nPtr;, it inputs repeated digits at the end of the (semi-sorted) linked lists.

View 1 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++ :: Using Arrays As Sources Of Data For Arrays In A Structure?

Feb 6, 2014

I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.

I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.

How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)

Code:

int _tmain(int argc, _TCHAR* argv[]) {
int comm = 10;
int targ = 5;
int death;
struct AI_WORDS

[Code]....

View 2 Replies View Related

C :: Assigning Values To Arrays / Printing Arrays

Jul 1, 2014

Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.

I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] .....

View 3 Replies View Related

C++ :: Ranged For Loop With Arrays Of Arrays

Dec 17, 2014

int arr[4][5];
for (int(&row)[5] : arr){
for (int &column : row){
} }

Why do we name it row instead column?

int arr[row][column]

Wouldn't this be like

int arr[4][5];
for (int(&column)[5] : arr){
for (int &row: column){
}

It just seems funny to me because we use row[5] which should be 4 if we meant row? Or did I read it wrong in C++ prime !?

View 2 Replies View Related

C++ :: Dynamic Creation Of Arrays Of Pointers To Arrays Of Pointers

Apr 15, 2013

I'm trying to write a function that takes a 32bit address and a data to store at this address.

I'm wanting to take the 32 bit memory address eg 0x12345678 and split it
into 4 x 2 bytes
12, 34, 56, 78

then each of the 4 entries is at most a 256 entry array.eg
FF, FF, FF, FF

So in this example, 0x12 points to 0x34 in the second array, which points to 0x56 in the third array, which finally points to 0x78 in the last array. This last array holds the actual data.

After successfully doing 0x12345678, say I might get a read for 0x1234AABB. So, the first and second pointers already exist, but I then have to create and write to dynamically created arrays.

The arrays need to have all entries set to NULL so that i know whether to follow the pointers to overwrite a previously entered value or create new arrays and pointers.

It all looks good and simple in the pseudo code I've written up but I'm having trouble coding it. I'm currently trying to deal with the first entry case, ie all array elements are NULL, but I'm getting confused with the pointers and creation of new arrays.

void cpu::store(unsigned int mem_add,unsigned int mem_val) {
int first = (mem_address&4278190080)>>24;
int second = (mem_address&16711680)>>16;
int third = (mem_address&65280)>>8;
int fourth= (mem_address&255);

[Code] .....

A1 has been declared as
int* A1[256] ;

View 3 Replies View Related

C++ :: Making A Game With GUI

Feb 27, 2015

Here's my game, what do I need to learn to make a basic GUI? (Easiest way possible for now).

--NOTE, the code was a bit too long for me to post. I can add it if it is necessary. Basically all I want are 4 buttons on the main screen, one that says "Arena," "Store," "Stats," and "Exit."

There will of course be sub menus to each option, but we will get to that later.

View 1 Replies View Related

C++ :: How To Set If Health 0 Game End

Mar 10, 2014

How i can set if health 0 game end?

#include <Windows.h>
#include <iostream>
#include <BluetoothAPIs.h>
#include <ws2bth.h>
bool Move(int xadj, int yadj);

void LoadMap();
void DrawScreen();

[Code] ....

View 3 Replies View Related

C# :: Three And Four Player Uno Game

Feb 26, 2015

I'm having some problems figuring out 3 and 4 player games in an Uno game I'm working on. I'm not sure what specifically the problem is, however. I've tried everything I can think of; I'm at a loss for what to do next. Two player games work perfectly, which makes the nonfunctional 3 and 4 player games seem odd to me. Here is the code:

public void MoveOpponents() {
if (nextPlayer == 0) {
if (Main.dir == Direction.Clockwise) nextPlayer = 1;
else nextPlayer = numPlayers - 1;

[Code] .....

The code for the human player is in Update(), but I won't show that because it's actually quite similar to the above code.

Right now what it's doing is jumping all over the place, making opponent 2 play before opponent 1, then I play, then opponent 1 plays. Then I play again. It's really messed up.

View 6 Replies View Related

C++ :: Tic Tac Toe Game With Multidimensional Array

Jan 13, 2015

Problems :

1) Is there any way so that i can use "X" and "O" char instead of 9 and 0 int.?? I also tried to use enum but was only able to print out -1 for 'X' and 0 for 'O'...

2) if player - 1 choose field 2 . and player - 2 chooses field 2 .. how can i show error and ask for another input ?

3) is there any short coding trick for int check_result(); ?

Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

[Code] ....

View 3 Replies View Related

C :: Can't Determine Tie Status Of The Game

Nov 12, 2014

I've made an effort for three days to write this code. But, my brain has stopped now. I wrote code to find the status of the game (win, loss or tie). However, I can't determine the tie status of the game. Tie status is the problem

View 5 Replies View Related

C :: Save And Load Game

Nov 26, 2013

I am trying to put my Save and Load function in my game, this is what i have:

Code:
/* Save game */
void GuardarJuego() {
FILE *fsave;
char turno;
fsave=fopen("SAVE.txt", "w");
fputs(*****, fsave);

[Code] .....

My game code is this: [C] GameCode - Pastebin.com

View 8 Replies View Related

C :: How To Continue Minesweeper Game

Oct 24, 2013

I am just now in my first programming class for learning C language and I am stuck on one of my homework assignments. I am not asking you to write the code for me or anything because I want to learn by doing it myself but all I am asking for is some pointers to where I am messing up. My program is already finished for what she asked for but I am trying to do an extra credit where she wants us to have the user decide how big the gameboard is and how many mines to hide in it. Really I know that I need to use srand() and rand() but I am not sure how to use them to randomly place mines and without placing mines on top of others.

Code:

//Program 3 "Minesweeper" by Casey Samuelson
//10-17-2013
//This program will imitate the game Minesweeper.
//Agorithum

[Code]....

View 4 Replies View Related

C :: Correct Answer Does Not End Game

Feb 21, 2013

Okay so I thought I had this assignment completed properly last week. Last night I found a bug while playing the game.why won't the game end when the player guesses the correct number? The game allows you to finish using the max number of guesses even though you already guessed the correct number.

Code:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAXGUESSES 6
#define MAXGAMES 20
#define MAXNUMBER 100
}

[code]....

View 9 Replies View Related







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