Skip to main content

Posts

Showing posts from March, 2018

Tic-tac-toe Game

A tic-tac-toe game in C++ using basic data structures and algorithm. In this game initially there is a matrix of size 3X3 on the console. Two players select one character each from {0, X}. Alternatively they place their character at one unused cell of the matrix. If a player makes a straight combination of three similar characters of his choice,that player wins the game otherwise game is a draw. This game was developed in C++ using code-blocks IDE. Code : #include <iostream> #include<windows.h> using namespace std; //  play matrix char matrix[3][3] = {'1','2','3','4','5','6','7','8','9'}; char player = 'X'; // initially I have set player X's turn int n = 0; //  to count the number of cells filled // to draw the play matrix void Draw(){     system("cls");// Console is made clear when Draw() function is called     cout<<"Tic-tac-toe game v1.0...

Snake and Fruit Game

A Snake and fruit game in C++ using basic data structures and algorithm. In this game initially there is a fruit at some random location and snake head lies in the middle of the console. By pressing left, right, top, down buttons, snake head moves accordingly. If stop button is pressed, game is paused.  If the snake eats the fruit then its tail’s length increase, score increases by ten points and a new fruit is generated at some random location in the console. If snake hits the wall or bites itself then the game will terminate. This game was developed in C/C++ using code-blocks IDE. Code :  //  header files #include <bits\stdc++.h> #include<conio.h> #include<windows.h> using namespace std; bool gameOver; // to check whether game is over or not const int width = 30;   // width of the window const int height = 20;  // height of the window int x; // current x-position of the snake int y; //  current y-pos...