Jogo da cobrinha (Snake II) refeito em C e C++

Publicado por retro (última atualização em 29/07/2020)

[ Hits: 9.455 ]

Homepage: nenhum kk

Download game.cpp




Vocês aí com certeza já jogaram o famoso Snake II (vulgo Jogo da Cobrinha), em seus antigos nokias dos anos 2000. Mas vocês já pensaram em um remake para Windows (no momento estou tendo que usar esse janelas aí para fazer uns negócios, depois eu faço a adaptação para Linux); escrito em C++ e C?

Então você veio no lugar certo, eu tenho o GitHub, onde você poderá criar sua própria versão do jogo, e aqui, onde você poderá jogar (usando o wine) ou criar sua própria versão.

Link do repositório: https://github.com/RetroGamerCX/snake-ii-remake

E então o script (sim, são 830 linhas de esforço para um simples remake de um jogo):

  



Esconder código-fonte

#pragma warning (disable : 4996)
#ifdef _WIN32
#include <windows.h>  
#else
#include <unistd.h>
#endif
#include <stdio.h>
#include <conio.h>
#include <ctime>
#include <iostream>
#include <locale.h>
#include <cstdlib>
#include <string>
using namespace std;
void mgotoxy(int x, int y) {
    COORD p = { x, y };
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
}
int main() {
    system("mode 27,20");
    system("title Snake");
    system("color 20");
    setlocale(LC_ALL, "Portuguese");
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "#    <<<----|-|---->>>    #" << endl;
    cout << "#     <<<---|-|--->>>     #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "###########################" << endl;
    Sleep(500);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "#    <<<----|-|---->>>    #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "###########################" << endl;
    Sleep(500);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "###########################" << endl;
    Sleep(600);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# #                       #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ##                      #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ###                     #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "# ####                    #" << endl;
    cout << "# #                       #" << endl;
    cout << "# #                       #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#  ####                   #" << endl;
    cout << "#  #                      #" << endl;
    cout << "# ##                      #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#   ####                  #" << endl;
    cout << "#   #                     #" << endl;
    cout << "# ###                     #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#    ####                 #" << endl;
    cout << "#    #                    #" << endl;
    cout << "# ####                    #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#     ####                #" << endl;
    cout << "#     #                   #" << endl;
    cout << "# #####                   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#      ####               #" << endl;
    cout << "#      #                  #" << endl;
    cout << "# ######                  #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#       ####              #" << endl;
    cout << "#       #                 #" << endl;
    cout << "# #######                 #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#        ####             #" << endl;
    cout << "#        #                #" << endl;
    cout << "# ########                #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#         ####            #" << endl;
    cout << "#         #               #" << endl;
    cout << "# #########               #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#          ####           #" << endl;
    cout << "#          #              #" << endl;
    cout << "# ##########              #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#           ####          #" << endl;
    cout << "#           #             #" << endl;
    cout << "# ###########             #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#            ####         #" << endl;
    cout << "#            #            #" << endl;
    cout << "# ############            #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#   <<<-----|-|----->>>   #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# <<<<<<<[INFINITY]>>>>>> #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#       apresenta:        #" << endl;
    cout << "#  um jogo clássico, que  #" << endl;
    cout << "# agora possui um REMAKE! #" << endl;
    cout << "#         É ELE:          #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#             ####        #" << endl;
    cout << "#             #           #" << endl;
    cout << "#  ############           #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    Sleep(300);
    goto title;
title:
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "#                         #" << endl;
    cout << "#     +------------+      #" << endl;
    cout << "#     |  SNAKE II: |      #" << endl;
    cout << "#     | THE REMAKE |      #" << endl;
    cout << "#     +------------+      #" << endl;
    cout << "#                         #" << endl;
    cout << "# A.K.A: Jogo da Cobrinha #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#             ####<-snake #" << endl;
    cout << "#             #           #" << endl;
    cout << "#  ############           #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# --> Pressione Enter <-- #" << endl;
    cout << "#       Versão: 1.1       #" << endl;
    cout << "###########################" << endl;
    getch();
    goto option;
option:
    int op;
    int password = 1;
    int speed = 200;
    int c = 0;
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "000_______________________ " << endl;
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#      o p t i o n s      #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#    Escolha uma opção:   #" << endl;
    cout << "# 0: Sair                 #" << endl;
    cout << "# 1: Continuar            #" << endl;
    cout << "# 2: Novo Jogo            #" << endl;
    cout << "# 3: Ajuda                #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# ------- options: ------ #" << endl;
    cout << "#  _0_   _1_   _2_   _3_  #" << endl;
    cout << "# |___| |___| |___| |___| #" << endl;
    cout << "#            #            #" << endl;
    cout << "#            #            #" << endl;
    cout << "#            #            #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "###########################" << endl;
    cin >> op;
    if (op == 0) {
       return 0;
    }
    if (op == 1) {
        c = 1;
#ifdef _WIN32
        system("cls");
#else 
        system("clear");
#endif
        cout << "000_______________________ " << endl;
        cout << "###########################" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#     p a s s w o r d     #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#   Digite a sua senha    #" << endl;
        cout << "#         abaixo:         #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#               ####      #" << endl;
        cout << "#               #         #" << endl;
        cout << "#    ############         #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "###########################" << endl;
        cin >> password;
        cin >> speed;
        goto size;
    }
    if (op == 2) {
    set:
#ifdef _WIN32
        system("cls");
#else 
        system("clear");
#endif
        cout << "000_______________________ " << endl;
        cout << "###########################" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#       s p e e d         #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "# Digite a velocidade de  #" << endl;
        cout << "# seu personagem, que é   #" << endl;
        cout << "# medida por milissegun-  #" << endl;
        cout << "# dos.                    #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#                         #" << endl;
        cout << "#              ------#### #" << endl;
        cout << "#             ------#     #" << endl;
        cout << "# ------############      #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "###########################" << endl;
        cin >> speed;
        goto size;
    }
    if (op == 3) {
    help:
#ifdef _WIN32
        system("cls");
#else 
        system("clear");
#endif
        cout << "000_______________________ " << endl;
        cout << "###########################" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#       p a g e  1        #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "# Primeiro, você precisa  #" << endl;
        cout << "# ajustar a sua velocida- #" << endl;
        cout << "# de. É usado um sistema  #" << endl;
        cout << "# de milisegundos para    #" << endl;
        cout << "# isso. Ao colocar certa  #" << endl;
        cout << "# quantidade de milisse-  #" << endl;
        cout << "# gundos, a cobra se move #" << endl;
        cout << "# um quadrado a cada mi-  #" << endl;
        cout << "# lisegundo que foi ajus- #" << endl;
        cout << "# tado pelo jogador.      #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "# próxima página: enter > #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "###########################" << endl;
        getch();
#ifdef _WIN32
        system("cls");
#else 
        system("clear");
#endif
        int o = 0;
        cout << "000_______________________ " << endl;
        cout << "###########################" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#       p a g e  2        #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "# Os controles são os di- #" << endl;
        cout << "# recionais de seu tecla- #" << endl;
        cout << "# do. Para colher uma ma- #" << endl;
        cout << "# çã, faça a cobra se en- #" << endl;
        cout << "# contrar com ela, assim, #" << endl;
        cout << "# cada maçã irá aumentar  #" << endl;
        cout << "# uma unidade de seu ta-  #" << endl;
        cout << "# manho.                  #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "#         Opções:         #" << endl;
        cout << "# 0: Sair                 #" << endl;
        cout << "# 1: Jogar                #" << endl;
        cout << "# ----------------------- #" << endl;
        cout << "###########################" << endl;
        cin >> o;
        if (o == 0) {
            return 0;
        }
        if (o == 1) {
            goto set;
        }
        else {
            cout << "Comando inválido" << endl;
            getch();
            goto help;
        }
    }
    else {
        cout << "Comando inválido" << endl;
        getch();
        goto option;
    }
size:
    int size[2] = { 1,password };
    goto game;
game:
    int x, d = 2, cx[300] = { 12,1 }, cy[300] = { 9,7 }, mx, my;
    char tecla = 'a';
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "0" << size[c] << "_______________________" << endl;
    cout << "###########################" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "###########################" << endl;
    srand(time(0));
    mx = rand() % 1 + 25 - 1;
    my = rand() % 16 + 2;
    while (tecla != 's')
    {
        while (tecla != 's' && !(tecla = kbhit()))
        {
            for (x = size[c]; x > 0; x--)
            {
                cx[x] = cx[x - 1];
                cy[x] = cy[x - 1];
            }
            if (d == 0)cx[0]--;
            if (d == 1)cy[0]--;
            if (d == 2)cx[0]++;
            if (d == 3)cy[0]++;
            mgotoxy(cx[size[c]], cy[size[c]]);
            printf(" ");
            if (mx == cx[0] && my == cy[0]){
                size[c]++;
                mx = rand() % 3 + 3;
                my = rand() % 15 + 3;
            }
            mgotoxy(cx[0], cy[0]);
            printf("#");
            mgotoxy(mx, my);
            printf("%c", 499);
            Sleep(speed);
            for (x = 1; x < size[c]; x++)
            {
                if (cx[0] == cx[x] && cy[0] == cy[x]) tecla = 's';
            }
            if (cy[0] == 0 || cy[0] == 18 || cx[0] == 0 || cx[0] == 26) tecla= 's';
        }
        if (tecla != 's') tecla = getch();
        if (tecla == 'K') d = 0;
        if (tecla == 'H') d = 1;
        if (tecla == 'M') d = 2;
        if (tecla == 'P') d = 3;
        if (tecla == 'p') {
#ifdef _WIN32
            system("cls");
#else 
            system("clear");
#endif
            cout << "###########################" << endl;
            cout << "# ----------------------- #" << endl;
            cout << "#        p a u s e        #" << endl;
            cout << "# ----------------------- #" << endl;
            cout << "#                         #" << endl;
            cout << "#                         #" << endl;
            cout << "#                         #" << endl;
            cout << "#                         #" << endl;
            cout << "#          ______         #" << endl;
            cout << "#  Senha: |" << size[c] << "    |        #" << endl;
            cout << "#         |" << speed << "   |        #" << endl;
            cout << "#         --------        #" << endl;
            cout << "# ----------------------- #" << endl;
            cout << "#                      z  #" << endl;
            cout << "#                     z   #" << endl;
            cout << "#                    z    #" << endl;
            cout << "#   #################     #" << endl;
            cout << "# ----------------------- #" << endl;
            cout << "###########################" << endl;
            getch();
            goto game;
        }
        if (cy[0] == 0 || cy[0] == 18 || cx[0] == 0 || cx[0] == 26) tecla = 's';
    }
gameover:
    int option;
#ifdef _WIN32
    system("cls");
#else 
    system("clear");
#endif
    cout << "###########################" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#    g a m e  o v e r     #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#         __________      #" << endl;
    cout << "# Senha: |" << size[c] << "        |     #" << endl;
    cout << "#        |" << speed  << "       |     #" << endl;
    cout << "#        ------------     #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "# Escolha uma opção:      #" << endl;
    cout << "# 0: Sair                 #" << endl;
    cout << "# 1: Continuar            #" << endl;
    cout << "# 2: Novo Jogo            #" << endl;
    cout << "# ----------------------- #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#                         #" << endl;
    cout << "#    ##############X#X    #" << endl;
    cout << "###########################" << endl;
    cin >> option;
    if (option == 0) {
        return 0;
    }
    if (option == 1) {
        goto game;
    }
    if (option == 2) {
        password = 1;
        goto set;
    }
    else {
        cout << "Comando inválido" << endl;
        getch();
        goto gameover;
    }
}

