#C++ Code For An Obstacle Game:
Instructions:
This is very simple and one of my old projects I've created.It's
probably the best one,as it really looks like a game,mind you the
code is not very complicated.It has 11 levels you can try, every
level the speed and the amount of "birds" is increasing.The
controls are arrow keys for moving and 1 / 2 for shooting.
Code:
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <ctime>
#include <vector>
class game
{
private:
std::vector <int> fake;
char map[1800];
int x;//COORDINATES
int c;
int speed;
int points ;
int CurrentLevel;
bool check;
public:
game()
{
x = 1940;
speed = 215;
check = 0;
points = 0;
}
void PrepareGraphics();
void graphics();
void LevelMenu();
void Levels();
void LOGIC();
void gameover();
friend void cls();
friend void sp();
friend void s();
};
void cls()
{
HANDLE hOut;
COORD Position;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = 0;
Position.Y = 0;
SetConsoleCursorPosition(hOut, Position);
}
void game::Levels() //Just minimize this function
////////////////////////////////////////////////////////////////////////////*//
{
speed-=20;
for(int a = 0;a < 1800;a++)
{
map[a] = ' '; //CLEAN IT FIRST
}
switch(CurrentLevel)
{
case
1://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 26;b++)
{
map[b + 7] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 47] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 87] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 127] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 167] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 207] = char(253);
}
break;
case
2://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 26;b++)
{
map[b + 7] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 47] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 87] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 127] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 167] = char(253);
}
for(int b = 0;b < 26;b++)
{
map[b + 207] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
break;
case
3://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 30;b++)
{
map[b + 5] = char(253);
}
for(int b = 0;b < 30;b++)
{
map[b + 45] = char(253);
}
for(int b = 0;b < 30;b++)
{
map[b + 85] = char(253);
}
for(int b = 0;b < 30;b++)
{
map[b + 125] = char(253);
}
for(int b = 0;b < 30;b++)
{
map[b + 165] = char(253);
}
for(int b = 0;b < 30;b++)
{
map[b + 205] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
break;
case
4://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 34;b++)
{
map[b + 3] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 43] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 83] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 123] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 163] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 203] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
break;
case
5://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 38;b++)
{
map[b + 1] = char(253);
}
for(int b = 0;b < 38;b++)
{
map[b + 41] = char(253);
}
for(int b = 0;b < 38;b++)
{
map[b + 81] = char(253);
}
for(int b = 0;b < 38;b++)
{
map[b + 121] = char(253);
}
for(int b = 0;b < 38;b++)
{
map[b + 161] = char(253);
}
for(int b = 0;b < 38;b++)
{
map[b + 201] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
break;
case
6://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 34;b++)
{
map[b + 3] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 43] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 83] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 123] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 163] = char(253);
}
for(int b = 0;b < 34;b++)
{
map[b + 203] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 400] = char(253);
}
break;
case
7://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 40;b++)
{
map[b] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 40] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 80] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 120] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 160] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 200] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
break;
case
8://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 40;b++)
{
map[b] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 40] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 80] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 120] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 160] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 200] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 400] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 440] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 480] = char(253);
}
break;
case
9://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 40;b++)
{
map[b] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 40] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 80] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 120] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 160] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 200] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 400] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[400 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[440 + 2 * b] = char(253);
}
break;
case
10://///////////////////////////////////////////////////////////////*//
for(int b = 0;b < 40;b++)
{
map[b] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 40] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 80] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 120] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 160] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 200] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 400] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[400 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[440 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[480 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[520 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[560 + 2 * b] = char(253);
}
break;
case 11:
for(int b = 0;b < 40;b++)
{
map[b] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 40] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 80] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 120] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 160] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 200] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 240] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 280] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 320] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 360] = char(253);
}
for(int b = 0;b < 40;b++)
{
map[b + 400] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[400 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[440 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[480 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[520 + 2 * b] = char(253);
}
for(int b = 0;b < 20 ;b++)
{
map[560 + 2 * b] = char(253);
}
break;
default:
system("cls");
std::cout << "CONGRULATIONS ";
Sleep(5000);
}
PrepareGraphics();
}
//////////////////////////////////////////////////////////////////////////
void sp(int spalva)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),
spalva);
}
void game::LevelMenu()
{
std::cout <<"CONTROLS: > ^ < for moving and 1 / 2 for
shooting...";
Sleep(4500);
system("cls");
system("color a5");
sp(481);
std::cout << "CHOOSE YOUR LEVEL:";
std::cout <<"1." << std::endl;
std::cout <<"2." << std::endl;
std::cout <<"3." << std::endl;
std::cout <<"4." << std::endl;
std::cout <<"5." << std::endl;
std::cout <<"6." << std::endl;
std::cout <<"7." << std::endl;
std::cout <<"8." << std::endl;
std::cout <<"9." << std::endl;
std::cout <<"10."<< std::endl;
std::cout <<"11."<< std::endl;
int y;
while(y > 12 || y < 1)
{
std::cin >> y;
}
if(y == 1)
{
CurrentLevel = 1;
speed = 215;
}
else if(y == 2)
{
CurrentLevel = 2;
speed = 195;
}
else if(y == 3)
{
CurrentLevel = 3;
speed = 175;
}
else if(y == 4)
{
CurrentLevel = 4;
speed = 155;
}
else if(y == 5)
{
CurrentLevel = 5;
speed = 135;
}
else if(y == 6)
{
CurrentLevel = 6;
speed = 115;
}
else if(y == 7)
{
CurrentLevel = 7;
speed = 95;
}
else if(y == 8)
{
CurrentLevel = 8;
speed = 75;
}
else if(y == 9)
{
CurrentLevel = 9;
speed = 55;
}
else if(y == 10)
{
CurrentLevel = 10;
speed =35 ;
}
else if(y == 11)
{
CurrentLevel = 11;
speed = 28;
}
std::cout << "GET READY.";
Sleep(2500);
Levels();
}
void game::PrepareGraphics()
{
x = 1140;
map[x] = 'H';
graphics();
}
void game::graphics()
{
c = 0;
for(int CheckingForWin = 0;CheckingForWin <
40;CheckingForWin++)
{
if(map[CheckingForWin] == ' ')
{
c++;
}
}
if(c == 40)
{
CurrentLevel++;
std::cout << "Congrulations,you have passed this
level\n,let's try another one!";
Sleep(4000);
Levels();
}
std::cout << std::endl;
for(int k = 0;k < 40;k++ )
{
std::cout << char(219);
}
std::cout << std::endl;
for(int u = 0;u < 1800;u++)
{
if(u!= 0 && u % 40 == 0)
{
std::cout << std::endl;
}
/////////////////////////////////////
/////////////////////////////////////
/////////////////////////////////////
if(map[u + 40] == char(173))
{
map[u + 40] = ' ';
if(map[u]!=char(253))
{
map[u] = char(173);
}
else
{
map[u] = ' ';
points++;
}
}
else if(u <= 39 && map[u] == char(173))
{
map[u] = ' ';
}
if(map[u] == char(253) && map[u + 40 ] != char(253))
{
c = rand() % speed + 1;
if(c == 5)
{
map[u + 40] = 'o';
}
};
if(map[u] == 'o')
{
for(unsigned int g = 0;g != fake.size();g++)
{
if(fake[g] == u)
{
g = fake.size() - 1;
check = 1;
}
}
if(!check)
{
map[u] = ' ';
if(x == u + 40)
{
gameover();
}
map[u + 40] = 'o';
fake.push_back(u + 40);
}
};
check = 0;
std::cout << map[u];
}
for(int h = 1760;h < 1800;h++)
{
if(map[h] == 'o')
{
map[h] = ' ';
}
}
fake.clear();
std::cout << std::endl;
for(int k = 0;k < 40;k++ )
{
std::cout << char(219);
}
std::cout << std::endl;
std::cout << "\n\n\n\n Points:" << points;
LOGIC();
}
void game::gameover()
{
system("cls");
std::cout <<"GG,YOU'VE JUST LOSE!";
std::cout <<"You scored " << points << "
points\n";
Sleep(2000);
std::cout <<"Restarting...";
Sleep(2000);
system("cls");
system("color a5");
sp(481);
LevelMenu();
}
void game::LOGIC()
{
if (GetAsyncKeyState(VK_LEFT))
{
if(x % 40 != 0)
{
if(map[x - 1] == 'o')
{
gameover();
};
x--;
map[x + 1] = ' ';
map[x] = 'H';
}
}
else if (GetAsyncKeyState(VK_RIGHT))
{
if((x + 1) % 40 != 0)
{
if(map[x + 1] == 'o')
{
gameover();
};
x++;
map[x - 1] = ' ';
map[x] = 'H';
}
}
else if (GetAsyncKeyState(VK_UP))
{
if(x > 480)
{
x-=40;
map[x+40] = ' ';
map[x] = 'H';
}
}
else if (GetAsyncKeyState(VK_DOWN))
{
if(x < 1760 )
{
x+=40;
map[x - 40] = ' ';
map[x] = 'H';
}
}
else{}
if(_kbhit())
{
char l = _getch();
if(l == '1' || l == '2')
{
map[x - 40] = char(173);
};
}
cls();
graphics();
}
int main()
{
system("color a5");
sp(481);
srand((unsigned)time(0));
game *memb;
memb = new game;
memb->LevelMenu();
}
#Note: Hope this code is useful for you. This is not same as you want but its similar to what you want . so you can learn from this code and make your own game.
JAVA GUİ And THREADS You will write a hunt-hunter game that runs on a 500x500 screen. In the ga...
Write a java program that simulates the operation of a Halloween Vampire Hunt game. In the game scenario, you are a vampire hunting a victim in a dark cave. The cave consists of 10 by 10 little squares, numbered 0-9 on each side; your victim is in the cave, with x-coordinate and y-coordinate 0-9 (both integers). On each turn, you guess where your victim is, and try to bite her/him. Your “health” is determined by the number of bloodpoints you...
Game Description: Most of you have played a very interesting game “Snake” on your old Nokia phones (Black & White). Now it is your time to create it with more interesting colors and features. When the game is started a snake is controlled by up, down, left and right keys to eat food which appears on random locations. By eating food snake’s length increases one unit and player’s score increases by 5 points. Food disappears after 15 seconds and appears...
Code in JAVA You are asked to implement “Connect 4” which is a two player game. The game will be demonstrated in class. The game is played on a 6x7 grid, and is similar to tic-tac-toe, except that instead of getting three in a row, you must get four in a row. To take your turn, you choose a column, and slide a checker of your color into the column that you choose. The checker drops into the slot, falling...
For this lab you will write a Java program that plays the dice game High-Low. In this game a player places a bet on whether the sum of two dice will come up High (totaling 8 or higher), Low (totaling 6 or less) or Sevens (totaling exactly 7). If the player wins, they receive a payout based on the schedule given in the table below: Choice Payout ------ ------ High 1 x Wager Low 1 x Wager Sevens 4 x...
1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...
In Java, Using arrays. You are going to write a program that will play a solitaire (one-player) game of Mancala (Links to an external site.) (Links to an external site.). The game of mancala consists of stones that are moved through various buckets towards a goal. In this version of mancala, the user will be able to choose a number of buckets and a number of stones with which to set up the game. The buckets will be created by...
Java BlackJack Game: Help with 1-4 using the provided code below Source code for Project3.java: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; public class Project3 extends JFrame implements ActionListener { private static int winxpos = 0, winypos = 0; // place window here private JButton exitButton, hitButton, stayButton, dealButton, newGameButton; private CardList theDeck = null; private JPanel northPanel; private MyPanel centerPanel; private static JFrame myFrame = null; private CardList playerHand = new CardList(0); private CardList dealerHand = new CardList(0);...
The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...
The following guidelines outline the basic template for a robot vacuum cleaner game. The game must be implemented in c programming language. It mimics a robotic vacuum cleaner. The code must only use the following libraries: #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> and any .graphics and .timers libraries. The guidelines are outlined as follows: Terminal Set-up: you may assume that the terminal will be quite large, for example, on the order of 150×50, or more. Status Display: The...
I am doing an Arduino Uno project where I made a "Simon says" memory game with 3 neopixel LED strips and 3 - ultrasonics. I have them working independently but I need to combine the code so they work together. Here is what I have: Memory Game #define PLAYER_WAIT_TIME 2000 // The time allowed between button presses - 2s byte sequence[100]; // Storage for the light sequence byte curLen = 0; // Current length of the sequence byte inputCount =...