C# :: Creating A Class And Methods For Dice Game?

Mar 21, 2015

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();

[code]....

View 3 Replies


ADVERTISEMENT

Visual C++ :: Dice Game - Creating Pass By Value Function Reference

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

C++ :: Creating Methods For Class List?

Jul 3, 2013

Creating the methods for class List

main.cpp Code: #include "List.h"
int main( )
{
List la; // create list la
la.push_front( "mom" );
la.push_back( "please" );
la.push_back( "send" );
la.push_back( "money" );
la.push_front( "hi" );
cout << "
la contains:
" << la << '

[code]...

View 12 Replies View Related

C :: Simulating Random Dice Roll As A Basis For Chutes And Ladders Game

Jan 24, 2014

I am trying to simulate a random dice roll as a basis for a chutes and ladders game

Code:
int main {
int i = 0, diceroll;
while (i>5) {
diceroll = 1+rand()%6;
i++;
}
return 0;
}

However the numbers get don't seem to be random, it always starts off with 6,6,5.. then its random.

View 10 Replies View Related

C++ :: Dice Game - Receive Same Values When Roll Function Get Call Twice For Same Object

Nov 7, 2013

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;
class Dice {

[Code] ....

Every time the roll_dice function get call twice for the same object, i receive the same dice values.

View 4 Replies View Related

C++ :: How To Call Methods Of Class

Feb 27, 2014

how to call the methods of the class.I have an object call v which is an array and I don't how to call the methods of the class. The error is here:

v.readDates(v[a]);

#include "Date.h"
#include <iostream>
using namespace std;
int main(){
int a;
cout << " HOW MANY DATES DO YOU HAVE? " << endl;

[code]....

View 3 Replies View Related

C++ :: Add And Overwrite Class Methods Through Lua

Oct 9, 2013

I'm using lua 5.2.2 with luabind 0.9.

I'd like to be able to add additional class-methods through lua for any classes that I've bound in c++, but I'm unsure how to do it.

The problem is that luabind uses a function as the __index-metamethod for any bound classes instead of a table, so I don't see a way to access the class-methods at all.

e.g., I'm binding my classes like this:

luabind::module(lua) [
luabind::class_<testClass>("TestClass")
.def(luabind::constructor<>())
.def("TestFunc",&TestFunc)
];

What I essentially want to do is to add a lua-function to the list of methods for this class, and be able to overwrite existing ones:

local t = tableOfClassMethods
local r = t.TestFunc -- Reference to the c++-function we've bound
t.SomeFunction = function(o) end -- New function for all objects of this class
t.TestFunc = function(o) end -- Should overwrite the c++-function of the same name

View 2 Replies View Related

C++ :: Override Few Methods In FILE Class

Oct 30, 2013

I need to override a few methods in FILE class so i defined few methods as

EnCrpt * fp;
fp * fopen(const char * filename, const char * mode);
int fwrite(const void * p,int length,int readLenth,FILE * fpp = NULL);
int fread(void * p,int length,int readLenth,FILE * fpp = NULL);
int fseek(FILE * fpp = NULL,long offset, int whence);
long ftell(FILE * fpp = NULL);
int feof(FILE * fpp = NULL);
int fflush(FILE * fpp = NULL);
int fclose(FILE * fpp = NULL);

I will call fread method in my encrypted file class .. similar to other methods.. is this correct ? can NULL file pointer create issue ?

Because i have so many place where FILE class called i don't want to change everywhere to call encrypted file class so i am override these methods to encrypted file class instead of standrd FILE class

View 9 Replies View Related

C# :: How To Combine 2 Methods To Make SQL Class

Jun 17, 2014

I am given 2 methods and they want me to create a stand alone class for sql that will change the sql string.

my question is how can i take these 2 methods and make one class out of them that will used on various other forms.

#1

public string AuthenticateWithDB(CUiPontisDatabaseSpecification pdb, string sUserId, string sPassword,
bool bCreatePersistentCookie)

#2

public static void ChangeConnection(Util.ODBC.ODBCDSN odbcInfo, CPonDatabaseVendorType dbType, string uid, string password)

they want it so they can use it like

CUiHttpSessionManager.SimpleDataConnectionString = SomeNewClass.CreateSimpleDataConnectionString()

where some new class is my new class

View 5 Replies View Related

C++ :: Compile Method Of Class Separately From Other Methods?

Apr 11, 2014

There is any method to compile a method of a class separately from the other methods and the main.

View 1 Replies View Related

C++ :: Pure Virtual Methods And Interface Class

Jul 11, 2012

I develop add-ons for MS Flight Simulator and I use the poorly documented SDK for this. The SDK provides a .h file in which an interface class is defined (with pure virtual methods only), something like this:

Code:
class IPanelCCallback {
public:
virtual IPanelCCallback* QueryInterface (PCSTRINGZ pszInterface) = 0;
virtual bool ConvertStringToProperty (PCSTRINGZ keyword, SINT32* pID) = 0;
virtual bool ConvertPropertyToString (SINT32 id, PPCSTRINGZ pKeyword) = 0;
};

In my code, I use this interface like this:
Code:
IPanelCCallback* pCallBack = panel_get_registered_c_callback("fs9gps");
...
SINT32 id;
pCallBack->ConvertStringToProperty(propertyName, &id);

Everything works fine, but I don't understand why... I thought the linker would stop with an "undefined symbol" error because the IPanelCCallback methods, such as ConvertStringToProperty, are declared as pure virtual but defined nowhere, and I don't use any library for linking. With such an interface class, I thought I would have to defined a subclass of IPanelCCallback and define the ConvertStringToProperty method.

View 6 Replies View Related

Visual C++ :: Polymorphic Methods In Abstract Class

Oct 2, 2013

Imagine if there is an abstract class with a method (say output or print) which would be inherited by a few other classes. Later objects are created using the inherited classes, and the user wishes to call the above method twice, for eg (i) output/print to screen and (ii) output/print to a file. What is the best way to achieve that.

View 6 Replies View Related

C++ :: How To Access Class Member And Methods From Static Method (signal Handler)

Dec 4, 2014

I am writing my program on C++ language. I have one promblem. I need to set signal handler for my process. As the signal is related with the process on system level I have faced the problem.

My program consists several classes. They are connected together. But it doesn't metter in this case. The problem is that I need to access to member and methods of the class from my signal handler. For instance , I have class named Foo at it has some members and methods.

So from my handler I need to call its function and change members.

I understand that compiler should know that this class instances will exist during all program execution.

I have tried to set static member class Foo instance in another class , but this didn't solve the problem.

What is correct approach to do this. How to correctly implement signal handling in such case.

Here is example of my code

Code:
class MyContainer{
private:
std::vector<Foo> container;
public:
int removeFromContainer(Foo* aFoo) {

[Code] .....

View 4 Replies View Related

C++ :: Creating Game Using SFML

Apr 26, 2014

I'm currently working on a 2D space shooter game in C++ using SFML library. What I need to know is how make an object (ex:laser) fire up from object (ex:player) when a user press button??

View 1 Replies View Related

C++ :: Creating Computer AI For Tic Tac Toe Game

Dec 24, 2014

How I can go about creating a computer AI given the way that I structured my code.

main.cpp

Code:
#include <iostream>
#include "Board.h"
#include <limits>
#include <cctype>
using namespace std;
int main() {
// Welcoming message.

[Code] ...

View 14 Replies View Related

C :: Creating A Kind Of Connect 4 Game

Nov 14, 2014

I'm creating a kind of connect 4 game that will be due on November 30. I'm starting now so that I don't have to worry about it as much later. Anyways, I just started, and I already have some questions/problems. I want to be able to change that numPlayers outside of the function, so I used pointers like my instructor said to, but it is giving me an error that numPlayers(the argument) is not an int*. How do I fix this?

Code:

int numPlayers=0;
void promptNumPlayers(int *numPlayers)
{
printf("Enter the number of players: ");
*numPlayers=readInt(stdin);
if (*numPlayers != 1 && *numPlayers != 2)
}

[code]...

View 3 Replies View Related

C/C++ :: Creating Moving Objects For 2D Game

Oct 21, 2014

I'm working on designing a game in C++ that is similar to the "find the ball under the cup" game. I have a Sonic the Hedgehog icon (weird I know, but it was the first thing that came to mind) that will be hidden underneath one of three rectangular blocks.

Here is how I envision this working:

On the main menu I have 3 buttons which represent 3 different difficulty levels
Easy- blocks move 3 times at a slow speed
Medium- blocks move 5 times at a slightly faster speed
Hard- blocks move 10 times at a fast speed

When the user clicks one of these buttons they will be taken to the game screen.

Sonic will be displayed for 3 seconds and the user will then see him be covered with one of the three blocks.

The three blocks will then move in a random pattern along the middle of the screen at the speed and number of times associated with the button that was pressed.

Once the blocks stop moving, the user is to click on the one they think Sonic is underneath.

If they choose correctly, they'll be taken to a "Winning Screen" that displays a congratulatory message and 2 buttons. Play Again- returns the user to the main menu and the game starts over with a new random pattern. Quit- the window closes.

If they choose incorrectly, they'll be taken to a "Losing Screen" that displays a "Try Again" message and 2 buttons that have the same function as the buttons on the winning screen.

I have never worked with any kind of graphics before other than in HTML and Javascript. I have managed to create the main menu, but how to do the actual game portion of the project. I've been trying to take it a step at a time, (for example, I first figured out how to set the background color for the console window, after I got that right I figured out how to add buttons) but the rest of this seems to depend on each other.

Here is what I have so far:

Main menu:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
class MainMenu

[Code]....

So I've got the screens pretty much designed now (with the exception of the game screen itself) but how to tie everything together.

In case my description wasn't too clear, here is a game that I found on Google that is pretty much exactly what I'm looking for. [URL]

View 2 Replies View Related

C/C++ :: Tic Tac Toe Game - Creating A Menu/choice

Nov 11, 2014

Im trying to create something like a menu in a tic tac toe game. I want the computer to ask the user "who starts first" is it the X or the O who starts first? Then the user should type in either X or O but if he types something else i want to ask again .

this is what ive done :

int main () {
printf("
");printf("
");
printf(" %c | %c | %c
", board[1], board[2], board[3]);

[Code] .....

View 10 Replies View Related

C++ :: Creating 2 Dimensional Console Base Game

Jun 13, 2013

what i got so for my code.

#include <iostream>
#include <windows.h>
using namespace System;
using namespace std;
int refreshDisplay(int , int);
const char wHole = '@';

[code]....

count <<" The oblective of the game is for the player to move around a 2 dimensional playing field and capture the star withought falling into a black hole or walking off the edge of the playing field. The controls are W = up S= down A=Left D=Right" <<endl; how implement 3 black hole X characters and 2 wormhole characters on field @ and a star *. all these char has to be randomly generated.

View 1 Replies View Related

C++ :: Creating A Game - Use Classes For Rendering Objects?

Mar 16, 2014

I am creating a game and I using classes for other things in my game, I was wondering if i should use classes for rendering objects?

View 2 Replies View Related

C/C++ :: Creating Two Dimensional Terminal Based Game?

Apr 4, 2014

i am working on class project in which i have to save the tank from canon....imy tank is moving only when i press the moving key.. and after that i see blank screen what should i do to run my process when i am not pressing moving keys....

View 8 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++ :: Creating Frog Leap Game That Starts At 1 And Finishes At 12

Feb 13, 2015

I have been given the task of creating a frog leap game that starts at 1 and finishes at 12. The layout is as follows. The '@' symbols are just included to show blank white space.

1-----2 @@ 3---4
|@@ |@@@ |
|@@ |@@@ |
5@@ 6------7-----8
|@@ @@@ |@@ |
|@@ @@@ |@@ |
9----10 @ 11 @12

Each number within the game will represent an object, the user will have to reach the 12th leaf start from leaf 1. the frog can only move in the directions of forwards backwards, left and right. Any starting points? E.g. using and array or list? i have a feeling this is going to be a big task. is inheritance possible?

View 1 Replies View Related

C++ :: Creating Game That Will Test The Attention And Mind Flexibility Of User

Mar 6, 2015

I want to create a game that will test the attention and mind flexibility of the user. So the challenge is The user will be given 50 rounds, and each round should generate a random combination of text and words.Then the user must Press 'Y' if the UPPER CASE text spells out a color that match the BACKGROUND. But if the text are in LOWERCASE the user must press 'N'.(Note: you can change the keys to any key from the keyboard if you wish to)

Then I also want my program to record the high score each time the program prompts the user if he/she wishes to play again.

I also want to control the combinations by NOT allowing the text color and background color to be the same.

I also want the combination to generate an AVERAGE of 50% correct combination and 50% wrong combinations. The I want to use is only Red, Blue and Green

HIGH SCORE Determinants:

1. Accuracy ( (Number of corrects / 50 ) * 100% ) - The higher the better.
2. Time in seconds (Time Ended - Time Started) - the lower the better.

Computation for high score: 10 000 * ( (Accuracy) - (2 x total Attempts - Time) )

View 6 Replies View Related

C++ :: Spaceship Game - Creating Gravity For Each Object Depending On Mass

Mar 27, 2012

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])

[Code] ....

View 7 Replies View Related

C++ :: Creating A Game - Read Prices Of Object Inputted By User From A File

Feb 19, 2013

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

Weapon Store Items
Pistol 300 375
Rifle 400 500
Ammunition 20 30

View 4 Replies View Related







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