Scripts recomendados

Aterm multi-color

Squid - Modo de Trabalho

Também enche a memória, porém desta vez com processos

[C] Decompositor de números em fatores primos

Agenda


  

Comentários
[1] Comentário enviado por maurixnovatrento em 31/07/2020 - 08:24h


Gostei mas vou ter que adaptar para o linux.

___________________________________
Conhecimento não se Leva para o Túmulo.

[2] Comentário enviado por maurixnovatrento em 31/07/2020 - 08:27h


Olhando bem, parece que você pensou nisso. Vou testar.

___________________________________
Conhecimento não se Leva para o Túmulo.

[3] Comentário enviado por Nick-us em 04/08/2020 - 14:57h

A Iniciativa é boa, mas não consegui compilar ele no Linux. Abaixo são os erros que eu não soube consertar

snake.cpp: In function ‘void mgotoxy(int, int)’:
snake.cpp:16:5: error: ‘COORD’ was not declared in this scope
16 | COORD p = { x, y };
| ^~~~~
snake.cpp:17:43: error: ‘STD_OUTPUT_HANDLE’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~~~~~~
snake.cpp:17:30: error: ‘GetStdHandle’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~
snake.cpp:17:63: error: ‘p’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^
snake.cpp:17:5: error: ‘SetConsoleCursorPosition’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~~~~~~~~~~~~~
snake.cpp: In function ‘int main()’:
snake.cpp:48:5: error: ‘Sleep’ was not declared in this scope; did you mean ‘sleep’?
snake.cpp:724:42: error: ‘kbhit’ was not declared in this scope
724 | while (tecla != 's' && !(tecla = kbhit()))
| ^~~~~



