File Folder Locker

                        File Folder Locker

Authors:

Raihanoor Farid(170218)

Ahsanul Haque(170223)

Mostaq Ahmed Polok(170232)

Ashiquer Rahman Naim(170238)

Computer Science and Engineering Discipline,

Khulna University

11th  November 2018

 

File Folder locker is used to hide personal folder of user.

 

We made this project using C programming language. We used file to hide information.

First, we use string to store the path of the folder that we want to hide.in our code there are three functions.

They are

1.Setcolour()

2.Lockfolder()

3.Unlockfolder()

 

Description of the function

 

1.Setcolour();

This function is used to set the colour of the text of our code.We use different colour in our code using different integer value. If we pass the value in setcolour function the function set different colour of the text.

 

2.Lockfolder();

This function is used to lock the folder. First it takes the path of the folder, that we want to hide.Then it stores the path in other palce and delete the path from the directory. So,the folder is locked.

 

3.Unlockfolder();

This function is used to retrieve the folder that we have locked.This takes the path and make new path for it and the folder is accessable again.

 

 

 

LINK OF THE CODE IS GIVEN BELOW

https://drive.google.com/file/d/1K3aiEb2Od06hiS7SJoYbwpR1txeaBi8H/view?fbclid=IwAR33TBz8CNE7_t0Q7FhEcsHAlvPi1HUZecZDQw65r21pDcUFV-3xX6Zj1ks

 

Student report card

                                                                       Student report card

Anika Asfi,Rownok Jahan Silvy,

Nakshi Saha and Al Amin Shaikh

Computer Science and Engineering Discipline,

Khulna University

Khulna,Bangladesh

 

 

Introduction: Student report card provides us with the information about a student’s name, student id with the marks and gpa etc.

 

We made this project using C programming language. We used file to store the information of the students.

Reference: http://mini-projects-in-c.blogspot.com/2011/04/student-report-card.html

 

Explanation: First, we use structure to store the information in our code. Struct student st. for every case we input the name roll and the marks of 3 subject. For this we just collected 3 subject numbers. We used input to take the desired input from the user if the user wishes to see the data they just simply call displayall() function. Inside input function we called gradecalculation() function to calculate the desired grade after that we appended the structure to the file. When user wants to see the output simply call the displayall() function which will show the total entry with grade and gpa. We used a standard library <stdlib> header . This header gives us a function called system. Using this function we send a string parameter “cls” which tells the programme to clear the screen we used student.txt file to store the data we  created a structure and saved the structure in the student.txt file . when we need to show the data we simply retrieve the data from the txt file.

 

How to run: while running the code user will be asked if he wants to see the result menu or entry or to exit using entry he will store the information of students using writestudent function and user will be shown information with grade and details when user goes to result menu

 

ALL THE CODE AND PIC ARE GIVEN BELOW:

https://drive.google.com/open?id=1uwJy7l8o-5-L-I5eCFFRTxfCixY9cEIL

source code link: https://github.com/nakshisaha/project_1c-/blob/master/student%20report%20card

Written By:

1.Anika Asfi (Student ID: 170224)

2.Rownok Jahan Silvy (Student ID: 170234)

3.Nakshi Saha(Student ID: 170236)

4.Al Amin Shaikh (Student ID :160229)

 

 

WHO WILL BE THE MILLIONAIRE (Using File Directory)

C Project

Who Will Be The Millionaire

(Using File Directory)

 

Authors:

Nafisa Binta Tofayel (180205)

Jawadul Islam (180213)

Musfiq Rahman (180214)

Jannatul Ferdous (180215)

Mukit Hasan Pranto (180224)

 

Computer Science and Engineering Discipline,

Khulna University.

28 October 2018.

Indroductry

C is an inevitable part of coding. Most of us who wants to learn programming as a beginner, starts by learning C. Mini projects like creating games or applications is always fun and challenging for a beginner programmer who completed learning the core parts of C language. The game “Who Will Be The Millionaire” is inspired by the famous reality show goes with the same name. The source code is not that long, over 400 lines. It is compiled in Code::Blocks IDE with GCC compiler. Various sound effect has been added to this project so in compiler linker settings “winmm” has been added. To help understand the code many comments will be given in the source code.

N.B: This project is created with file directory so other .txt file is as important as the source file.

Click on the link below to directly download the source file along with other important files used in this project.

 

Download Link

Click here to download all the mandatory files needed for this project ->

Download Here

 

 

About This Project

The project on “Who Will Be The Millionaire” is an console application which has no graphics interface. Although various sound effects are used. The unique thing about this game is, it is created mainly by file directory. Total number of 15 questions will be presented in the game and all 15 of them will be randomly selected from 15 files which contains 10 questions each. A total number of 32 .txt files are created. 15 files for questions and 15 files for answer and lastly 2 files for adding and showing records. There are also 3 .wav files created for Intro, right answer and wrong answer background music. The prize pool ladder for 15 questions is as same as the original.

 

 

First of all, to add audio effect “winmm” library need to be added in the compiler linker setting.

https://drive.google.com/file/d/1Y-jdirjYppBNj-e4GbbG9d7BzNTfZxAe/view?usp=sharing

https://drive.google.com/file/d/1dsQrA051uAqgicw_sNaKXKS2Bjk0O7Kt/view?usp=sharing

-+

Gameplay

The game opens in the main menu which has 3 options.

https://drive.google.com/file/d/1g1B0s1beqU2WVaBXJWfoSQRNnlv652Zx/view?usp=sharing

By pressing ‘I’, the introduction window pops up, in which the prize money ladder is explained.

https://drive.google.com/file/d/19fx8yf_awTeGPkFh4VzJdp6nDEPmTB0f/view?usp=sharing

By pressing ‘R’, the previous records for the game shows up.

https://drive.google.com/file/d/1wZU0-MePaFh7V0zt_H-LtyQTkVa9mG0W/view?usp=sharing

