Jump to content
EN
Play

Forum

programming


 Share

Recommended Posts

The forum is a lot of programmers! 

I suggest we all get together here and write perfect code!   :lol: 

Good luck to everyone to write code!

 

 

 

 

Example function GotoXY console in C++ using WinAPI:

 


 



void gotoxy(int xpos, int ypos)
{
COORD scrn;

HANDLE hOuput = GetStdHandle(STD_OUTPUT_HANDLE);

scrn.X = xpos; scrn.Y = ypos;

SetConsoleCursorPosition(hOuput,scrn);
}


 


 

Change the color of certain characters to the console using WinAPI:

 




enum ConsoleColor
{
Black = 0,
Blue = 1,
Green = 2,
Cyan = 3,
Red = 4,
Magenta = 5,
Brown = 6,
LightGray = 7,
DarkGray = 8,
LightBlue = 9,
LightGreen = 10,
LightCyan = 11,
LightRed = 12,
LightMagenta = 13,
Yellow = 14,
White = 15
};

// Change Color
void SetColor(int text, int background)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
}


 


 

 

Processing keystrokes without stopping program using WinAPI. C + +   :

 


 



#include <windows.h>

inline bool IsKeyDown(int Key)
{
return (GetKeyState(Key) & 0x8000) != 0;
}


int main()
{
while (true)
{
if (IsKeyDown(VK_ESCAPE)) // VK_key
{
break;
}


}
return 0;
}


 

Edited by r_N.u.m.m.e.r0
  • Like 1

Share this post


Link to post
Share on other sites

Ball Game :lol:  C++ :

 




#include <iostream>
#include <windows.h>
 
float coordx = 40, coordy = 13, coordoldx = 5, coordoldy = 5; //Корды. Олды для перерисовки
 
using namespace std;
 
char sharik = 'O'; // наш шарик
 
inline bool IsKeyDown(int key) // считываем кнопки
{
    return (GetKeyState(key) & 0x8000) !=0;
}
 
void gotoxy(int xpos, int ypos) // по названию всё понятно
{
    COORD scrn;
 
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
 
    scrn.X = xpos; scrn.Y = ypos;
 
    SetConsoleCursorPosition(hOutput, scrn);
}
 
void DrawBall() // рисуем шарик
{
    gotoxy(coordoldx, coordoldy);
    cout << " "; // стираем его на старых кордах
    coordoldx = coordx;
    coordoldy = coordy;
    gotoxy(coordx, coordy);
    cout << sharik; // рисуем на новых
}
 
void PaintBall()
{
    float axelX = 0, axelY = 0; // ускорение шарика
    while(1)
    {
        while(1)
        {
            Sleep(10);
            if (axelX < 0.6 && axelX > -0.6 ) //кнопочки
            {
                if (IsKeyDown(VK_LEFT))
                {
                    axelX -=0.001;
                }
                else if (IsKeyDown(VK_RIGHT))
                {
                    axelX +=0.001;
                }
            }
            else if(axelX > 0)
            {
                axelX = 0.599;
            }
            else if(axelX < 0)
            {
                axelX = -0.599;
            }
            if (axelY < 0.6 && axelY > -0.6 )
            {
                if (IsKeyDown(VK_UP))
                {
                    axelY -=0.001;
                }
                else if (IsKeyDown(VK_DOWN))
                {
                    axelY +=0.001;
                }
            }
            else if(axelY > 0)
            {
                axelY = 0.599;
            }
            else if(axelY < 0)
            {
                axelY = -0.599;
            }
            break;
        }
        // физика
        if(coordx > 2 && coordx < 78)
        {
            coordx += axelX;
        }
        else
        {
            axelX= axelX* -1;
            coordx += axelX;
        }
        if(coordy > 2 && coordy < 23)
        {
            coordy += axelY;
        }
        else
        {
            axelY= axelY* -1;
            coordy += axelY;
        }
        if(axelY > 0)
        {
            axelY -=0.0005;
        }
        else if(axelY < 0)
        {
            axelY +=0.0005;
        }
        if(axelX > 0)
        {
            axelX -=0.0005;
        }
        else if(axelX < 0)
        {
            axelX +=0.0005;
        }
        DrawBall();
    }
}
 
int main()
{
    LPCSTR titlePaintBall = "Paint Ball GAME! Beta ! by nummer";
    SetConsoleTitle(titlePaintBall);
    PaintBall();
    return 0;
}
 



 


Edited by r_N.u.m.m.e.r0
  • Like 1

Share this post


Link to post
Share on other sites

How to make a object move. (Flash, Action Script 2):

 

1. Draw a shape. (Example: Square)

 

2. Convert it to a symbol and call it "character" and make the registration point at the bottom where the middle is then hit ok. After that give it a instance name called "char". (Without quotes)

 

2. Double click on the shape and paste this code on the object:

 

 

 

onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 9;
var maxJump:Number = -16;
var touchingGround:Boolean = false;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
_root.char._xscale = 100;
}
if (Key.isDown(Key.LEFT)) {
_x -= speed;
_root.char._xscale = -100;
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}

 

 

 

3. Now draw a new object and convert the object to a symbol and call it "level1ground" and make the registration point at the middle top then hit ok. After that give it an instance name called ground. (Without the quotes)

 

4. If you use arrow keys you should be able to move your object and make it jump.

 

You should get this: http://www.swfcabin.com/open/1399410964

 

Note: Be sure to make the FPS 24.

  • Like 2

Share this post


Link to post
Share on other sites

I programmed a quiz with notes scores etc it is very long like 100 pages with math class and keyboard class to(with java)

Edited by jordan61

Share this post


Link to post
Share on other sites

Making a button. (Flash/Actionscript 2)

 

1. Draw a rectangle

 

2. Convert the rectangle to a button. (Right click rectangle > "Convert to Symbol..." > Button)

 

2. Create a new frame.

 

3.  Add this code to the button:

 

 

 

on (release) {
	gotoAndStop(YOUR FRAME NUMBER);
}

 

 

 

If you click the button it should take you to the next frame.

 


 

Adding a context menu:

 

1. Create a new layer.

 

2. Double click the frame in the timeline.

 

3. Add this code to it:

 

 

 

var myMenu = new ContextMenu();
myMenu.hideBuiltInItems();
function itemHandler1(obj, item) {
}
item1 = new ContextMenuItem("YOUR TEXT HERE", itemHandler1);
myMenu.customItems.push(item1);
_root.menu = myMenu;

 

 

 

If you right click on your flash movie then it should show your context menu.

 

Note: If you want to disable a item on your context menu simply add this to the code:

 

 

 

item1.enabled = false;

 

 

Edited by GeneralPie

Share this post


Link to post
Share on other sites

#include <iostream>

#include <gold>

using namespace std;

int main {

 

long long N;

cout<<"write how many gold boxes do you want"<<endl;

cin>>N;

 

while(N)

  {

   cout<<"Gold Box Will Be Dropped Soon"<<endl;

   N=N-1;

  }

 

system("pause")

return 0;

 

}

 

:D

  • Like 1

Share this post


Link to post
Share on other sites

 

#include <iostream>

#include <ctime>

 

int gold;

     int main(){

     srand(time(NULL));

     gold=rand() % 1000;

     while(1)

     {

          if(gold==1)

          cout << "Gold Box Will Be Dropped Soon" << endl;

     }

     return 0;

}

Edited by r_N.u.m.m.e.r0

Share this post


Link to post
Share on other sites

Why isn't that programming forum about Visual Basic too?!?! C++ and C# aren't good languages but I know them, and VB I know the best. If somebody wants something developed by VB or simply wants help with VB if he's a beginner with it, contact me - I'm a real Visual Basic freak!  :D 'Till now I had made with VB a Web Browser, a program that enables you to type in English letters a word and it's converted to Russian letters (for example if you write with it Y ne ruskii' it replaces it by Я не русский) and many more programs&softwares.

Edited by ariking777

Share this post


Link to post
Share on other sites

Include file "ConsoleUtils" by Nummer!


DOWNLOAD

Example:

Read keys:
        if (IsKeyDown(VK_ESCAPE)) // VK_key
        {
        break; // activity
        }
 
 
GotoXY
gotoxy(int xpos,int ypos);
 
 
 
 
ConsoleColor:
SetColor(int text, int background);

Share this post


Link to post
Share on other sites

 Share

×
×
  • Create New...