[4] Comentário enviado por retro em 05/08/2020 - 09:19h


[3] Comentário enviado por Nick-us em 04/08/2020 - 14:57h

A Iniciativa é boa, mas não consegui compilar ele no Linux. Abaixo são os erros que eu não soube consertar

snake.cpp: In function ‘void mgotoxy(int, int)’:
snake.cpp:16:5: error: ‘COORD’ was not declared in this scope
16 | COORD p = { x, y };
| ^~~~~
snake.cpp:17:43: error: ‘STD_OUTPUT_HANDLE’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~~~~~~
snake.cpp:17:30: error: ‘GetStdHandle’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~
snake.cpp:17:63: error: ‘p’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^
snake.cpp:17:5: error: ‘SetConsoleCursorPosition’ was not declared in this scope
17 | SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), p);
| ^~~~~~~~~~~~~~~~~~~~~~~~
snake.cpp: In function ‘int main()’:
snake.cpp:48:5: error: ‘Sleep’ was not declared in this scope; did you mean ‘sleep’?
snake.cpp:724:42: error: ‘kbhit’ was not declared in this scope
724 | while (tecla != 's' &amp;&amp; !(tecla = kbhit()))
| ^~~~~





deve ser por eu estar usando a api do windows, e essa api é muito diferente da api do linux

[5] Comentário enviado por SamL em 16/08/2020 - 20:25h

Pra quem teve dificuldade pra compilar no Ubuntu:
Instale primeiro o Wine:
[Só seguir os comandos]
https://wine.htmlvalidator.com/install-wine-on-ubuntu-20.04.html
Depois instale estes pacotes:
sudo apt install g++-mingw-w64 gcc-mingw-w64 mingw-w64
Pra compilar basta baixar o game.cpp e compilar com:
x86_64-w64-mingw32-g++ game.cpp -o game.exe -static-libgcc -static-libstdc++
Execute com:
wine ./game.exe

O jogo ficou bom aqui, só que no terminal do Linux fica muito bugado.
____________________________________________
https://nerdki.blogspot.com/ acessa aí vai lá, é grátis!
Acesse meu jogo aqui:
https://github.com/cpusam/dangerous_tux

[6] Comentário enviado por maurixnovatrento em 17/08/2020 - 00:24h


Eu baixei e ainda não testei, vou ver como fica no linux qualquer dia desses.

___________________________________
Conhecimento não se Leva para o Túmulo.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts