Author Topic: Fun Little C++ Pointless Program  (Read 7247 times)

0 Members and 2 Guests are viewing this topic.

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Fun Little C++ Pointless Program
« Reply #15 on: September 16, 2011, 11:57:20 pm »
The original code was using W, A, S, and D but you had to press Enter each time. Then Netham showed me that thread and that's how I learned to do it, there wasn't anything about recognizing them by letter. If you have something to offer please do.
« Last Edit: September 16, 2011, 11:57:35 pm by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)

Offline Netham45

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2103
  • Rating: +213/-4
  • *explodes*
    • View Profile
Re: Fun Little C++ Pointless Program
« Reply #16 on: September 17, 2011, 02:40:45 am »
Just check if it's equal to '<char>'.
'w' = 119d, 'a' = 97d 'd'=100d, 's'=115d.
Omnimaga Admin

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: Fun Little C++ Pointless Program
« Reply #17 on: September 17, 2011, 02:55:52 am »
With a few modifications your first version will compile under Linux but the second version will not because it relies on conio.h which was originally designed for MS DOS. btw try to avoid to avoid system() calls as they are very platform specific. For some of functionality you need though higher level libraries are needed which will require you to leave the console. Part of the problem is just that consoles don't work very well for graphical apps.

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Fun Little C++ Pointless Program
« Reply #18 on: September 17, 2011, 08:41:50 am »
With a few modifications your first version will compile under Linux but the second version will not because it relies on conio.h which was originally designed for MS DOS. btw try to avoid to avoid system() calls as they are very platform specific. For some of functionality you need though higher level libraries are needed which will require you to leave the console. Part of the problem is just that consoles don't work very well for graphical apps.

system(); calls the command line, in whichever system we are. Different systems have different terminal languages (bash, batch, etc).

I never use them unless if my program is supposed to be platform-specific. And what you said about conio.h is also true ;)

Offline meishe91

  • Super Ninja
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2946
  • Rating: +115/-11
    • View Profile
    • DeviantArt
Re: Fun Little C++ Pointless Program
« Reply #19 on: September 17, 2011, 10:41:09 am »
I know that system() is relatively Windows specific but for the purposes of my class that is what we are supposed to use for the most part to get the program from just starting, running, and finishing.

Edit:
Code: [Select]
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace std;
void move(int direction,int &x,int &y)
{
if(direction=='w')
{
y-=(y!=1);
}
else if(direction=='s')
{
y+=(y!=11);
}
else if(direction=='a')
{
x-=(x!=1);
}
else if(direction=='d')
{
x+=(x!=11);
}
else {;}
return;
}
void display(int x,int y)
{
cout<<"*************\n";
for(int i=0;i<11;i++)
{
if(i+1==y)
{
cout<<"*"<<setw(x)<<"X"<<setw(13-x)<<"*\n";
}
else
{
cout<<"*           *\n";
}
}
cout<<"*************\n";
}

int main()
{
int x=6;
int y=6;
int direction=27;
do
{
move(direction,x,y);
display(x,y);
direction=getch();
system("cls");
}while(direction!='q');
system("pause");
return 0;
}
« Last Edit: September 17, 2011, 10:44:15 am by meishe91 »
Spoiler For Spoiler:



For the 51st time, that is not my card! (Magic Joke)