My issue is that my program dies whenever it attempts to readout the average and sum of the rolls. I think I need to include the size function in here somewhere but am not sure how to go about it. Possibly scrap the "do while" loop and go with something else, or just am completely missing something.
Here's the code:
#include<iostream> #include<random> #include<ctime> #include<vector> #include<cstdlib> #include<iomanip> using namespace std; int sum5(int d1, int d2, int d3, int d4, int d5); int DiceRoll();
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;
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:
this function will return a temporary integer now void fun1(const int & num); this function can receive from myfun().BUT void fun2(int & num); this function cannot receive from myfun() Why is that, Moreover what is lifetime of a temporary object like one returned in myfun() ???
The only difficulty im having is creating a class and methods & being able to access them from my win form app. Can i get a few tips on the do's and donts of creating classes / methods and accessing them from form app.
This is what i have put together so far.
public partial class Form1 : Form { private Image[] dicePics; private int[] diceNum; private Random randomize; public Form1() { InitializeComponent();
I'm having a problem adding up the values of the dice rolls in a while loop. The program will only store the last value so how would I get it to store multiples values? Here is my program thus far. I would try an array but we haven't gotten to that yet.
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int die_1=0, die_2=0, total_score1, total_score2, player1score; char enter;
[Code] ....
What operators or equation I should use to accomplish this?
I have written the code below that allows the user to input any sided dice and any number of rolls. The program will print out the output in sequence. I need to sum these outputs into one number, but I am having trouble writing a sum function for this.
//This Program Creates the Sum of a Number of Dice Rolls of the Same Size
#include <stdio.h> #include <math.h> #include <time.h> int rolldie(); int main(){ int x, n, a; //'x' n=number of rolls, a=number sided dice
[Code] ....
The output looks something like this currently:
Please Enter the Number Sided Dice Followed by the number of Rolls... 12 10 4 12 2 10 12 5 5 12 12 5 >Exit code: 0
I am writing a snakes and ladder program and I'm almost finished, but I am struggling with the dice to work in the way I want it to work. I want the dice to work like this :
Before each player throw the dice they must start at 0. Each player must throw a 6 on the dice to move on the board. If a player threw a 6 on the dice, that player can throw again.
But I ended up with two seperate dice, one for each player (game is only for two players).And when I run the program, both players don't start at 0. And when I throw the dice, both players move at the same time but with different values.
If one of my players threw a 6, they just keep on throwing until someone wins the game. I tried to use a switch and if statements but I couldn't get it right. And so I did this :
Code: #include<stdio.h> #include<stdlib.h> #include<windows.h> #define SpaceBar 32// 32 is an ASCII value for a spacebar
I am creating a Matrix class, and one of the constructors parses a string into a matrix. However, printing the result of the constructor (this->Print()) prints what I expect, and an <object_just_created>.Print() call returns bogus data. How is this even possible?
Snippets below:
Matrix::Matrix(const string &str) { // Parse a new matrix from the given string Matrix r = Matrix::Parse(str); nRows= r.nRows; nCols= r.nCols;
[Code] ....
in the driver program, here are the two successive calls
Matrix mm6("[1 2 3.8 4 5; 6 7 8 9 10; 20.4 68.2 1341.2 -15135 -80.9999]"); mm6.Print(); // mm6.Print() calls bogus data, -2.65698e+303 at each location. The matrix's // underlying array is valid, because printing the addresses yields a block // of memory 8 bits apart for each location
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:
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.
In 2D games, what's the best way to handle the order of drawing objects? Because most games have a background, tiles to be drawn behind the player, perhaps tiles to be drawn covering up the player, etc. My point is, with my current setup of simply looping through all objects and drawing, I have no control over what objects are drawn on top of or behind the others. My best idea so far is to hold a vector of object pointers, each vector representing a different "visibility level", like so:
class Level{ //... std::vector<Object> allObjectInstances; std::vector<Object*> visibilityOne; //background objects std::vector<Object*> visibilityTwo; //objects in front of background but not necessarily all the way in front //and so on for more objects };
If I go through with this, I'm wondering how I could loop through all my objects and add them to each vector, then shorten whatever I have to loop through for subsequent visibility vectors. handling the order of drawing objects?
I've been having trouble working on this physics engine of mine. Right now I'm having trouble adding gravity.
The game is a spaceship--which you control--flying around in space with asteroids and eventually the ability to shoot bullets. There should be a wrap on the edges of the screen and gravity for each object depending on their mass.
I'm creating a forceX and forceY for each force put onto each object, and then computing that force into a velX and velY which will determine the direction of each object and at which speed.
Where my problem arises:
Code: //add gravity pulls to forces for(int i = 0; i <= pushCount; i++) //add gravity pulls for each object { for(int u = 0 ; u <= pushCount; u++) //each object should add a force for every other object { if(i != u) { switch(id[i])
How do i read a specific part of a file? I am trying to create a game that reads the prices of an object inputted by the user from a file. This is the code i have so far
#include <iostream> #include <fstream> using namespace std; int main () { ifstream infile; infile.open ("Objects.txt", ifstream::in);
[Code] ....
The file contains this :
Example objects ( ) store items (item) (purchase value)/(sell value)
Grocery Store Items Fish 5 7 Vegetables 10 15 Drinks 20 30
Here is the code I have written so far. My problem is that when the second user enters its position the last user's position is wiped of the board. I want to know how I can hold that position and keep doing so until the game is finished. I thought that calling the previous function would do that (and you can see where I have put that into a comment) but it doesn't.
Code: #include <iostream> //includes header file using namespace std; //function prototypes void printLeftUpper(int i, int j); void printMiddleUpper(int i, int j);
When things at work get overwhelming, it's not unusual for me to briefly "escape" by writing small programs simply for fun. A few days ago, I had an idea for a "binary game". I completed the first draft of it yesterday.
The idea is simple. The game uses 8-bit values. At the start of the game, a random "target" value is generated. The player is dealt a "hand" of seven values. The object is to use the values in your hand, along with some basic logical operations, to create the "target" value. While the idea is simple, the game itself can be quite difficult.
: Looking at the first column: - 'T' is the "target" value - '0' can be thought of as the "game board" - this is the value that needs to match the target value for a win - '1' - '7' are the values in your "hand"
You can apply logic AND ('A'), OR ('O'), or XOR ('X') to a value in your hand with the value on the "game board". You are also allowed to apply logic to two values in your hand to create a new value for your hand. When a value from your hand is used, it is removed.
Some examples of the commands:
A30 --- apply logic AND to value #3 in your hand, and the "game board" value O23 --- apply logic OR to value #2 in your hand and value #3 in your hand X70 --- apply logic XOR to value #7 in your hand, and the "game board" value
You can also be dealt new values (as long as there's room in your hand) with the '+' command. 'H' or 'h' prints the help, and 'Q' or 'q' exits the game.
I haven't thoroughly tested it yet, since I just finished it a yesterday, but so far it looks good. The program itself uses only standard C.
I was dickering with the idea of supporting more logical operators (NOT, NAND, NOR, XNOR, shift), but I like the simplicity and resulting difficulty of the current implementation.
During initial testing, I realized it's possible to have doubles in your hand. Also, it's quite possible to be dealt the target value directly, which means that you could potentially win with one move, chance permitting. At first I thought about defending against these conditions, but came to the conclusion that it is fine as is - chances of an instant win are small, and if it does occur, would still be an enjoyable experience. Besides, if you're dealt the target value after the "game board" value has been modified.
Also, I did not allow a value of "zero" in the players hand. This was originally because I thought it would be of little use (though I've been reconsidering this). This also means that if two values in the hand are combined and result in zero, both values are removed and no new value is added. This was originally a bug, but I think I'll just reclassify it as a feature
So far, I found that the best strategy is to avoid modifying the "game board" value, and just play with the values in your hand. If you can get the target value in your hand, you just OR it with the "game board" and you're done.
I am trying to seed a vector with 52 values ranging from 1 to 52. I already have the code written to seed the vector bu how to keep from repeating the same values from being seeded. This is for a five card stud game.
#include<iostream> #include<cmath> #include<cstdlib> #include<string> #include<vector> #include<ctime> using namespace std;
I have the code to make the text roll. But the problem is that the application can't execute other instructions coz its busy in the infinite loop of the marquee. How do i make the application to execute its normal instructions as well as roll the text simultaneously
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.