By pressing ‘S’, The game of knowledge begins. For every right answer, player will get the rightful amount of prize money and climb up the ladder.

https://drive.google.com/file/d/1_wMdstIwqMRUCDkM-SFkuSZQ5BpR-kBO/view?usp=sharing

But for a wrong answer, the game will be terminated and player will return to the main menu.

https://drive.google.com/file/d/1muORgeRARgA0M0bjavRv1DB1qzAmjWaw/view?usp=sharing

 

 

 

Function Explanation

The functions used in the source code are simple and easy to understand. They are described in the source code with comments.

The following library functions are used:

  1. <stdio.h> – for standard input output
  2. <conio.h> – for console input output
  3. <ctype.h> – for case sensitivity
  4. <time.h> – for generating a random number
  5. <windows.h> – for declaration of all the function especially <MMSystem.h>
  6. <MMSystem.h> – multimedia function for adding multimedia files.

 

The following user defined functions are used:

  1. void open_sector(char question[20], char answer[20]) : This is the most important function. It contains two other functions named as ‘void questions() and ‘void answer_match()’. It opens both the question and answer files in reading mode. After that it calls both the functions.

https://drive.google.com/file/d/1bfZt1LsdD2iY0V8-CcWHDOGxY7Iak2gM/view?usp=sharing

 

  1. void question(): First a random number is generated by using srand(time(0)), rand() and <time.h>. Then it prints a random question with options.

https://drive.google.com/file/d/1yGybPvxAQuF5wcJZaSiVsEUDvhkaNqeq/view?usp=sharing

 

  1. void answer_match(): First an input is taken from the user then it matches with the correct answer. If it doesn’t match the answer then the game will take user to the main menu.

https://drive.google.com/file/d/1W-wbxNXN083NOMPG47uE-K5xg0qtx5cu/view?usp=sharing

 

  1. void add_record(): After every game ends. The name of the player and the prize money is printed in a separated file.

https://drive.google.com/file/d/1Ed9CA6gz6t-knhdObqEFdwHVzP95kIkC/view?usp=sharing

 

  1. void show_record(): It shows the previous records in the console by printing the values from the file.

https://drive.google.com/file/d/15kksc7kcFHJHWkDpnPiFeG92MkiaqDb_/view?usp=sharing

 

Thank you very much.

 

THE END

 

Virus With C

Virus

with C

Authors:

Charles Chayon Mondol (180208)

Abu Dawod Rahman (180216)

Rabiul Hasan Nayan (180234)

Muntaseer Hafiz (180239)

What is a Computer Virus?

A computer virus is a malicious program that self-replicates by copying itself to another program. In other words, the computer virus spreads by itself into other executable code or documents. The purpose of creating a computer virus is to infect vulnerable systems, gain admin control and steal user sensitive data. Hackers design computer viruses with malicious intent and prey on online users by tricking them.

One of the ideal methods by which viruses spread is through emails – opening the attachment in the email, visiting an infected website, clicking on an executable file, or viewing an infected advertisement can cause the virus to spread to your system. Besides that, infections also spread while connecting with already infected removable storage devices, such as USB drives.

It is quite easy and simple for the viruses to sneak into a computer by dodging the defense systems. A successful breach can cause serious issues for the user such as infecting other resources or system software, modifying or deleting key functions or applications and copy/delete or encrypt data.

There are two types of ways in viruses operate, as soon as they land on a new device they begin replicating, while the second type plays dead until a particular trigger makes the malicious code to be executed. Thereby, it is highly important to stay protected by installing a robust antivirus program.

Presently, the sophisticated ones come with evasion capabilities that help in bypassing antivirus software and other advanced levels of defenses. Subsequently, the polymorphic malware development in the recent times enables the viruses to dynamically change its code as it spreads. This has made the virus detection and identification very challenging.

 

Different Types of Virus:

  • Boot Sector Virus.
  • Web Scripting Virus.
  • Browser Hijacker.
  • Resident Virus.
  • Direct Action Virus.
  • Polymorphic Virus.
  • File Infector Virus.
  • Multipartite Virus.
  • Macro Virus.

Among these types of viruses, we have tried to make some Direct-Action Viruses using only C language.

Here we have made 4 sample Direct-Action Viruses that uses

File directory access to manipulate, delete, copy and as well as making its own replica.

And almost all of them implements the header file dirent.h which enables us accessing through the file directories.

dirent.h

The <dirent.h> header defines the following data type through typedef: DIR. A type representing a directory stream. It also defines the structure dirent which includes the following members: ino_t d_ino file serial number char d_name [] name of entry. The type ino_t is defined as described in <sys/types.h>.

This header file is used in our codes and its library functions like readdir                                                                has been used for various purposes

 

We have created Four Viruses

  • Self-Replicating Virus
  • Copy Virus
  • Memory eater
  • Deleting Virus

All of them are Direct action Virus and they are controllable under certain circumstances.

We have also tested them on Windows operated machines and also in Virtual Box to avoid certain complexity and damage of the machines.

 

Self-Replicating Virus

This virus’s work is to replicate its own executive file in every folder of a partition. For making this virus we will need to work with directory. We need DIR type pointer to access directory and struct dirent type pointer. We will also need to work with strings and dynamically allocate memory. So, we will need stdio.h, stdlib.h, string.h, dirent.h header file.

LINK OF THE CODE IS GIVEN BELOW

https://drive.google.com/open?id=1UaJfmt8XzZpSTEQCEAnObfFZqzKjmTNx&fbclid=IwAR2VT6bTX3_ycBt77Af-rj6VDwAkD9RARx3Erate6Hjf59PA2EQLuEZKhWE

Here we only need to give this virus a path and it will make a copy of its own executive file in each folder including the path folder. Firstly, we need include stdio.h, stdlib.h, string.h, dirent.h header files.

