Ahah, I shouldn't have changed it to Ex. It works now, my smurf is very happy and he thanks you deeply.
LieAfterLie 10 Light Poster
Okay.. I switched from libglew32.a to libglew32.dll.a, and... it compiled!! But, I didn't get a window, just an empty console. And when I switch from 'debug' to 'release' it just gives a bunch of errors again.
build/Release/MinGW-Windows/Opengl_3.o:Opengl_3.cpp:(.text+0x2f): undefined reference to `wglMakeCurrent@8'
build/Release/MinGW-Windows/Opengl_3.o:Opengl_3.cpp:(.text+0x3d): undefined reference to `wglDeleteContext@4'
build/Release/MinGW-Windows/Opengl_3.o:Opengl_3.cpp:(.text+0xb2): undefined reference to `ChoosePixelFormat@8'
(etc)
Edit: Nevermind about the debug/release thing, it turns out I added libraries only to the 'debug' version.
Edit again: RegisterClassEx(&wc) is returning false.
LieAfterLie 10 Light Poster
Yeah, I figured the pragma thing wasn't doing anything, because it didn't for dev. That's why it was commented out before. I just uncommented them for NetBeans in case they did. I also already had glew32.dll installed.
I had gone through all the menus, and the only thing relevant I could find was tools>options>c++>project options, where I had glew32 and opengl32 added as make options. Turns out that there's a wealth of project options hidden elsewhere, outside the menus, after right clicking on a project root in the expanding project browser on the left, and going down to properties.
I didn't know I needed gdi32 though... I've spent a couple days straight trying to get this to compile and I never found that.
And I knew it was an empty window, hah. I said that in my first post.
I am getting fewer errors now, thank you.
build/Debug/MinGW-Windows/Opengl_3.o: In function `ZN13OpenGLContext15create30ContextEP6HWND__':
C:\MyProject/Opengl_3.cpp:60: undefined reference to `_imp__glewInit'
C:\MyProject/Opengl_3.cpp:70: undefined reference to `_imp__wglewIsSupported'
C:\MyProject/Opengl_3.cpp:71: undefined reference to `_imp____wglewCreateContextAttribsARB'
That's all of them.
LieAfterLie 10 Light Poster
I installed NetBeans, MinGW, MSYS and your glew, but I'm still getting undefined reference errors.
build/Debug/MinGW-Windows/Opengl_3.o: In function `~OpenGLContext':
C:\MyProject/Opengl_3.cpp:21: undefined reference to `wglMakeCurrent@8'
C:\MyProject/Opengl_3.cpp:22: undefined reference to `wglDeleteContext@4'
build/Debug/MinGW-Windows/Opengl_3.o: In function ZN13OpenGLContext15create30ContextEP6HWND__':
C:\MyProject/Opengl_3.cpp:47: undefined reference to `ChoosePixelFormat@8'
(etc)
I changed the beginning of Opengl_3.h to this
#pragma once
#include <windows.h>
#include <iostream>
#include <GL/glew.h>
#include <GL/wglew.h>
#pragma comment(lib, "libglew32.a")
#pragma comment(lib, "libopengl32.a")
LieAfterLie 10 Light Poster
I was following this tutorial for my first attempt at OpenGL. All I'm doing is initializing an empty window. His VS 2010 code is here. Using Dev-C++ as my IDE on Windows 7, and MS SDK 7.1, I get this error:
[Linker error] undefined reference to `_imp____wglewCreateContextAttribsARB'
ld returned 1 exit status
[Build Error] ["My] Error 1
I have -lopengl32 and -lglew32 as my linker parameters, and I've tried adding -lglu32 too.
Here's my code.
Opengl_3.h
#pragma once
#include <windows.h>
#include <iostream>
#include <GL/glew.h>
#include <GL/wglew.h>
//#pragma comment(lib, "glew32.lib")
//#pragma comment(lib, "opengl32.lib")
/*
OpenGLContext is a class designed to store all of your OpenGL functions and keep them
out of the way of your application logic. Here we have the ability to create an OpenGL
context on a given window and then render to that window.
*/
class OpenGLContext {
public:
OpenGLContext(void); // Default constructor
OpenGLContext(HWND hwnd); // Constructor for creating our context given a hwnd
~OpenGLContext(void); // Destructor for cleaning up our application
bool create30Context(HWND hwnd); // Creation of our OpenGL 3.x context
void setupScene(void); // All scene information can be setup here
void reshapeWindow(int w, int h); // Method to get our window width and height on resize
void renderScene(void); // Render scene (display method from previous OpenGL tutorials)
private:
int windowWidth; // Store the width of our window
int windowHeight; // Store the height of our window
protected:
HGLRC hrc; // Rendering context
HDC hdc; // Device context
HWND …
LieAfterLie 10 Light Poster
And if you want a console that stays open afterward like IDLE does, for browsing objects and output, use
C:\PythonXX\python.exe -i "$(FULL_CURRENT_PATH)"
I'd sage this post but I don't see an option..
LieAfterLie 10 Light Poster
Problem solved itself, I'll never know why it did this though. :/ Oh well. It lasted for several days.
LieAfterLie 10 Light Poster
I got a laptop with vista and connected to the wireless router here with no problems. Everything went along smoothly for a couple days then it decided to quit working. My wireless connection is still perfect, I can ping and browse anything by IP only. It stopped resolving domain names and typing google.com gets nowhere, firefox gives me the standard 'Server not found, Firefox can't find the server at www.google.com' message. nslookup fails as well. I can ping my router, and another computer I have connected to the router via ethernet works just fine. I nslookup'd google.com on it and pinged the IP and loaded the google page perfectly with the IP address, but I can't look up and IP addresses on the laptop.
Internet Connection Sharing is disabled on each computer, and when I ping google.com from the router itself it resolves and gets replies.
Any ideas? I'm getting really angry about this, I've spent all day trying to figure out what's wrong. Google has failed me and I don't see any reason why I can't resolve domains. Until I get this fixed, my laptop is crippled.
LieAfterLie 10 Light Poster
ahh, carriage return... What exactly does \r do in text files? How is that typically interpreted by the font? I think in terminals, it goes back to the beginning of the line without going down to a new one, but I've seen it displayed differently in different terminals. Some will need both, and some automatically do the newline when they display a \r.
LieAfterLie 10 Light Poster
For some reason, newline characters seem to be using 2 bytes in text files instead of one. Is this normal? When I open a text file and look at the size, I get one more for every character I add, except for newlines, which add 2 bytes.
LieAfterLie 10 Light Poster
It works now... wow
I just assumed that would make it send a literal "%1", like it sends /c. I feel like an idiot now, I knew that % was just the escape sequence... After all, that's how it works everywhere else. ("\n" doesnt mean \n, it means newline, even though it's in quotes. *slaps forehead*) I was going off of what I saw other file types do, like notepad. It has
C:\WINDOWS\system32\NOTEPAD.EXE %1
but now that I think about it, that doesn't need to have quotes around the executable path either... hmm... and I knew mine didn't work without those.
Thanks
I still wonder why that caused that though....
LieAfterLie 10 Light Poster
I'm making a program that compresses text files using the LZW compression algorithm and creates a seperate compressed file. I made a file type and extension and icon for this file type (.nct), and set up 2 actions for it - one that calls the program and passes the .nct file path name, uncompresses the file and displays the text in the executable window (default), and one that recreates the original .txt file (simply passes a "/c" before the .nct file path name, only accessed by right clicking the .nct). I haven't even started with the program, I'm just experimenting with the file type and argument stuff. When I drag the .nct (not a real file, just a short text file with the extension changed to nct) onto a shortcut to the program (for now it just tells me the number of arguments passed to the program (the first main() argument) and the arguments themselves (the second argument to main(), an array of pointers to char arrays)), it gives me 2 arguments - the executable path and the nct path, as I would expect. (It shows '-' at the beginning and end of the strings, so I could verify there were no spaces at the end.)
Output:
nNumberofArgs = 2
The arguments are:
0-C:\Program Files\Text Compress\TextCompress.exe-
1-C:\Documents and Settings\Nick\Desktop\hioo.nct-
That's it
Press any key to continue . . .
But when I double click the nct or right click and select open …
LieAfterLie 10 Light Poster
Care to be a little more specific?
LieAfterLie 10 Light Poster
Okay, I'll use a multidimesional array to store the 'objects'. I just thought it would be helpful if I could name them different things and use the default copy constructor/copy assignment constructor, like b = a;
or point top (c);
. Don't you think such a member-modifying feature should be added to C++? It would be awesome.
:)
LieAfterLie 10 Light Poster
Well I need each x member to have different instances, like this:
struct point
{
float x, y, z;
}
point a, b, c;
a.x = 10;
b.x = -50;
c.x = 2000.3258;
a.x += 20; //
b.x += 20; // now how would i do this in one statement?
c.x += 20; //
and yet be able to modify them all, even if there were hundreds of instances of point.
LieAfterLie 10 Light Poster
How would you change the same member of many objects of the same class (or structure if possible)?
struct point
{
float x, y, z;
}
point a, b, c;
a.x += 20; //
b.x += 20; // now how would i do this in one statement?
c.x += 20; //
I don't see how inheritance or polymorphism would apply, and as far as I know they don't work with structures anyway, and I really have no need of classes. So how would I change all point::x members universally regardless of how many or what objects use it?
LieAfterLie 10 Light Poster
Thanks, that's exactly what I wanted, Sleep()
works perfectly. Capital S, milliseconds, like vegaseat said. All it needs is iostream though, not windows.h or anything else.
aeinstein commented: Always nice to see someone post how there issue was resolved. +10
LieAfterLie 10 Light Poster
I experimented with the SetPixel() function in console mode as suggested by Vega, it has renewed my interest in C++. It's nice to know I can indeed do something beyond text stuff. I just made a quick bouncing ball thingy, now I'm done with that phase, I can stand to sit and read the WinAPI tutorial linked at the beginning. I admit the first time it shocked me a bit to see that it took 70 lines to set up a real, empty window. I can read it now though, I've reminded myself that there are fun things in this language.
BTW, I tried SetPixel() in Windows App mode, purely by accident, and it did indeed create a sin wave in the top left corner of my screen on top of my compiler. Not that there was any reason it wouldn't have, I just thought it was interesting.
LieAfterLie 10 Light Poster
ahahah, I knew that :o
thanks
LieAfterLie 10 Light Poster
How would i specify a Win32 project in Dev-C++? All that's listed is console, windows app, static library (.a), DLL and empty project.
LieAfterLie 10 Light Poster
Use arrays rather than pointers when you can, they're simpler. And watch that accidentally putting stuff at the end of a comment when you wanted in the code. You did that a few times, it was confusing. And use \n (newline character, yes it's one character, so '\n' is valid) in a string to do the same thing as endl, it's more convenient most of the time.
#include<iostream>
using namespace std; // a little simpler, but the same thing
int getcoins ()
{
int total = 0, number;
cout << "Put in coins: ";
while (total < 65)
{
cin >> number;
if (number == 100 || number == 25 || number == 10 || number == 5)
total += number;
else
cout << "Bad coin.\n"; // added a way to indicate it didnt accept the entered value
if (total < 65)
cout << "Total so far: " << total << "\nAdd more coins: "; // added total so far
}
return total;
}
//function to see if selection is available
bool checkselection (char machine[], char select) // seperate your comments and functions,
// the compiler was including the function name in the comment
{
// took out declarations for machine and select, they're declared in the function parameters
bool isavailable = false;
for (int i = 0; i < 9; i++)
{ // added brackets ( {} ) for the for loop
if (machine[i] == select) // when you have more than one statement under one if, they …
LieAfterLie 10 Light Poster
How would you make the program pause for a certain amount of time? I can't just tell it to do some trivial task over and over for so many loops, because the compiler seems to know its trivial and cuts it out. There's gotta be a simpler way anyway.
LieAfterLie 10 Light Poster
Wow thanks awesomeness. Visited by the almighty cscgal too. And WinAPI is the same as the Win32 API right?
LieAfterLie 10 Light Poster
Yay, Wikipedia! Oddly enough, I never tried API in Wikipedia, although I've put almost everything else i could think of in it. And also oddly enough, I have that exact link already in favorites waiting for me to wade through it. (Dragon's tutorial, that is.) I know you never really finish learning C++, I just meant like I finished learning the basic language and enough to understand most of the concepts and techniques, even if not the applications, tricks, uses of the individual techniques and infinite things it can do. This coming from one who just previously knew almost nothing of programming beyond idle BASIC-like programs made on my school-issued TI calculator during, yes, school. I want to know everything I can learn to do right now (that can be integrated and used with C++, as it's my current and only base to work from), and more advice from the awesome people in DaniWeb. Is the Win32 API where I should start now? Anything else I should/might be interested in at this early stage?
LieAfterLie 10 Light Poster
Okay, Iv'e finished learning C++. What can I do with it? Specifically, I want to do some graphics stuff, anything beyond iostream and fstream. What comes after C++? I know it does more than this. If I could just have a function to set a pixel, I could make my own functions for lines and circles and even 3d and whatever else. I've heard of OpenGL and Direct3D, and I know they're API's. What exactly is an API? What does it do, how is it different from other things? Does it just let you access hardware abilities? For now, I just want the simplest, most basic, easy-to-use method for outputting a pixel. I've heard of GUI programming, what is it (beyond what it stands for :rolleyes: ) ? And if I were to learn an API or different, complicated graphics thingy, what's the difference between them? I know D3D is for Windows and OpenGL is portable and entirely high-level, i've read some articles and stuff trying to find something fun to do with C++, but nothing is very specific. Any information would be helpful, I would like to know every practical option available. I use Windows XP and Dev-C++.
LieAfterLie 10 Light Poster
So I guess there isn't a simple way? It would have made C++ a bit easier I think. :-| Well, I can't make it global or anything, cause it has to be in a block that tests the condition first, which is the cause of the scope problem anyway. Thanks again, you helped me understand. I guess I'll just keep doing it the way i was if i need it to be local everywhere in main(). After all i guess there's nothing wrong with copying the array like i said first, I'll use your method whenever the array doesn't need to be accessed everywhere. I bet scope gives alot of newbs trouble.
LieAfterLie 10 Light Poster
Say I have an array, and I want the content (which list it's iniliazed to) to depend on, say user input, like you said, and like your examples. There's no need for the conditions to change, say they are just numbers from user input. And then the array could be accessed freely throughout the program, having the value list that was picked by the user.
I think i understand now thanks, the access of the array has to be in the same block it was initialized in? A scope thing? Is that why it won't work (says undeclared) if its accessed after the if-condition block that declared it?
LieAfterLie 10 Light Poster
Hi, i'm new to C++ (well actually i just haven't looked at it in awhile) and I've been trying to figure out how to make my array's content depend on a condition. It's not extremely important, but I think there's got to be an easier way than what I'm using. I would like to know the best way to fully assign an array with one of many possible sets of data, depending on a condition/s. I've realized (atleast i think, correct me if i'm wrong) that the only way to store lots of values to an array without storing the elements individually or copying a different array to it (but that would be element by element too, just with a simple loop) is when you first initialize it, and nowhere else. Problem is, if i use conditions and declare/initialize the array to different possible things it has a compile error, saying that the array is undeclared when i first access it. If i dont have an unconditional declaration of the array somewhere, it won't even compile. But, the array can only be initialized when it is declared (i think, again help me out here) so i can't have more than one potential initialization. I can't declare an array and pass the address to a function (which function depending on a condition) because the array would have to already be declared to pass it, which means my oppurtunity to initialize it is gone. I can daclare/initialize different arrays unconditionally and then …
LieAfterLie 10 Light Poster
I would like an answer...
I know they seem unrelated, but all these questions have come up from my 15 puzzle program (first program) and are probably simple to most people.
LieAfterLie 10 Light Poster
I would think specific things like that are easy enough to find online. Yahoo and dogpile and search engines like that are better at finding researchy/technical stuff than Google I think, just search. I am new, forgot the exact syntax of heap commands (I know it involves new and delete), and dont know what stackframes are. No one else replied, so i thought i might suggest basic searching.
LieAfterLie 10 Light Poster
Thanks. I didnt think to use a matrix like that, so that i dont have to reference every solution individually, i can reference by number (which is sortof what i was looking for to begin with). I wouldn't need getSolution as a function, would I? Since it would only be called once in the program (or atleast only typed once)? Unless it has something to do with static? What does static do? Is it possible to return an array in a function, or only its pointer? And I still would like to know (even though i have no immediate need now) if its possible to store an array with {1,3,6,2....} while not initialising it. Tell me if i'm wrong, but i think i've noticed that you can use either an array or a pointer as an argument (they'd be used differently in the function, of course), and then you can pass either an array or a pointer and it will convert it according to the argument type.
LieAfterLie 10 Light Poster
could you tell me?
lol
LieAfterLie 10 Light Poster
Sry for my repeat posts, but i had a problem, and this was my solution. Like Salem said, it was lucky. I couldn't figure out how to store values to an array with {1,2,3....} unless it's being initialized. Obviously, the {1,2,3....} is the only practical way (that i know of) to store all the data in the arrays. I couldn't use conditions to only declare and initialize the array to a certain set of numbers, because even though it would only be declared once, the compiler errors and says im redeclaring as I have multiple declarations of the same variable in the same scope. So I made functions to do it and return a pointer to the array, so it wouldn't error because they all declare the array in a different scope. Not that it would matter if i gave 'solution' a different name in each function. It was faulty logic I know, but it seemed like an answer and it works. I also know now that the array is technically garbage data and goes out of scope when the function returns, and that any new variable could potentially mess with the array. I would like suggestions of better ways to store the info in the array. Also, the row & col should be initialised your right (just to 0 or something right?). I don't use them without storing something first, but what i store in them at first isn't constant.
LieAfterLie 10 Light Poster
Guess im lucky.:) I have the same warnings, but no actual compile errors. Again again thank you, I'm learning alot. I'm used to gotos from basic, i know theyre obsolete in C++. It was easier for me at the time, and really big loops are confusing to me. :confused: I will try.
LieAfterLie 10 Light Poster
Thanks again. This is my slightly edited version, with string newline(59, '\n')
. It is definitely faster. I didn't know what to do about the controls, though. All you need to know is that w, a, s and d move around. They're conveniently in the same shape as the arrow keys. I have no clue how to sort of getkey like basic, i can only input chars for now. And c at any time brings the controls back up. But this is my first non-trivial program. First one over maybe 50 lines that's more than a test of a feature.
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
//
//
// 15 PUZZLE
//
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <string>
using namespace std;
int getCol(int pos)
{return pos%12;}
int getRow(int pos)
{return (int)(pos/12);}
int getPos(int col, int row)
{return row*12 + col;}
void dispPuz(int* current)
{
for (int i = 0; i < 144; i++)
{
if (*(current+i) == 0)
cout << " ";
else
{
if (*(current+i) == -1)
cout << "--";
else
{
if (*(current+i) == -2)
cout << "?";
else
cout << *(current+i);
if (*(current+i) < 10)
cout << " ";
} // end 'else'
} // end 'else'
cout << " ";
if (getCol(i) == 11)
cout << "\n\n\n";
} // end 'for'
} // end dispPuz()
void move(int direction, int current[])
{
int row,col;
for (int i = 0; i < 144; i++)
{
if (current[i] == -1)
{
col = getCol(i);
row = getRow(i);
break;
} // end 'if'
} // end 'for'
if (direction == 1 && current[ getPos(col,row-1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row-1)];
current[ getPos(col,row-1)] = -1;
} // end up 'if'
if (direction == 2 && current[ getPos(col-1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col-1,row)];
current[ getPos(col-1,row)] = -1;
} // end left 'if'
if (direction == 3 && current[ getPos(col,row+1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row+1)];
current[ getPos(col,row+1)] = -1;
} // end down 'if'
if (direction == 4 && current[ getPos(col+1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col+1,row)];
current[ getPos(col+1,row)] = -1;
} // end right 'if'
} // end move()
int testWin(int current[], int solution[])
{
int win = 0;
int i;
for (i = 0; i < 144; i++)
{
if (current[i] != solution[i])
break;
} // end 'for'
if (i == 144)
win = 1;
return win;
} // end testWin()
void scramble(int current[])
{
srand(time(NULL));
for (int i = 0; i < 1000000; i++)
move(rand()%4+1, current);
} // end scramble()
void dispControls()
{
string newline(59, '\n');
cout << newline;
cout << "CONTROLS\n\nQ E\n\n Z X C\n\nC - Display Controls\nE - Display "
<< "Solution\nZ - Scramble\nX - Solve (Not done yet)\nQ - Quit to Menu\n\n "
<< "W\n A S D\n\nW - Move the number above the space down\nA - Move the number "
<< "to the left of the space right\nS - Move the number below the space "
<< "up\nD - Move the number to the right of the space left\n\n-You can put in "
<< "a sequence of letters.\n-Make sure Caps Lock is off.\n\n";
system("PAUSE");
} // end dispControls()
void dispControls2()
{
string newline(59, '\n');
cout << newline;
cout << "CONTROLS\n\nQ E\n\n C\n\nC - Display Controls\nE - Change "
<< "the block\nQ - End customize\n\n W\n A S D\n\nW - Move cursor up\nA - "
<< "Move cursor left\nS - Move cursor down\nD - Move cursor right\n\n-You "
<< "can put in a sequence of letters.\n-Make sure Caps Lock is off.\n\nCHANGING "
<< "THE BLOCK\n\n0 - Unused block\n# - A sliding block\n-1 - The empty "
<< "space\n\n";
system("PAUSE");
} // end dispControls2()
void custom(int* solution)
{
string newline(59, '\n');
int row = 1;
int col = 1;
char in;
int inNum, count;
int solution2[144];
for (int i = 0; i < 144; i++)
*(solution+i) = 0;
dispControls2();
for (;;) // input loop
{
cout << newline;
for (int i = 0; i < 144; i++)
solution2[i] = *(solution+i);
solution2[getPos(col,row)] = -2;
dispPuz(solution2);
cout << "Choice: ";
cin >> in;
switch (in)
{
/////////////////////
case 'w':
if (row != 1)
row--;
break;
/////////////////////
case 'a':
if (col != 1)
col--;
break;
/////////////////////
case 's':
if (row != 10)
row++;
break;
/////////////////////
case 'd':
if (col != 10)
col++;
break;
/////////////////////
case 'c':
dispControls2();
break;
/////////////////////
case 'e':
cout << "Number: ";
cin >> inNum;
if (inNum < 100 && inNum > -2)
*(solution + getPos(col,row)) = inNum;
else
{
cout << newline;
cout << "Must be a number -1 or greater with 1 or 2 digits.\n\n";
system("PAUSE");
}
break;
/////////////////////
case 'q':
break;
/////////////////////
default:
break;
/////////////////////
} // end 'switch'
if (in == 'q')
{
count = 0;
for (int i = 0; i < 144; i++)
{
if (solution[i] == -1)
count++;
} // end 'for'
if (count > 1)
{
cout << newline;
cout << "There's more than one open spot.\n\n";
system("PAUSE");
}
if (count == 0)
{
cout << newline;
cout << "There's no open spot.\n\n";
system("PAUSE");
}
if (count == 1)
break;
} // end 'if'
} // end input loop
} // end custom()
int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn1()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0,
0, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0,
0, 9, 10,11,12,0, 0, 0, 0, 0, 0, 0,
0, 13,14,15,-1,0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn2()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0,
0, 6, 7, 8, 9,10, 0, 0, 0, 0, 0, 0,
0, 11,12,13,12,15,0, 0, 0, 0, 0, 0,
0, 16,17,18,19,20,0, 0, 0, 0, 0, 0,
0, 21,22,23,24,-1,0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn3()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0,
0, 7, 8, 9, 10,11,12,0, 0, 0, 0, 0,
0, 13,14,15,16,17,18,0, 0, 0, 0, 0,
0, 19,20,21,22,23,24,0, 0, 0, 0, 0,
0, 25,26,27,28,29,30,0, 0, 0, 0, 0,
0, 31,32,33,34,35,-1,0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn4()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0,
0, 8, 9,10,11,12,13,14, 0, 0, 0, 0,
0, 15,16,17,18,19,20,21,0, 0, 0, 0,
0, 22,23,24,25,26,27,28,0, 0, 0, 0,
0, 29,30,31,32,33,34,35,0, 0, 0, 0,
0, 36,37,38,39,40,41,42,0, 0, 0, 0,
0, 43,44,45,46,47,48,-1,0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn5()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0,
0, 9,10,11,12,13,14,15,16, 0, 0, 0,
0, 17,18,19,20,21,22,23,24,0, 0, 0,
0, 25,26,27,28,29,30,31,32,0, 0, 0,
0, 33,34,35,36,37,38,39,40,0, 0, 0,
0, 41,42,43,44,45,46,47,48,0, 0, 0,
0, 49,50,51,52,53,54,55,56,0, 0, 0,
0, 57,58,59,60,61,62,63,64,-1,0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn6()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
0,10,11,12,13,14,15,16,17,18, 0, 0,
0,19,20,21,22,23,24,25,26,27, 0, 0,
0,28,29,30,31,32,33,34,35,36, 0, 0,
0,37,38,39,40,41,42,43,44,45, 0, 0,
0,46,47,48,49,50,51,52,53,54, 0, 0,
0,55,56,57,58,59,60,61,62,63, 0, 0,
0,64,65,66,67,68,69,70,71,72, 0, 0,
0,73,74,75,76,77,78,79,80,-1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn7()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 0,
0,11,12,13,14,15,16,17,18,19,20, 0,
0,21,22,23,24,25,26,27,28,29,30, 0,
0,31,32,33,34,35,36,37,38,39,40, 0,
0,41,42,43,44,45,46,47,48,49,50, 0,
0,51,52,53,54,55,56,57,58,59,60, 0,
0,61,62,63,64,65,66,67,68,69,70, 0,
0,71,72,73,74,75,76,77,78,79,80, 0,
0,81,82,83,84,85,86,87,88,89,90, 0,
0,91,92,93,94,95,96,97,98,99,-1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn8()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
LieAfterLie 10 Light Poster
So how can i write a GUI in C++ without the console window?
LieAfterLie 10 Light Poster
Thanks again. Very much.
btw, have u tried compiling it?
I'm very proud of my primitive program ;)
LieAfterLie 10 Light Poster
thanks. I don't know how to apply it, though.... Im new. I dont even know what std:: and that newline function do. (sry)
LieAfterLie 10 Light Poster
Fancy. Ty. Its like 1008 lines and not well commented, though. Atleast it only uses simple stuff.
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
//
//
// 15 PUZZLE
//
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <time.h>
using namespace std;
int getCol(int pos)
{return pos%12;}
int getRow(int pos)
{return (int)(pos/12);}
int getPos(int col, int row)
{return row*12 + col;}
void dispPuz(int* current)
{
for (int i = 0; i < 144; i++)
{
if (*(current+i) == 0)
cout << " ";
else
{
if (*(current+i) == -1)
cout << "--";
else
{
if (*(current+i) == -2)
cout << "?";
else
cout << *(current+i);
if (*(current+i) < 10)
cout << " ";
} // end 'else'
} // end 'else'
cout << " ";
if (getCol(i) == 11)
cout << "\n\n\n";
} // end 'for'
} // end dispPuz()
void move(int direction, int current[])
{
int row,col;
for (int i = 0; i < 144; i++)
{
if (current[i] == -1)
{
col = getCol(i);
row = getRow(i);
break;
} // end 'if'
} // end 'for'
if (direction == 1 && current[ getPos(col,row-1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row-1)];
current[ getPos(col,row-1)] = -1;
} // end up 'if'
if (direction == 2 && current[ getPos(col-1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col-1,row)];
current[ getPos(col-1,row)] = -1;
} // end left 'if'
if (direction == 3 && current[ getPos(col,row+1) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col,row+1)];
current[ getPos(col,row+1)] = -1;
} // end down 'if'
if (direction == 4 && current[ getPos(col+1,row) ] != 0)
{
current[ getPos(col,row)] = current[ getPos(col+1,row)];
current[ getPos(col+1,row)] = -1;
} // end right 'if'
} // end move()
int testWin(int current[], int solution[])
{
int win = 0;
int i;
for (i = 0; i < 144; i++)
{
if (current[i] != solution[i])
break;
} // end 'for'
if (i == 144)
win = 1;
return win;
} // end testWin()
void scramble(int current[])
{
srand(time(NULL));
for (int i = 0; i < 1000000; i++)
move(rand()%4+1, current);
} // end scramble()
void dispControls()
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "CONTROLS\n\nQ E\n\n Z X C\n\nC - Display Controls\nE - Display "
<< "Solution\nZ - Scramble\nX - Solve (Not done yet)\nQ - Quit to Menu\n\n "
<< "W\n A S D\n\nW - Move the number above the space down\nA - Move the number "
<< "to the left of the space right\nS - Move the number below the space "
<< "up\nD - Move the number to the right of the space left\n\n-You can put in "
<< "a sequence of letters.\n-Make sure Caps Lock is off.\n\n";
system("PAUSE");
} // end dispControls()
void dispControls2()
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "CONTROLS\n\nQ E\n\n C\n\nC - Display Controls\nE - Change "
<< "the block\nQ - End customize\n\n W\n A S D\n\nW - Move cursor up\nA - "
<< "Move cursor left\nS - Move cursor down\nD - Move cursor right\n\n-You "
<< "can put in a sequence of letters.\n-Make sure Caps Lock is off.\n\nCHANGING "
<< "THE BLOCK\n\n0 - Unused block\n# - A sliding block\n-1 - The empty "
<< "space\n\n";
system("PAUSE");
} // end dispControls2()
void custom(int* solution)
{
int row = 1;
int col = 1;
char in;
int inNum, count;
int solution2[144];
for (int i = 0; i < 144; i++)
*(solution+i) = 0;
dispControls2();
for (;;) // input loop
{
for (int i = 0; i < 59; i++)
cout << "\n";
for (int i = 0; i < 144; i++)
solution2[i] = *(solution+i);
solution2[getPos(col,row)] = -2;
dispPuz(solution2);
cout << "Choice: ";
cin >> in;
switch (in)
{
/////////////////////
case 'w':
if (row != 1)
row--;
break;
/////////////////////
case 'a':
if (col != 1)
col--;
break;
/////////////////////
case 's':
if (row != 10)
row++;
break;
/////////////////////
case 'd':
if (col != 10)
col++;
break;
/////////////////////
case 'c':
dispControls2();
break;
/////////////////////
case 'e':
cout << "Number: ";
cin >> inNum;
if (inNum < 100 && inNum > -2)
*(solution + getPos(col,row)) = inNum;
else
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "Must be a number -1 or greater with 1 or 2 digits.\n\n";
system("PAUSE");
}
break;
/////////////////////
case 'q':
break;
/////////////////////
default:
break;
/////////////////////
} // end 'switch'
if (in == 'q')
{
count = 0;
for (int i = 0; i < 144; i++)
{
if (solution[i] == -1)
count++;
} // end 'for'
if (count > 1)
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "There's more than one open spot.\n\n";
system("PAUSE");
}
if (count == 0)
{
for (int i = 0; i < 59; i++)
cout << "\n";
cout << "There's no open spot.\n\n";
system("PAUSE");
}
if (count == 1)
break;
} // end 'if'
} // end input loop
} // end custom()
int* fn0()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0,
0, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0,
0, 7, 8,-1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn1()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0,
0, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0,
0, 9, 10,11,12,0, 0, 0, 0, 0, 0, 0,
0, 13,14,15,-1,0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn2()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 0, 0, 0, 0, 0, 0,
0, 6, 7, 8, 9,10, 0, 0, 0, 0, 0, 0,
0, 11,12,13,12,15,0, 0, 0, 0, 0, 0,
0, 16,17,18,19,20,0, 0, 0, 0, 0, 0,
0, 21,22,23,24,-1,0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn3()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0,
0, 7, 8, 9, 10,11,12,0, 0, 0, 0, 0,
0, 13,14,15,16,17,18,0, 0, 0, 0, 0,
0, 19,20,21,22,23,24,0, 0, 0, 0, 0,
0, 25,26,27,28,29,30,0, 0, 0, 0, 0,
0, 31,32,33,34,35,-1,0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn4()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0,
0, 8, 9,10,11,12,13,14, 0, 0, 0, 0,
0, 15,16,17,18,19,20,21,0, 0, 0, 0,
0, 22,23,24,25,26,27,28,0, 0, 0, 0,
0, 29,30,31,32,33,34,35,0, 0, 0, 0,
0, 36,37,38,39,40,41,42,0, 0, 0, 0,
0, 43,44,45,46,47,48,-1,0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn5()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0,
0, 9,10,11,12,13,14,15,16, 0, 0, 0,
0, 17,18,19,20,21,22,23,24,0, 0, 0,
0, 25,26,27,28,29,30,31,32,0, 0, 0,
0, 33,34,35,36,37,38,39,40,0, 0, 0,
0, 41,42,43,44,45,46,47,48,0, 0, 0,
0, 49,50,51,52,53,54,55,56,0, 0, 0,
0, 57,58,59,60,61,62,63,64,-1,0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn6()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
0,10,11,12,13,14,15,16,17,18, 0, 0,
0,19,20,21,22,23,24,25,26,27, 0, 0,
0,28,29,30,31,32,33,34,35,36, 0, 0,
0,37,38,39,40,41,42,43,44,45, 0, 0,
0,46,47,48,49,50,51,52,53,54, 0, 0,
0,55,56,57,58,59,60,61,62,63, 0, 0,
0,64,65,66,67,68,69,70,71,72, 0, 0,
0,73,74,75,76,77,78,79,80,-1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn7()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 0,
0,11,12,13,14,15,16,17,18,19,20, 0,
0,21,22,23,24,25,26,27,28,29,30, 0,
0,31,32,33,34,35,36,37,38,39,40, 0,
0,41,42,43,44,45,46,47,48,49,50, 0,
0,51,52,53,54,55,56,57,58,59,60, 0,
0,61,62,63,64,65,66,67,68,69,70, 0,
0,71,72,73,74,75,76,77,78,79,80, 0,
0,81,82,83,84,85,86,87,88,89,90, 0,
0,91,92,93,94,95,96,97,98,99,-1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};return solution;}
int* fn8()
{int solution[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
LieAfterLie 10 Light Poster
Wow, i need to read what I write before i post. If anyone wants, i can email it so you can see what i mean.
LieAfterLie 10 Light Poster
its really big, prolly outside the limits for posts. Im getting way ahead of myself, making a program this big wen i know nothing and probably would be able to make the same program better if i wait until i know more. but, basically its a program for the 15 slider puzzle and it gets confusing/disorienting or watever cause the info is flashing too fast for you to really make moves as fsast as you would like.
LieAfterLie 10 Light Poster
This is useless i know, but im using a free compiler i got with C++ for Dummies (which REALLY sucks) and it doesn't have tab characters for specifically that reason i think. Tabbing in it is confusing, i dont get the rules yrt but sometimes it does 4 spaces, 8 spaces, jumps to the previous tab and weird stuff like that. Same for deleting, cause it doesnt know if the spaces ur deleting were originally tabs. I don't mean to clog, i'm just bored.
LieAfterLie 10 Light Poster
I am extremely new to C++, can sum1 tell me a faster way to output stuff than cout? It either outputs too slow or takes too long to automatically scroll or something. I was trying to sort of output and refresh in real time w cout