skip to Main Content

I want to create just a simple exe file from some code i am trying in c++
when i try to create exe file it creates a exe recipe and it does not work.
how do i fix that problem i tried looking it up and could not find a good answer.
i am just trying to create a snake game and run it as a exe file.
i am using visual studio public for school work.

enter image description here

#include<stdio.h>
#include<Windows.h>
#include<stdbool.h>
#include<time.h>
#include<conio.h>
#include<iostream>

bool gameover;
const int height = 15;
const int width = 80;
int x, y, fruitX, fruitY, score=0;
enum eDirection { STOP = 0, UP, DOWN, LEFT, RIGHT };
eDirection dir;
int tailx[100], taily[100], ctail = 0;


void setup()
{
    gameover = false;
    
    x = width / 2;
    y = height / 2;
    srand(time(0));
    fruitX = rand() % width + 1;
    fruitY = rand() % height;
}

void board()
{

    system("CLS");
    for (int i = 0; i < width; i++)
    {
        
        printf("#");
    }
    for (int i = 0; i < height; i++)
    {
        printf("n");
        for (int j = 0; j < width; j++)
        {
            if (j == 0 || j == width - 1)
                printf("#");
            else
            {
                if (i == fruitY && j == fruitX)
                    printf("f");
                else
                    if (i == y && j == x)
                        printf("o");
                    else
                    {
                        
                        bool print = false;
                        for (int k = 0; k < ctail; k++)
                        {

                            if (i == taily[k] && j == tailx[k])
                            {
                                printf("o");
                                print = true;
                            }
                        }
                        if (!print)
                            printf(" ");
                    }
            }

        }


    }
    printf("n");
    for (int i = 0; i < width; i++)
    {

        printf("#");
    }
    printf("n x is %d y is %d", fruitX, fruitY);
    printf("nn the score is %dnn",score);






}
void input()
{
    if(_kbhit())
        switch (_getch())
        {
        case 'w':dir = UP;
            break;
        case 's':dir = DOWN;
            break;
        case 'a':dir = LEFT;
            break;
        case 'd':dir = RIGHT;
            break;
        default:break;
        }
}
void logic()
{
    int prevx = tailx[0];
    int prevy = taily[0];
    tailx[0] = x;
    taily[0] = y;
    int prev2x, prev2y;
    for (int i = 1; i < ctail; i++)
    {
        prev2x = tailx[i];
        prev2y = taily[i];
        tailx[i] = prevx;
        taily[i] = prevy;
        prevx = prev2x;
        prevy = prev2y;
        
    }


    switch (dir)
    {
    case UP:y--;
        break;
    case DOWN:y++;
        break;
    case LEFT:x--;
        break;
    case RIGHT:x++;
        break;
    default:break;
    }
    if (x<0 || x>width )
        gameover = true;
    if (y<0-1 || y>height)
        gameover = true;

    for (int i = 0; i < ctail; i++)
    {
        if (x == tailx[i] && y == taily[i])
            gameover = true;
    }

    if (x == fruitX && y == fruitY)
    {
        score += 10;
        fruitX = rand() % (width-1) + 1;
        fruitY = rand() % height;
        ctail++;
    }
}

int main()
{

    setup();
    while (!gameover)
    {
        board();
        input();
        logic();
        Sleep(5);
    }

    return 0;
}

2

Answers


  1. This file isn’t executable. If you want to run your executable go to the location which includes the executable file. These files are in the intermediate directory, but the executable file always places in a directory which is called the output directory. These settings can be watched in the project properties of your visual studio. Output directory as the default set to the $(SolutionDir)$(Platform)$(Configuration). However, Once the project is built, navigate to the folder where the executable file is located. By default, the executable file is created in the project’s "Debug" or "Release" folder, depending on the build configuration.

    Login or Signup to reply.
  2. A picture says a thousand words!

    Well… here are some pictures! Maybe this will help 🙂

    File Directory

    Play the Game

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search