In the main function we have just used a user defined function “replicate_d”. Its return type is “void” and its parameter have a character type pointer. The formal view of this function is: “void replicate_d (char *str1)” We have also used three more user defined function named addstring, copy, fileorfolder. Formal view of these functions is:

char *addstring (char *str1, char *str2)

It takes two-character type pointer as parameter and returns a character type pointer.

  • Its work is to add two strings. The first pointer *str1 points the first string. The second pointer *str2 points the second string. This function just adds these two strings returns the joined string.
  • In this function firstly, we have declared two integer len1 and len2 and assigned the length of the first string and the second string respectively. For doing this we have used “strlen” function.
  • We have declared a character type pointer *str and 3 integer type variable I, j, k;
  • Then we have dynamically allocated memory to *str. For this reason, we need “malloc” function. Malloc function dynamically allocates memory. Here we have allocated (len1+len2+1) numbered character type memory.
  • Then we assigned two strings one after another by using loop and added a null character at the next memory of the last character. And have return the str.

int fileorfolder (char *str)

It takes a character type pointer as parameter and returns an integer.

int copy (char *str)

It takes a character type pointer as parameter and returns an integer. The work of four user defined functions are:

void replicate_d (char *str1)

We have worked with the directory in this function. We have opened the directory with opendir () function and read the file or folder of that directory with readdir () function. If an element is folder then we copy the main executive file in that folder. We have copied the main executive file with copy () function and figured out that element is file or folder with fileorfolder () function. We have used recursion to go through all the folders

int fileorfolder (char *str)

Its work is to let us know if the given string is file or folder. • Firstly, we have assigned the length of the string which the parameter pointer indicates in an integer variable.

  • If the string “.” or “..” the function will return 1 which means we don’t want to copy anything here. So, we have used control statement.
  • Then we have checked the whole string using loop. If we can find ‘.’ character there then the function will return 1. Because it would be a file. It will be a folder if the string doesn’t contain any ‘.’. So, we have controlled this situation in a loop with control statement. If the loop executed completely then it will return 0. That means the string is a folder as it doesn’t have any ‘.’ character in it.

int copy (char *str)

  • In this function we have declared two FILE type pointers *fp1 and *fp2. We have opened the main executive file with “fopen ()” function and assigned it in fp1. Then we have used the addstring function and added two strings one of which is saved in “str” and another one is “Virus.exe” and assigned the function’s return value into str1. Here “str” is a path. For using “Virus.exe”, this virus copies the same .exe file as the main .exe file of the virus.
  • Then we have opened and created a new file named “Virus.exe” and copied the full fp1 file to fp2.
  • Then we have closed fp2. And used rewind () function so that we can copy the fp1 again.

Thus, this is how the Self-Replicating Virus operates.

 

………………………………………………………………………………………………….

Copy Virus

This Virus’s work is to make a folder in partitions so that the space in drives goes out. We have used stdio.h, string.h, stdlib.h header file.

LINK OF THE CODE IS GIVEN BELOW

https://drive.google.com/open?id=1gE4odRZHaS6AqWSZWysPWjVYoiJNR95B&fbclid=IwAR2vfYauaDQ16uVE35jZeSdejxiaVZb5tMnrvoOyjACKAOTOUY2HbsAfFy4

 

We have used take () user defined function to copy files into C drive, take_d () user defined function to copy files into D drive and take_e () user defined function to copy files into E drive. First, we have copied files into C drive. We can’t just copy file into C drive because windows do not give us permission. So, we have created a folder first there using mkdir () function, then we have copied files there. For D and E drive, we can copy files there so we have not created any folder there. In main function we have taken an array of characters to determine the file name because we cannot make files having same name. The user defined function’s work is to copy a specific file. We have passed the name to the file through the parameter. In the function we have gone through loop where files would be created. Here we have used fopen (), fclose (), rewind () functions to do that.

………………………………………………………………………………………………….

Memory Eater

This virus tests the capacity of operating system of creating folder. We can create folder in our machine because windows provide us that accessibility to do so.

But there a question arises how much?

So, this virus was made to test the fact actually how much indeed how long the windows can offer us to create folders.

So, this simple code starts creating directories by mkdir (char [] s) when it runs the console prints and the directories are made. After sometime like 2-3 sec the device feels a bit laggy and the after that it hangs and disrupts doing the simple commands like closing the program. Though the windows recover when we close it after crashing due to stack overflow

LINK OF THE CODE IS GIVEN BELOW

https://drive.google.com/open?id=1EQCRVZXl-wlSAwWlXblaYUWzThAl5TEF&fbclid=IwAR31ZNxfP8m_7BUkELDEFevvM4ILJlJoiPlIbBwOJunQgLwrRt4mfDYfbzs

here we have a screenshot while running the virus and a window of Task Manager that indicates that the virus consuming the disk space and making CPU deal a heavy load thus, causing lag and hang eventually.

This virus enables us to make infinite directory creating approach which most of the windows versions handle pretty well but faces certain lag during this and lower OS will crash due to stack overflow.

https://drive.google.com/open?id=1wOfNfHgjXM6YiFS1vcZ1OSGg9WgS-BP_&fbclid=IwAR0oqlNwq8IRpZLbDhuox8i2o9013_iQztFGoBb-pwLos8MNP8hytJvQ2Cg

………………………………………………………………………………………………….

Deleting Virus

This virus’s work is to delete the files of the folder including itself where it is stored of a partition. For making this virus we will need to work with directory. We need DIR type pointer to access directory and struct dirent type pointer. We will also need to work with elimination and check availability of file in those directories and being able to open as well as reading those directories. So, we will need stdio.h, stdlib.h, string.h, dirent.h header file.

LINK OF THE CODE IS GIVEN BELOW

https://drive.google.com/open?id=1bvtm6QwPmi0B2PHARl-7J6O8p8-VPAVL&fbclid=IwAR19MBiSRMRTr7X3Y7vwFX4nt0sh_XZqtJjr5Q1IM5_jSR76NuAodmdSo5s

Here we only need to give this virus a path and it will delete all the files and folders of that directory. Firstly, we need include stdio.h, stdlib.h, string.h, dirent.h header files.

Here we have made some user defined functions to make the process easy those are addstring (char *s1, char *s2) , fileOrDir(char* aa) , deelet(char aa[])

char* addString (char *s1, char *s2)

this function returns a string pointer that adds Strings s1 & s2 that are given in the parameter.

  • We have dynamically allocated memory to *str. For this reason, we need “malloc” function. Malloc function dynamically allocates memory. Here we have allocated (len1+len2+1) numbered character type memory.
  • Then we assigned two strings one after another by using loop and added a null character at the next memory of the last character. And have return the str.

int fileOrDir (char* aa)

this function checks the given string whether it’s a file or a directory. Usually it looks for ‘.’ In a string to determine the given string as a file or it will be a directory –

  • It’s work is to let us know if the given string is file or folder. • Firstly, we have assigned the length of the string which the parameter pointer indicates in an integer variable.
  • If the string “.” or “..” the function will return 1 which means we don’t want to copy anything here. So, we have used control statement.
  • Then we have checked the whole string using loop. If we can find ‘.’ character there then the function will return 1. Because it would be a file. It will be a folder if the string doesn’t contain any ‘.’. So, we have controlled this situation in a loop with control statement. If the loop executed completely then it will return 0. That means the string is a folder as it doesn’t have any ‘.’ character in it.

 

 

int deelet (char aa [])

this function does the main part of this code by using the remove (char *s) function to delete the files in other words making the files address to the memory undetectable and returns zero if successful. remove () is a function of stdio.h header file which enables us damaging the files of the selected path and the directory location where the virus is stored.

In this scope we try to open the directory the virus is stored in using opendir () & also apply a recursive way to read the directories through using readdir () if the directory is null then we move forward using addString (bb,” \\”) after that when we find a file while opening the directories we use the remove function that makes the files disappear and after that close the directory using closedir ()

In the main function we just have to copy the path of the virus where it consists and after running the program all the files of the directory will be deleted except the directories.

And surprisingly it happens fast and big amount of data can be deleted within 2-3 secs only. Moreover, the data that are damaged cannot be found in the recycle bin!

Through the execution the virus itself will be deleted by itself after every execution and only the .exe will be available.

We have also upgraded the virus to be able to remove the directories also and avoiding more time complexity the code runs very fast.

LINK TO THE MAIN COPY OF THIS REPORT

https://drive.google.com/open?id=1EajsPzVRkqCmGGVjzx_IHfr43bccVQfu&fbclid=IwAR0OLFG8IZQgayYdFLcQYLwxZwpEA5clNf8RfmaZ8kvzgUtEjrwtF4IbA1k

Caution

  • The following viruses are tested and been proven to do what they are described this long.
  • Please be cautious while trying and executing these programs it can cause unrecoverable damage.
  • It is advised to use Virtual Box to test these Viruses & avoid certain difficulties.

 

 

 

 

 

 

 

 

 

 

MINESWEEPER GAME

Abstract
Minesweeper is a small grid-based game where a player has to identify hidden mines and open all the safe tiles. Players who are bored of staring at the same monitor and willing to play in a different monitor, can try this project game. The game was created by Robert Donner whilst working for Microsoft. The objective of the project is to create a tutoring system that will help the player how to play this game. While playing this game, strategies will be explored and the strategies will help a player to understand the game in an efficient and effective way.

Introduction
The computer game Minesweeper is a game that was made popular by the windows OS. The computer game minesweeper starts the game by showing you blank grid of squares. Some squares conceal mines, the rest are safe. Your task is to work out where the mines are without detonating any of them.

History of Minesweeper
Minesweeper is a single player puzzle game. The origin of the minesweeper game is the earliest mainframe game of the 60’ and 70’ decades. The earliest ancestor of Minesweeper was Jermiac Ratliff’s Cube. This game became more popular amongst puzzle games during 1980’s with the title of ‘Mined-out’ ,’Yomp’ and ‘Cube’.The game of minesweeper that we play now-a-days created for windows.
Robert Donner and Curtis Johnson, who worked for Microsoft, wrote and developed the game for release with the Microsoft Entertainment Pack for Windows 3.1 in 1990. It was then upgraded in 1992 to feature in the in-game pack, replacing Reversi in the process. Versions of Minesweeper are frequently bundled with operating systems and GUIs, including Minesweeper for OS/2, Minesweeper in Windows, KMines in KDE (Unix-like OSes), Gnomine in GNOME and MineHunt in Palm OS.

Game rules
At the beginning of the game, a 2D grid of identically looking tiles (or squares) is presented to the player. The player has to find all the mines and it determines the difficulty of the game. The goal of the game is to set up flags on the tiles that are containing mine. If the player reveals a tile containing a mine, the game will over. To prevent the mine from being exploded player has to set up the flags on all the mines that are possible according to the game rules. At first, the player has to reveal a tile which will show some numbers and that is the clue to find the mines. The number on a particular tile indicates number of possible mines around its adjacent eight tiles.

Code explanation
This game is a C based Minesweeper. To implement this code we used four header files: graphics.h, conio.h, stdio.h, time.h. Including these libraries we got some advantages. By using time.h library we can use srand(time(NULL)) function which helps us to generate random number in every execution. Using graphics.h libarary we get a graphical user interface. From this library we used different types of functions like
• initwindow(): This function initializes the graphics system by opening a graphics window of the specified size. The first two parameters (width and height) are required but all other parameters have default values.
• bar(): This function is used to draw a two dimensional rectangular filled bar which takes four parameters as the co-ordinates of the bar. First two arguments are the starting point and last two arguments are the ending point.
• line(): This function is used to draw a line which takes four parameters as the co-ordinates of the line. First two arguments are the starting point and last two arguments are the ending point.
• setcolor(): This function is used to set the current drawing color to the new color.
• outtextxy(): This function takes three parameters. First two are the co-ordinates and the third parameter is the string or the text we want to display.
• settextstyle(): This function is used to change the way in which text appears. It takes three parameters. First one is font style, second one is direction and third one is text size.
• cleardevice(): This function clears the graphics window.
• setfillstyle(): It sets the current fill pattern and color to new fill pattern and color.
• closegraph(): It closes the graphics mode.

How to play this game
When we run the code a window and console will pop up like shown below:

After pressing “enter” we will see two options: Play and game rules as in the picture:

If we press “space” we will see the game rules.

Press “ESC” to return to main menu.
If we press left key we will see a 6X6 grid which is the main board of the game and on the console we will have to enter a starting point to open a tile.

After entering row and column number, we will see this:

If we want to flag a tile, we will have to select the f mode and after giving the point we will see this output:

If we want to open a tile, we will have to select the o mode and input a point and the output will be like this:

If we want to remove a flag, we will have to select the r mode and input the point where we want to remove the flag.
If we successfully flag all the mines, we will win and we will see this output:
And if we open a tile which contains a mine we will lose and see this

To play this game, download the source code from here

Written By:
Ayasha Hossain Jui (180201)
Maliha Bintay Zaman (180210)
Samia Sharnami (180233)
Umma Habiba Akhey(180237)

Thank you

Ludo game (snake & ladder)

                                  Ludo  game

                              Snake &ladder

 

                           SUBMITTED  BY:

 Student name                                                 id

Md. Mazharul Islam                             (180203)

Rayhain Jobair                                       (180209)

Abid Afsan Hamid                                 (180217)

Sheikh Asif Hasan                                 (180223)

 

 

 

Introduction :

The game of Snakes and Ladders is today considered a classic, and is loved by children from all over the world. Whilst the game itself is known my most people, its origin is less well-known. As a matter of fact, the game of Snakes and Ladders is an ancient Indian invention, and was not played for mere entertainment, but had a philosophical dimension to it as well.

History of the ludo  game(snake & ladder):

The board game, today called Snakes and Ladders, originated in ancient India, where it was known with the name Mokshapat or Moska Patamu. It’s not exactly known when or who invented it, through it’s believed the game was played at a time as early as 2ad century BC. According to some historians , the game was invented by Saint Gyandev In  the 13th century AD. Orginlly ,the game was used as a part of moral instruction to children. The squaries in which ladders start were each supposed to stand for a virtue, and those housing the head of a snake were supposed to stand for a evil. The snakes outnumbered the ladders in the original Hindu game. The game was transported to England by the colonial rules in the latter part of the 19th century, with some notifications. The modified game was named snakes and Ladders and stripped of it’s moral and religious aspects and the number of laders and snakes were equlizesd.

 

Game Rules:

 

This game is played between two or more people. Each of the player can play the game with rolling the dice.

How to play:

  • Each player puts their counter on the space that says ‘start here’.

 

  • Take it in turns to roll the dice. Move your counter forward the number of spaces shown on the dice.

 

  • If your counter lands at the bottom of a ladder, you can move up to the top of the ladder.

 

  • If your counter lands on the head of a snake, you must slide

down to the bottom of the snake.

 

  • The first player to get to the space that says ‘home’ is the winner.

 

 

Using  graphichal function:

Line(): 

 

Declaration: void line(int  x1, int  y1, int  x2, int  y2);

 

 line function is used to draw a line from a point(x1,y1) to point(x2,y2) i.e. (x1,y1) and (x2,y2) are end points of the line.The code given below draws a line.

Circle():

Declaration: void circle(int x, int y, int radius);

 

Circle function is used to draw a circle with center (x,y) and third parameter specifies the radius of the circle. The code given below draws a circle.

Floodfill():

Declaration: void floodfill(int x, int y, int border);

floodfill function is used to fill an enclosed area. Current fill pattern and fill color is used to fill the area.(x, y) is any point on the screen if (x,y) lies inside the area then inside will be filled otherwise outside will be filled,border specifies the color of boundary of area. To change fill pattern and fill color use setfillstyle. Code given below draws a circle and then fills it.

Setfillstyle():

Declaration: void setfillstyle( int pattern, int color);

 

Setfillstylefunction sets the current fill pattern andfill color.

Setcolour():

Declaration: void setcolor(int color);

 

Total 16 colors are available. Strictly speaking number of available colors depends on current graphics mode and driver.For Example :- BLACK is assigned 0, RED is assigned 4 etc. Setcolorfunction is used to change the current drawing color.e.g. Setcolor(RED) or setcolor(4) changes the current drawing color to RED. Remember that default drawing color is WHITE.

Outtextxy():

Declaration: void outtextxy(int x, int y, char *string);

 

Outtextxy function display text or string at a specified point(x,y) on the screen.

Getmaxx():

Declaration: int getmaxx();

Getmaxx function returns the maximum X coordinate for current graphics mode and driver.

Getmaxxy() :

Declaration: int getmaxy();

 getmaxy function returns the maximum Y coordinate for current graphics mode and driver.

Getch():

getchfunction prompts a user to press a character and that character isn’t printed on screen,getch header file is conio.h. This function is not a part of standard C library.

Delay():

Declaration: void delay(unsigned int);

delay function is used to suspend execution of a program for a particular time.

Cleardevice():

Declaration: void cleardevice();

 

cleardevice function clears the screen in graphics mode and sets the current position to (0,0). Clearing the screen consists of filling the screen with current background color.

Rand():

rand is using for print random number.

 

 

Code explanation:

In our code we use graphics. For this we need to use graphics .h header file. For this we need to ready our codeblocks for supporting graphics .h. Then we use as usual header file. Now we go to our code:

