Hi, iam new to C++, but i thought i'd try making a small game. It is a table, with A-Z across the top and 1-26 down the side. I used arrays in for loops for this. Now i need to work out how to get coordinates (eg, B-14) for random number genorator and user input etc. I cannot work this out, could you please help!!?
19 1532
use your random number generator twice for each random move
case:
array[generator()][generator()];
How is you generator constructed?
Thanks, but its getting the coordinates in the first place that my problem even before generating random ones. this is my code for the table - for(int i=0; i<=size; i++)
-
cout << setw(1) << top[i] << " ";
-
-
cout << endl;
-
-
for(k=0; k<=27; k++)
-
cout << "__";
-
-
-
for(int j=0; j<=size2; j++)
-
{
-
cout << endl << setw(3) << side[j] << " |";
-
-
for(k=1; k<=26; k++)
-
cout << setw(1) << "*" << " ";
-
}
-
Hi, if you have constructed your array as arGame[26][26] then you have a matrix that you can instantly access without loops. If you have a single dimension array you can do the same with a little math.
So, for the above array, B-14 is arGame[1][13] in a single dimension use the following guide: - array[col][row] is array[col + (numcols * row)]
which gives: - int arGames[26 * 26];
-
-
//and B-14
-
guess = arGame[1 + (26 * 12)];
i had to use two arrays, because ones char and the others int - dont know how to do it any other way :(
Are you having problems getting the user's input for cord.'s? or just gernerating then?
is this code for graphically showing the table?
(I added some '{' for better reading )
for(int i=0; i<=size; i++)
{cout << setw(1) << top << " ";}
cout << endl;
for(k=0; k<=27; k++)
{ cout << "__"; }
for(int j=0; j<=size2; j++)
{
cout << endl << setw(3) << side[j] << " |";
for(k=1; k<=26; k++)
{cout << setw(1) << "*" << " ";}
}
so if this is the table itself just being outputted to the screen where's the array or arrays I can't realy help without knowing the real scope of the program...
another thing that might be useful to you is converting the B character to a numeric value for your loop.
First you can use the toupper() function to convert the character to upper case and then subtract 65 (the ascii value of 'A').
If the input is 'D' this will give you the value 3 etc.
use char[ letters ][ numbers ]
you can always cast the numbers as char using some one line function
char convert( int number )
{
switch( number )
case 1 etc.
}
or
use an enumerator (probably the easiest)
or submit and use an int array[][] and whenever you need a letter use something like some function
that does not work for every system
getting anscii values depends (A) on hardware and (B) on the enviroment in which your programming
...there is probably some table with those values you can go against....
some enviroments have a unction for that but that'll depend on the enviroment...
that does not work for every system
getting anscii values depends (A) on hardware and (B) on the enviroment in which your programming
...there is probably some table with those values you can go against....
some enviroments have a unction for that but that'll depend on the enviroment...
How interesting. Which environment does not have ascii values for characters?
And which hardware?
My god, your heads might explode when you see my arrays: -
int size = 25;
-
int size2 = 25;
-
-
char top [26]={65,66,67,68,69,70,71,72,73,74,75,76,77,
-
78,79,80,81,82,83,84,85,86,87,88,89,90};
-
-
int side [26]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-
16,17,18,19,20,21,22,23,24,25,26};
-
-
int k = 0;
-
My god, your heads might explode when you see my arrays: -
int size = 25;
-
int size2 = 25;
-
-
char top [26]={65,66,67,68,69,70,71,72,73,74,75,76,77,
-
78,79,80,81,82,83,84,85,86,87,88,89,90};
-
-
int side [26]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-
16,17,18,19,20,21,22,23,24,25,26};
-
-
int k = 0;
-
Great. And what do these arrays represent?
the top row of the table - A - Z (obviously the 'char top') and the verticle one - 1-26 (int side). its bad i know, but its only supposed to be rough (and just for me)
the top row of the table - A - Z (obviously the 'char top') and the verticle one - 1-26 (int side). its bad i know, but its only supposed to be rough (and just for me)
It's not bad at all and that is not what I am asking you.
What do the arrays represent in your game. What do you want to use them for?
oh sorry - the game is a hidden coordinate that the user has to guess by inputting the coordinates (obviously) - those arrays are for the top and side - is that what your asking?
This is the entire code so far -
#include <iostream>
-
#include <iomanip>
-
-
using namespace std;
-
-
int main()
-
{
-
int size = 25;
-
int size2 = 25;
-
-
char top [26]={65,66,67,68,69,70,71,72,73,74,75,76,77, 78,79,80,81,82,83,84,85,86,87,88,89,90};
-
-
int side [26]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 16,17,18,19,20,21,22,23,24,25,26};
-
-
int k = 0;
-
-
cout << endl << "\t\t\tHIDDEN SQUARES GAME!" << endl << endl << " ";
-
-
-
for(int i=0; i<=size; i++)
-
cout << setw(1) << top[i] << " ";
-
-
cout << endl;
-
-
for(k=0; k<=27; k++)
-
cout << "__";
-
-
-
for(int j=0; j<=size2; j++)
-
{
-
cout << endl << setw(3) << side[j] << " |";
-
-
for(k=1; k<=26; k++)
-
cout << setw(1) << "*" << " ";
-
}
-
-
cout << endl;
-
-
return 0;
-
}
-
I know my toshiba satelite using metrowerks in java don't like anscii it uses some other default as it's base I can't remeber which...
I believe C++ and Java have a function where you can format your char's into anscii values instead of it's default
oh sorry - the game is a hidden coordinate that the user has to guess by inputting the coordinates (obviously) - those arrays are for the top and side - is that what your asking?
I understand. So you do not need to initialise your arrays this way.
if you generate 2 random numbers between 0 and 25, this will be the coordinates of your hidden value. Store the value at these coordinates and let the user guess the coordinates until they are correct or give up.
fistly declare your array like this: - char arGame[26][26] = {0};
Then you generate 2 random numbers and store your prize at those coordinates as indicated previously by DemonPiggles using a variation of this code to generate the numbers: - #include <cstdlib>
-
#include <ctime>
-
#include <iostream>
-
-
using namespace std;
-
-
int generator()
-
{
-
srand((unsigned)time(0));
-
int random_integer;
-
random_integer = (rand()%26);
-
return random_integer
-
}
so you can use - arGame[generator()][generator()] = 1;
so you now have a hidden square with the value 1, while all the other squares are 0.
Take the input of the guess as a character using a variation of below - //Program creates char d, sets it equal to lowercase letter
-
//Converts it to uppercase and outputs it
-
#include <cctype>
-
#include <iostream>
-
-
using namespace std;
-
-
int main()
-
{
-
char d='a';
-
d=toupper(d);
-
cout<<d;
-
}
Don't forget to subtract 25 from the result
and you have the value for the left part of your array.
next take the number input and subtract 1. You now have the value for the right part of your array. - if (arGame[InCh][InNum] == 1)
-
cout << "Congratulations! You have just wiped the hard drive";
have fun
Thank you very much :D
Welcome very much :)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: theodp |
last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml
Microsoft Patents Saving The Name Of A Game
Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM
from the...
|
by: Claude Vernier |
last post by:
Hello,
I'm a C# programmer. I have two projects.
First, write an action scrolling game in C#, (portable to Windows Mobile
eventually...),
This game will look like The Adventure of Link from...
|
by: Gasten |
last post by:
Hello.
The last weeks I've been coding a roguelike (you know, like nethack) in
python using the nCurses library. Some week ago I ran into a problem:
When I made the object for messagebar-output, I...
|
by: hpbutterbeer |
last post by:
We have a Machine Project and my brain is currently in a clouded state. Sorry, I'm just a beginner in C Programming...
Text twist is a windows game whose main objective is to form words out of the...
|
by: raypjr |
last post by:
Hi everyone. I need a little help with some parts of a word guessing game I'm working on. I have some parts done but unsure about others and could use a little advice. Any help is very much...
| |
by: Jeff Rush |
last post by:
At PyCon this year we're going to have a multi-day game programming clinic and
challenge. This is a first-time event and an experiment to find those in the
Python community who enjoy playing and...
|
by: smartx |
last post by:
Hi, I would like to share my knowledge as a game programmer, really
game programming is hard, I don't want to disappoint you, the
important point to become a game programmer is to love game...
|
by: LilMeechc20 |
last post by:
Hello,
I have a group assignment that I have to do. We have to write a Tic Tac Toe game. One person in my group has managed to write the code for a multiplayer (human -vs- human) game and I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |