C/C++ :: How To Write A Function For A Single Turn Involving Die In A Game
May 16, 2014
So basically it consists of implementing a single turn for the game called 'pig' and printing out scores and probabilities of those scores. So this is what I have thus far :
int randomNum (int min, int max) {
return min + rand () % (max - min + 1);
} int singleTurn (int holdValue) {
int totalRoll = 0;
int score = 0;
do {
score = randomNum(1,6);
[code]....
View 13 Replies
ADVERTISEMENT
Feb 14, 2013
How would one cycle through a turn order in a turn-based game? I was thinking an array of every creature (including the player) and have a pointer to the array++ after the turn, but I couldn't put all the objects into an array.
View 2 Replies
View Related
Sep 12, 2014
I am starting a turn based battle (similar to pokemon) app. How could i make this and make it cross platform. Also is it possible to make it access gps and allow other devices with the same app communicate with each other?
I have done things on the command line but i never made anything with images so i dont even know where to start for this app.
View 4 Replies
View Related
Nov 1, 2014
I am making a game which is a two player strategic battle turn based game..... The game will require each player to choose a attack. What would be the best key configuration for set of four attack. Like
player 1: 1,2,3,4;
player 2: 7,8,9,0;
where 1&7 are for kick 2&8 are for punch etc.....
or
player 1: q,w,e,r;
player 2: u,i,o,p;
View 2 Replies
View Related
Sep 26, 2014
what I'm trying to do is create 3 child processes stemming from one parent process. I have figured that out but the problem is my program exits when it get to the third child leaving it orphaned(I think).
This is my code for the first generation of processes:
int i = 0;
pid_t child;
about("Dad");
printf("Now .. Forking !!
[Code] .....
I have created a menu GUI that I feel messes with the loop commands, i.e. "Continue". The menu pops up repeatedly after each child process is created. I commented out the block of code for menu which fixed it. I was wondering if there is a way so that I can have the menu not messing with the processing?
View 1 Replies
View Related
Jun 7, 2013
I've got the program for the most part except one part because it's basically wanting me to return 3 values from a single function and I'm unsure how to do this the way it wants me to. The rules:
Call the user-defined function to read in x in the series to be used for calculating the results. Pass a prompt for x as an input parameter, and return the validated x value to main.
After a valid x has been entered, call the same user defined function a second time, to read in y. Pass the prompt for y as an input parameter, and return the validated number of terms value to main.
After a valid y has been entered, call the same user-defined function a third time, to read in z. Pass the prompt for z as an input parameter, and return the validated z value to main.
View 2 Replies
View Related
Jan 14, 2014
I need to write a code (in C99). The programe receives an input number (integer) 'n' and then a matrix sized n*n (matrix[n][n]), all numbers are integers. We're supposed to define the matrix's size with malloc. Now the program needs to sort the lines of the matrix (the number in each line), in a single function (!) this way:
even line index (0,2,4,6...): from small to big.
odds line index (1,3,5...): from big to small.
and then print it.
*note: first line is indexed 0, second line is 1, etc.
I was thinking to sort it with bubblesort function with the following if:
if(i%2==1)
do odds sorting.
else
do even sorting.
when i is the index of the row.
my problem is defining the malloc and how do I send the matrix to sorting.If needed I will attach my current (not so good (completly awful)) code and functions as well as an example of what the prog. supposed to do.
View 13 Replies
View Related
Dec 9, 2014
Write following functions
makingArray: this function will return a double pointer which points to a double array and take one parameter- an integer variable which has a default argument of 5. The argument is the size of the integer array. when the function is called, the users input or default argument will be used for the size of the array. The function will initialize all elements of the array with the 'cin' object.
getTotal: this function will return a double and take two parameters- a double array, which can NOT be modified by this function, and an integer variable for a size of the array. This function will calculate the total of all elements then return a double number which is the total.
main: demonstrate functions( makingArray and getTotal) by calling them in a program
View 1 Replies
View Related
Jan 30, 2014
I am currently trying to write a test program involving constructors. I know what I am about to ask is pretty basic stuff but Visual Studio is not recognizing when I declare strings for some reason. My code isn't completed yet but as I am typing string in to declare the variable in the class Visual Studio is not recognizing string as a usable value.
Code below:
#include <cassert>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class college {
[Code] .....
Like I said... this is completely unfinished I just need to understand why my strings aren't being recognized.
View 2 Replies
View Related
May 12, 2013
I've written a c++ program that contains the following classes: class Shape, Circle, Ellipse, Rectangle, Triangle. All the classes are a subclass of class Shape. They syntax of their definition is fine, I see no visible errors. This is the code:
#include "graphics.h"
//#include <iostream>
using namespace std;
const float Pi = 3.141;
float distance (int x1, int y1, int x2, int y2) {
[Code] ....
Now when I declare a variable of each subclass in the main, I get an error on two of the classes.
int main () {
Circle a;
Rectangle b;
Ellipse d;
Triangle c;
int x1, y1;
float length;
[Code] .....
...And there's a bunch of similar if conditions. My compiler gives an error under b and d, i.e. the Rectangle object and the Ellipse object. The error is, "Expected a ';'" . I have quadruple checked every inch of my code and as far as I can tell, there are no missing semicolons. Where this ";" belongs ....
View 2 Replies
View Related
Dec 8, 2013
The reason being is that it says that my program is right
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define NFlights 10
struct date {
int month;
int day;
int year;
int hour;
int minute;
[Code] ....
View 6 Replies
View Related
Jul 10, 2014
map< int, int > cache;
int count( int n ){
if( cache[n] != 0 ){
return cache[n];
[Code] ....
I don't know how to turn this recursive function into an iterative...
View 7 Replies
View Related
Feb 22, 2015
I am trying to include all repetitions for just one turn but I keep getting
00.0 but I want (the one in red)
170.3 0 0.3
180.0 17 0.0
190.3 18 0.0
200.3 19 0.3
210.0 20 0.3
220.0 21 0.0
22 0.0
so basically I call a function that represents just one turn of getting a random number, and then when the player decides he wants to get a random number that is at least 17 and wants to repeat this 3x I have to print out this chart that shows the chances of the player rolling the numbers between 17-22 [how many times does he get 0,17,18,19,20,21,22] this is what I have
cout << "your score: " << (' ') << "chances for that score:" << endl;
/* score is the player's total score for the one turn */
int score = 0;
int score0 = 0; // 0
[Code]....
View 3 Replies
View Related
Mar 28, 2013
Say you the user inputs x number of names and then is to put in x amount of values for each name. How would you display these values in a 2d array and be able to add the values for each row which will represent each name?
View 5 Replies
View Related
Jul 23, 2013
int main () {
string integer1;
string integer2;
cout <<" enter your first number: " << endl;
cin >> integer1;
cout << endl;
cout << integer1 << " is your first number" << endl;
}
Now how do I turn the string integer into an array?
View 5 Replies
View Related
Dec 9, 2013
I'm having trouble trying to turn a word into letters. I've seen other posts but they deal with a sentence and it only outputs the words only. What I want to know is how do they take a word (Ex: "word") and break it into individual letters, where I want to store them in a vector of string?
If it's not too much trouble, I would prefer without using pointers or "std:: " marks, since I am trying to avoid pointers and I'm using "using namespace std" all the time.
Ex:
In the example "word", it should output into:
"w"
"o"
"r"
"d"
and I will push them back into a vector of string where each vector element contains a letter.
View 2 Replies
View Related
Mar 2, 2014
I know strings are essentially just arrays of characters, so what would be the easiest way to take each individual digit and put it into a separate space in an array?
ex.) *str = "90210"
array[0] = 9
array[1] = 0
array[2] = 2
array[3] = 1
array[4] = 0
All my attempts at achieving this just result in an array full of garbage numbers. What I've done is
Code:
int *array;
array = malloc(sizeof(int)*(strlen(str));
for(i=0; i<strlen(str); i++) {
array[i] = str[i]
}
also, I should mention that the string will be defined in main, and its converted into an array in a separate function.
View 2 Replies
View Related
Dec 11, 2013
[URL] ....
This is my code, but how can I implement this?
View 1 Replies
View Related
Dec 22, 2014
I want to store all the result which are basically 8 points generated after every time function GenTestPoint is called.
how to store all the points generated i.e 4096+512+64+8 points. However, I mainly need the 4096 points which are generated at the end. I am new to programming, not much familiar with pointer and all stuff.
Its start from level 1.
Level 1 = 8 Points;
Level 2 = 64 points;
Level 3 = 512 Points;
Level 4 = 4096 points;
8 points will be calculated only when if statement is true. But it's fine in the worst case all the statements are true and at the end we will get 4096 points. Just consider that all the if statements are true and I am getting 4096 points at the end which I need to store in some GLOBAL Variable.
I need this 4096 points at the end.
void GenTestPoint(Vec3f test, float level) {
float new_denominator = pow(2.0f,level);
Vec3f result1, result2, result3, result4, result5, result6, result7, result8;
Vec3f result11, result12, result13, result14, result15, result16, result17, result18;
result1 = (test.x - 1/new_denominator, test.y - 1/new_denominator, test.z - 1/new_denominator);
[code].....
View 2 Replies
View Related
Dec 4, 2013
I am trying to add a small function to allow me to pause the game I am making. I measure the time elapsed using the following algorithm:
1. USE ""clock_t begin=clock();"" FOR SYSTEM TIME OF GAME BEGINNING.
2. USE ""cout<<(clock()-begin)/CLOCKS_PER_SEC;"" TO DISPLAY TIME ELAPSED IN SECONDS.
Now, if I want to pause, I would want to subtract the 'paused' time from the total time elapsed.Say,
clock_t pause, resume;
{
pause=clock();
.
.
.
resume=clock();
}
Then I would do cout<<(clock()-begin-(resume-pause))/CLOCKS_PER_SEC;
This, though is what I want, works only once(I can pause only once). I can use arrays of resume and pause, but it would still limit the number of times I can pause.
What I am looking for is a way to pause any number of times.
View 3 Replies
View Related
Apr 20, 2013
I was trying to look up solution for this for quite a while already but found nothing. I am writing a simple console based turn based RPG game for my class project. I was trying to have a member function attack() in class of the player character, which affects the component called health of the class Enemy. both this classes are inherited from the base class Unit. I tried to pass the object of type enemy as an argument to the function attack, but the function call gives me Error: too many arguments in function call. Here's the code for classes:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
class Unit {
protected: int power, intellect;
[Code] ....
View 5 Replies
View Related
Jul 10, 2013
So I wrote a program to turn a binary file's data into an unsigned character array for inclusion in an executable. It works just super.
I'm wondering how I can write a program that will perform this operation on every file in a directory and all it's sub-directories so that I can I can include everything I need all at ounce.
View 9 Replies
View Related
Nov 27, 2014
i have a project where i create a dice game, the user rolls 2 dice and the computer roles 2 dice. the player that wins 3 out of 5 rolls wins the game. I have completed the requirements, but i wanted to create a pass by value function for "void Dice()", I'm not too sure how that works?
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//creating my variables and their values
int compinput;
[Code] .....
View 5 Replies
View Related
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
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
Dec 5, 2013
how would one write a function that doubles every element of a 20×10 2-dimensional array? this is what i've got so far.
double arrary [i][j];
for(double i=0; i<20;++i) {
for (double j=0;j<10;++j) {
array[i][j] =
[Code]......
View 5 Replies
View Related