At first we declare a global array. Then we also declare two array for snake and for ladder that’s return type is boolean.  Then we make a rectangular board where we use some line function to draw the 100 square boxes where every boxes have value sequence according the basic ludo game. For this we use loop and in this we use sprintf and outtextxy, function of c++. Then for changing the color of the value  we use setcolor function. Then we make some snake using circle function. For coloring that snake we use setfillstyle and floodfill function to color the snake. Then we use ladder to increasing the value. The ladder is made with line function. We using so many line function to make the ladder. Now in main function we use random number to roll the dice. Then according to the value the pointer will move .And  the value is set in the current score. And all the value will print beside the board and it will using the function outtextxy. We also make a dice which will show the value  of random number in star. We also use placeguti function for changing the row and column form lower to upper. It will the row when one row is end the column will increase in 45. So the column will change and then it starting from the right.

And in this process the code executed. It is the main functionality of our function.

 

When we run the code a window and console will pop up like shown below:

 

First view after opening the consol…….

https://drive.google.com/open?id=1GtCftri10ZAMcpOjnCkR8rLeqIPruhCJ

Then after pressing 1……

https://drive.google.com/open?id=1_csFXdHgzuIAnxDyzKFGCEUcaSHnlLAA

After that press 3 to open the game……..

https://drive.google.com/open?id=1eYTaX7Y_6ybomeN8Gw_fInhhPdsANG7-

Then after throwing the dice ………

https://drive.google.com/open?id=1PNEXB7Rt3TRDxOen8tzWb6jXok0tG00A

https://drive.google.com/open?id=1NSVcveV8qbsR6nnNiT1k_K8L4VlWrqgu

https://drive.google.com/open?id=1H00jgnaJY3KrIomKtzL4KsC165zZDrme

At the last, when game is over it will show who will win……

https://drive.google.com/open?id=1LuWdr0QeAn09duxxM5WcSRfLKcNJPnMc

Now the code link is here ……….

https://drive.google.com/open?id=1fLVur5EFzBycx__FXX9tEQ-i2yS3wUcc

  • This code can be downloaded from this link.

                                            Thank you

 

 

A Snake Game Program Using C

Abstract: It is a game in which a snake is controlled by a person to eat foods(dots). As the foods are eaten the score is increased.

 

Introduction: In this game the person controls the snake with the arrow keys to eat foods. There are borders at the end of the screen at four sides.As the snake hits any of the borders,the snake dies.

 

Explaination :

 

The project(Snake Game) is written in C language.

First we added “#include<graphics.h>”header file to “CODEBLOCKS”  using this link and then we started coding.

 

DWORD scwidth = GetSystemMetrics(SM_CXSCREEN);

DWORD scheight = GetSystemMetrics(SM_CYSCREEN);

initwindow(scwidth, scheight, “The Snake Game”);

 

DWORD means “double word”.It is defined in windows.h header file.It contains integer value in the range 0 through 4,294,967,295.

 

GetSystemMetrics() and initwindowfunctions are written to create a window fit to the screen on which the game will be  played.

GetSystemMetrics(SM_CXSCREEN) and GetSystemMetrics(SM_CYSCREEN) functions return integer type value which indicate the pixels of the screen width and height respectively.

Initwindow()

This function takes 7 arguments,2 arguments are necessary other 5 arguments are optional.The first and second arguments create the window.We set first and second arguments as the returned values of GetSystemMetrics(SM_CXSCREEN) and GetSystemMetrics(SM_CYSCREEN) functions.We set the third argument as the name of the window.

 

 

x[0]= scwidth/2;

y[0]= scheight/2;

 

Writing x[0]= scwidth/2 and  y[0]= scheight/2 line of code we set the initial position of the snake as the  middle of the screen .This two lines make the head of the snake.

 

l=5;

Writing l=5,we set the initial length of  snake as 5 blocks.

 

Food coordinates :

 

rx=rand()%scwidth;

ry=rand()%scheight;

    if(rx<=(scwidth/2)) rx+=50;

    else rx-=50;

    if(ry<=(scheight/2)) ry+=50;

    else ry-=50;

 

 

 

rand()

It is a function that generates random number.

 

If the random numbers is greater than the screen,then after getting the modulus value of the function and screen width and screen height we set the food coordinates in the screen.For preventing the food generation on border we increased or decreased the value of the coordinates with 50.

 

Graphics Functions:

 

setcolor()

This function takes 1 argument as parameter.The colors are assigned in numbers.We can pass the color as the name of the color(in capital letters)or the assigned numbers.It sets the current drawing color.

 

settextstyle()

This function takes 3 arguments as parameters.First,second and third arguments are text font,text direction text size respectively.They are integer type.The arguments can be passed as assigned numbers or like this format :

 

settextstyle(BOLD_FONT, HORIZ_DIR, 5);

 

outtextxy()

This function takes 3 arguments.First 2 arguments is the coordinates of the text which  is to be appeared on the screen and the third argument is the text itself or the text can be stored into a string and then the string can be passed.

 

sprintf()

This function takes two arguments and it passes the second argument into the first argument.If we take this line to be clear,

sprintf(ins, “WELCOME TO SNAKE GAME”);

the second part is passed into first argument as string(ins named string should be declared first).

 

setfillstyle()

This function takes two arguments.First argument is pattern and second argument is color.There are 13 values which are allowed as pattern.We can even pass the value.

 

bar()

This function takes 4 integer type arguments.The first and second arguments are the starting point of X and Y axes.The third and fourth arguments are the ending point of X and Y axes.

 

getpixel()

This function returns the color of pixel at point (x,y).

 

 

GetAsyncKeyState()

This function is used for detecting key presses.

 

VK_RIGHT means right arrow key.

VK_LEFT means left arrow key.

VK_UP means up arrow key.

VK_DOWN means down arrow key.

VK_RETURN means enter key.

 

