C++ :: Game Loop Design - Restart Round?

Sep 30, 2013

I have a simple game loop.

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
}
}

I am faced with the decision of what is the best way of restarting the game. The problem is, the condition for restarting a game is very, very deep inside the game's logic. So returning returning... is not an option, or at least, it ain't gonna be pretty.

So one of my considerations is to use a goto label, like so:

while(true) {
//round initialization stuff
while(true) {
//capture input, make pieces move,
} restart_round:
}

This seems to be the cleanest solution, since it allows me to fully reset the 'state' of the round, by first having all the destructors(pertaining to the round's objects) called, and then the constructors and other initialisation stuff.

Are there any subtleties that I am missing regarding this solution?

View 10 Replies


ADVERTISEMENT

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++ :: Quiz Game - Playing Video In One Round?

Apr 9, 2014

I am making a game of quiz and i want to play a small clip in one of the rounds, but i dont know how to do it in c++ ....

View 3 Replies View Related

C :: Use A Loop To Restart A Program

Feb 21, 2015

I've just started to learn C programming. In following program I need to use a loop, so at the end, it asks the user that if wants to try other numbers or not. If yes program restarts from beginning.

Code:
/*
A program who checks three positive integers to be 3 sides of a triangle and calculates the area and shows the triangle type.
*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)

[Code] .....

View 11 Replies View Related

C++ :: Do While Loop Skips Over Input The Second Time Round

Mar 4, 2014

I don't understand why my Do While loop skips over the input the second time round?

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;
//prototype
string reverseInput(string *);

[Code] ....

View 2 Replies View Related

C :: Round Up To Or Round Off To The Nearest Cent?

Nov 19, 2013

how I would easily round a double or a float to the nearest cent. It was easy enough to do it in visual basic or java, But i cannot figure out how to do it in C.

View 6 Replies View Related

C++ :: Program With Do-while Loop To Restart Program And Validation

May 11, 2013

I am having problems at the end of the program with the do-while loop to restart the program and the validation.

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <time.h>
using namespace std;

[code]....

View 3 Replies View Related

C/C++ :: Factor Game Using Loop

Feb 12, 2015

So I'm doing this problem where the user will input a number that will be factored until the number is 1, 2 people will play this game and they will take turns entering a number that the initial number(named gameN) will be divided by until it is 1. Whoever get it to 1 wins. My problem is I'm not really sure how to do this, I'm pretty new to programming so besides some if statements and a loop, the problem shouldn't require too much to write. Some rules for the game are, the number entered to factor the gameN cant be less than 2, and has to divide evenly into gameN, which I have signifies with modulus. Here is where I'm at so far.

#include <stdio.h>
int main(){
int gameN;
int p1f;
int p2f;
printf("What number should the game be played with?");
scanf("%d", &gameN);

[Code] ....

View 2 Replies View Related

C/C++ :: Updating Window In Game Loop?

May 25, 2014

So I am working on making a game. The first thing I did was make a window class. This correctly makes the window and displays it.

Now, I run my game loop and it just freezes the window and shows the Application has stopped working message box. I believe this is because the Window is not actually being updated.

My game loop however, looks like this.

bool run = true;
while(run) {
Window::Render();
if (Window::IsCloseRequested())

[Code].....

View 4 Replies View Related

C++ :: Guessing Game - How To Successfully Loop Back To The Beginning

Feb 5, 2015

So I'm making my first program w/ C++ and its a game guessing game. I've learned how to use booleans, chars, strings, if/else, loops, and input. Anything past that I dont know. I've gotten my game to work properly except for the fact that when you guess incorrectly, the program closes. I want the program to go to the beginning of the program again so the user can restart. So far i've gotten the loop to beginning thing to work but not well. It'll only repeat twice before closing again and it'll say the user got the wrong answer even if it was correct. Here's my code

#include <iostream>
#include <string>
#include <random>
#include<ctime>
using namespace std;

int game(){
string playerName;
int guess;

[Code] ....

View 1 Replies View Related

C++ :: Number Guessing Game - Play Again Loop Broken

Sep 11, 2013

OK, so the program is working minus the play again loop. I even tried a goto statement for it but no luck. Basically what its doing is after the game runs its course it asks if you would like to play again? If you hit Y it starts over but if you it N it starts over. I want it to out put thank you for playing and close after user hits a button.

// C// Guess My Number
// The classic number guessing game

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

[Code] ....

View 1 Replies View Related

C/C++ :: Yes Or No To Restart A Program Or End It

Aug 8, 2014

I just started learning c++ and got a problem now, i need a Y/N code, i case of yes the loop will restart and i case of no the program will end, Heres the code i got so far from trying to make my first steps.

#include <stdio.h>
void main() {
int a,b,c;
printf ("Zahl 1 Eingeben
");
scanf ("%i",&a);

[Code] ....

As u can see the other printf tasks are in german, but they are not important, the last one needs a Y/N "switch" y to restart the loop, and n to stop the program.

View 2 Replies View Related

C++ :: Tile Mapping Program - Loop Through All Tiles In Game Setting X And Y Coordinates

Jun 6, 2013

void create_map(){

int x = 0;
int y = 0;
while (y >= 15) {
game_map[x][y].pos_x = x * tile_size;
game_map[x][y].pos_y = y * tile_size;

Objective of the code: to loop through all tiles in the game, setting their X and Y coordinates.

It just doesn't do anything at all. No error message.

View 12 Replies View Related

C# :: How To Take A Variable Value And Put It In Database To Recover After Restart

Jul 18, 2014

How can I take a variable value and put it in a DataBase to recover the value after a restart?

View 4 Replies View Related

C :: If Put WRONG Input For INTEGER / Program Will Restart

Feb 15, 2015

I have a question about my program.. I would like to make a program that if you put "ABC" on INT, the program will restart again... below are my coding...but it not works..if i put ABC on INT, the "Invalid Mark.. please re-insert mark :" will repeat, repeat and repeat infinitely...

Code:

#include <stdio.h>
void calcul() {int mark;
char * grade;
if (!(scanf("%d",&mark))){printf("
}

[code]....

View 7 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++ :: Restart Program Every Time Type Move Of Blank Place?

Mar 5, 2013

I have to make a 8-puzzle and I got the algorithm i just dont know how to restart the program every time i type the move of the blank place in the 3x3 puzzle so i dont have to make 10000 lines to solve the puzzle

View 2 Replies View Related

C :: Round Off Float To Integer

Mar 10, 2013

I have a float values I'd like to round off to the nearest integer value.

That is to say, if the float value is 44.234533, the integer value should be 44. If the float value is 44.682101, the integer value should be 45.

How do I do this?

View 4 Replies View Related

C :: How To Truncate And Round A Decimal

Jan 14, 2014

To one decimal place?

Code:

#include <stdio.h>
int main() {
double num, trunc, round;
printf("
Enter a Decimal:
}

[code]...

That's my code currently, I've gotten it to round as I want, but I want it to truncate to one decimal place as well.If i enter 4.157, It should truncate to 4.1, and round to 4.2.

View 1 Replies View Related

C/C++ :: FLTK - Creating Box With Round Corners

May 8, 2014

The problem says: Draw a box with rounded corners. Define a class Box, consisting of four lines and four arcs. So I wrote the below code for that exercise:

#include <Simple_window.h>
Simple_window win(Point(100,100), 600,400, "semi-ellipse");
struct Box: Shape{
Box(Point p, int ww, int hh): w(ww), h(hh)
{ add(Point(p.x-ww,p.y-hh)); }

[Code] ....

When I ran it I faced this exception:

Unhandled exception at 0x757FE9D7 (ole32.dll) in test.exe: 0xC0000005: Access violation reading location 0x00000004.

I know this refers to declaring "Simple_window win(Point(100,100), 600,400, "semi-ellipse");" in global state. But I did that because I had to do it. The problem is that how to attach lines and also object (here b) to Simple_window win in either parts (main() function and also Box struct).

View 13 Replies View Related

C/C++ :: Time Gaps In Round Robin Scheduling?

Mar 26, 2015

I've recently completed a fully functional round robin algorithm for a class, however upon running a myriad of test cases I found where mine fails. I think it best to show with an example:

Process-Burst-Arrival
P1 1 0
P2 1 1
P3 1 4
P4 3 8
P5 5 20

Currently what happens is this, it runs perfectly from process 1 through process 3. However once it reaches process 4 it does the appropriate thing and adjusts my total processing time (q variable) to the arrival time of process 4. Great! But then, it rolls over to check the queue again and it's bringing in process 5, changing q to it's arrival time. Then it proceeds to swap them in and out due to them both now being in the queue and time quantums/slices running out.

My question is this: How/where do I put a lock on the while loop that runs the simulated scheduler (round robin in this instance) to not grab the next process when there's a time gap in between each process.

This specifically is the two lines that I can't seem to get working as they should:

if(arrival[i]>q)
q=arrival[i];

FULL CODE BELOW

#include <iostream>
using namespace std;
void RR(int n, int burst[], int arrival[], int throughput)
{

[Code].....

View 14 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/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

Mar 10, 2015

This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??

#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;

[Code] ....

View 2 Replies View Related

C :: Function To Round A Number To Give Integer Number That Is Closer To Real Value

Oct 9, 2013

I was told to use a round function to round a number to give an integer number that is closer to the real value. (for example if the number is 114.67 I need to print an int value of 115 instead of 114)

I am not exactly sure how a round function works, but I am told to include math.h library. What I try doesn't seem to work.

View 1 Replies View Related

C++ :: Design A Program For A Machine?

Jul 10, 2014

My need is that i need to design a program for a machine. The machine takes "x"qty of load, refines 30% of it and sends back the 70% to the initial position. after how many times, does the qty of the load refined will be equal to the initial load and how many times does it need tot be refined?

View 1 Replies View Related

C++ :: How To Write Algorithm / Design

Nov 16, 2013

How to write Algorithm / Design

View 7 Replies View Related







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