These are the parameters of this function.

 

 

 

 

Double Buffering (Graphics function):

 

setactivepage()

This function makes the page as active graphic page.An active graphic page is a page in which the graphics are drawn off screen.It is not visible page.

 

setvisualpage()

This function makes the page as visual graphics page.It is visible on screen.

 

These two functions prevent flickering.

 

 

How to play Snake Game :

 

One has to press the arrow keys to move the snake. If the position of snake head is overlapped with the food,then the food will be eaten and score and the length of the snake will be increased. But if the snake touches the border the snake dies.

 

 

Starting playing ,at first a window will pop up like this

 

https://drive.google.com/file/d/1eNmfd_i5rdnb1zl4JWNcmsu-9g2YVJFn/view?usp=sharing

 

After pressing any key ,the game will start.

It will look like this

https://drive.google.com/open?id=1TyW8fNNqKGWQVyYpzgojEw_Ubh-r_nEi

 

If the snake hits the border,then it will look like this,

 

https://drive.google.com/open?id=1qua-RDs6aeyMDIb8OpmpB7_gRbRO5QmJ

 

DOWNLOAD: Download our source code from https://github.com/PronabSarker/Snake_Game/blob/master/main.cpp

 

 

 

Authors:

Ruhit Arman (Student ID: 180222)

Md. FizulHaque (Student ID: 180230)

Pronab Sarker (Student ID: 180236)

Md. Tarif Hasan(Student ID :180238)

 

Computer Science and Engineering Discipline, Khulna University, Khulna.

 

A Simple Calculator With Graphics And Mouse Operation In C

                                                    Simple Calculator

We make a calculator using graphics and mouse operation in c language. In this calculator we can add, subtraction, multiplication and division between two numbers. After resulting ,we can again add , subtract, multiply, divide with the former result.

#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<graphics.h>

 

Here, we use “#include<graphics.h>” header files for

draw different shapes, display text in different fonts, change  color  and many more. Using functions of graphics.h  in Turbo C compiler for making our calculator with a particular design “#include<dos.h>”contains functions for handling interrupts, producing sound, date and time functions etc. It is Borland specific and works in Turbo C compiler.

 

We can use some functions to making this calculator,the functions are given below:

 

  • int initmousedetect();
  • void showpointer();
  • void openwindow();
  • void closewindow();

 

  • void hidepointer();
  • void getmouseposition(int *,int*,int*);
  • void restrictpointer(int,int,int,int);

 

 

 

How it works:

Firstly when we press any key button, the getmouseposition() takes three arguments. Here contains button , x co-ordinate  and y co-ordinates. In this function we get the position of the pressing key. Then it goes to

 

“if((x>=c && x<=c+40)&&(y>=d&&y<=d+40))”.

                 here  c=240;   d=100;

After  checking this operation it goes  to

“ if((button&1)==1)” 

this operation, after confirming it, the array index

“Char input=inp[a][b]”

“inp[a][b]” it contains the character into char input.

The character input now goes to switch case function, after completing the case it operates the operation between the numbers and print the result

 

How Button works:   (The given code is hereJ)

For (a=0; a<4 ; a++) {

c=240;

d=100;

for (b=0 ; b<4;b++)

{

if((x>=c&&x<=c+40) && (y>=d&&y<=d+40))

{

if((button&1) ==1)

{

While ((button&1 )==1)

{

Setcolor(WHITE);

rectangle (c ,d,c+40,d+40);

rectangle (c-1,d-1,c+41,d+41);

rectangle (c-2, d-2, c+42 ,d+42);

break;

}

delay(100);

setcolor(WHITE);

char    input=inp[a][b];

Then input contains digit from inp[a][b],,Then this input goes to switch case operation,After matching it,it contains operation the following instruction.

How can we use this calculator:

After compiling and running this code ,new window is opening here shows the welcome page, then we have to press any key to go ahead, then it goes to our calculator, here we have to input any digit by clicking on it by mouse. After that we have to press any operation then we have to click on other digit then we have to press “=”.After that we will get result, Not only that, we can also operates the result with the new digit or number.

we can add, subtract, multiply, divide on the user defined given number. After that we have to press any key, then it goes to our last page, here contains thank you and references.

To do mouse programming we use “include <dos.h>”. We use a function called int86() to access     ” interrupts”.

we use “int   initmousedetect()” for  detecting whether mouse click or not. Here we use “void  openwindow()” to open a new window, “void  closewindow()” for closing window, for get mouse position we use “void getmouseposition (int *,int*,int*)” this function ,for taking a particular point in mouse we use “void restrictpointer(int,int,int,int)”.We now restrict the mouse in particular rectangle .

We create a function called restrict which takes

four parameters, two Cartesian points each containing one

x coordinate and one y coordinate.

First point mentions the top of the rectangle while second point mention the bottom point of rectangle.

char input;

char*inpu[4][4]={“1″,”2″,”3″,”4″,”5″,”6″,”7″,”8”,     “9”,”0″,”+”,”-” ,”*”,”/”,”clr”,”=”};

Here we input characters ,that will a part of our calculator, by input variable.

“initgraph (&driver,&mode,”C:\\TC\\BGI“)” ,we use this   for   graphics operation of making shapes of calculator.

 

We use “union REGS in, out” .
REGS is the union of two structures. The union REGS has been defined dos.h and it is used to pass information to and from the functions, int86, int86x, intdos and intdosx.

“long double addnum(int);

char opr;”

Here we use addnum function to take  many digits at a  same time ,which contains call that:

long double addnum(int getnum)

{

num = num*10+getnum;

return(num);

};

when we take operation from keyboard ,it then in switch case,after matching operation type it operates the digit.At the last ,the result will go to printf, which type is long double.

For making calculator ,we use some graphics functions such as outtextxy(),setcolor(),bar(),rectangle(),gotoxy().For clear  screen device we are using cleardevice();

  • initwindow(): This function initializes the graphics system by opening a graphics window of the specified size. The first two parameters (width and height) are required but all other parameters have default values.

bar(): This function is used to draw a two dimensional rectangular filled bar which takes four parameters as the co-ordinates of the bar. First two arguments are the starting point and last two arguments are the ending point.

  • line(): This function is used to draw a line which takes four parameters as the co-ordinates of the line. First two arguments are the starting point and last two arguments are the ending point.
  • setcolor(): This function is used to set the current drawing color to the new color.
  • outtextxy(): This function takes three parameters. First two are the co-ordinates and the third parameter is the string or the text we want to display.
  • settextstyle(): This function is used to change the way in which text appears. It takes three parameters. First one is font style, second one is direction and third one is text size.

“while(!kbhit()) “:  kbhit function is used to determine if a key has been pressed or not. To use kbhit function in our program we should include the header file “conio.h”. If a key has been pressed then it returns a non zero value otherwise returns zero.

After completing switch case operation, it goes to printf() and it prints the result in our graphical calculator screen.At the last part of code ,we print “THANK YOU” by outtextxy() graphics function.

 

Firstly we open a window with welcom page:

https://drive.google.com/file/d/1U0lw2iUjEWr4W0uJvpFNwJNbXJIn2FpU/view?usp=sharing

Then it goes to our calculator:

https://drive.google.com/file/d/1vFBzwUAI73_1sRC2zyPT1lQFFa2Aiisi/view?usp=sharing

Ending point of our project :

https://drive.google.com/file/d/1C-UwYcerLzCdLmp9puzLRPvHoQwtMomk/view?usp=sharing

Here you can download our project:

https://github.com/sayeediku/CALCULATOR_PROJECT/blob/master/CALCULATOR_PROJECT.cpp

 

 Reference:

For our mouse operation we took help from:

“www botskool.com”“https://www.dreamincode.net/forums/topic/150609-graphics-calculator/?fbclid=IwAR1y-jijSwqxsjNuzDGNlf9aF1BmJtQ9xzkDflnfCZXgJGMMVwOXgOkuBP8

 

Written by:   

                     

MD.Sifatur Rahman(180206)

MD.SohanurRahman(180218)

MD.Sayeedi Mottakin(180227)

MD.Asif Anam(180228)

Thank you

                                    

SUDOKU GAME

GROUP MEMBERS : 

NAME-                           STUDENT ID 
MD Ahsan Habib –     180211
Mahbub E Elahi –       180212
Sk. Wasiqul Hoque – 180219
Al Afiat Emon –           180231

WHAT IS SUDOKU ?

Sudoku is a logic based combinatorial number-placement puzzle . The objective is to fill a 9×9 box with digits so that each column, each row, and each of the nine 3×3 subgrids that compose the grid (also called “boxes”, “blocks”, or “regions”) contains all of the digits from 1 to 9. We provide a partially completed grid, which has a single solution.

HOW TO PLAY

· There is only one valid solution to each Sudoku puzzle. The only way the puzzle can be considered solved correctly is when all 81 boxes contain numbers and the other Sudoku rules have been followed.

· When you start a game of Sudoku, some blocks will be pre-filled for you. You cannot change these numbers in the course of the game.

·Each column must contain all of the numbers 1 through 9 and no two numbers in the same column of a Sudoku puzzle can be the same.

· Each row must contain all of the numbers 1 through 9 and no two numbers in the same row of a Sudoku puzzle can be the same.

· Each block must contain all of the numbers 1 through 9 and no two numbers in the same block of a Sudoku puzzle can be the same.

INTERPRETATION OF THE CODE

We made this project using C programming language . We implemented the graphics.h library header function which wasn’t built-in with codeblocks . We downloaded and learned how to use it from https://learn24bd.com/how-to-enable-graphics-h-in-codeblocks .

First we used the initialwindow function () for controlling the size/bar/exit sign. Then we set the text color in graphics window . After that we used the ‘settextstyle()’ function to control the size and font of the text. We used ‘outtextxy()’ function to control and write the desired text in the graphics window. Then we used the ‘getch()’ function. Finally we used ‘cleardevice()’ function to format the graphics window. On the fresh window we set the background color using ‘setfillstyle()’ , ‘setbkcolor()’and ’floodfill()’ . Then we created 81 boxes by using ‘rectangle()’ function inside 9 for loops. Then we separated the 3X3 boxes by using a different color ‘line()’ function . We read a sample sudoku problem from a file and solution then stored them in 2 2D array one for the problem and one for the solution. Then we inserted the values of the unsolved problem array in each box of the graphics window by using ‘sprintf()’ and ‘outtextxy()’ function. Mainly we used ‘sprintf()’ function to convert the integer type into character type because ‘outtextxy()’ can only take character type values. We used red color in ‘setcolor()’ function to indicate the unsolved values (in this case 0) and we used green color in ‘setcolor()’ function to indicate other given values.
Now we started solving the problem. When the player wants to rewrite the an unsolved value all he needs to do to right click that certain box to rewrite the value of the box. We took the answers in the console from the player by using ‘scanf ()’ function and placed them in the unsolved boxes in the graphic window. Then we match the player’s answer with actual answer. If the answer is correct then it turns green. We did it by using ‘setcolor ()’ function. If the answer is wrong then it turns red so that the player can understand that his answer is wrong… One by one the player will fill up all the unsolved boxes. If his solution is correct then program will show him “WELL DONE”. The player can play the game once again by pressing 0. We use ‘goto’ function to do that.

ALL THE CODE AND PIC ARE GIVEN BELOW:
https://drive.google.com/drive/folders/1KXa6i3VLxceTEYrpYXabMXMMmhBeKVsv?fbclid=IwAR1PmKCK1ObtN1A-rKA6uA6w_COlHBCtAJg2ssfZcGyJdyB0JhwgvxcHb24 ….