Project Report (Game)
Project Report (Game)
Project Report
On
“Gaming Website (Duo Gamer)”
Using
HTML, CSS, JAVASCRIPT
Submitted By :
Shivali Kumari (1907051063)
Sanya Chouhan (1907051059)
Contents 1
Certificate ……………………… 3
Declaration …………………….. 4
Acknowledgement ……………... 5
Abstract ………………………… 6-7
Introduction to Html, CSS, and
JavaScript ………………………. 8-10
Steps in making Gaming
Website (output with coding) .. 11- 57
Bibliography………………… 58
3
DECLARATION
We, hereby declare that the discussion entitled
“Gaming Website(Duo Gamer)” being submitted by us
towards the fulfillment of the Assessment Major
Project in the Department of Computer Engineering is
a project work carried by us under the supervision of
Dr. Neetu Mehta, and have not been submitted
anywhere else.
4
ACKNOWLEDGMENT
We like to share our sincere gratitude to all those who help us
in completion of this project. During the work we faced many
challenges due to our lack of knowledge and experience but
these people help us to get over from all the difficulties and in
5
ABSTRACT
Rock, Paper, Scissors
What it is: An easy, fast game that everyone probably
already knows. But I like to be comprehensive, so here we go
with some rock-paper-scissors instructions. Rock-paper-scissors
is a quick win-loose game that is often used to determine who
will go first or who will win some other small privilege.
Best for: Two players. But you could have a giant rock-
paper-scissors tournament with tons of people!
6
Continue…
The type of game originated in China and spread with
increased contact with East Asia, while developing
different variants in sign over time.
Tetris
Tetris is a surprising game. On paper, at least, it
seems unlikely that something so basic should have done
so well beyond the year 1975. Nevertheless, it’s been a
consistently popular video game for decades. It was
invented in Russia, and it was never expected to be as
popular as it became. Yet, the reason it is so popular is that
it meets the key criteria for fun in a game.
The aim in Tetris is simple; you bring down blocks from
the top of the screen. You can move the blocks around,
either left to right and/or you can rotate them. The blocks
fall at a certain rate, but you can make them fall faster if
you’re sure of your positioning.
Your objective is to get all the blocks to fill all the empty
space in a line at the bottom of the screen; whenever you
do this, you’ll find that the blocks vanish and you get
awarded some points.
7
INTRODUCTION
Introduction to HTML :-
HTML stands for Hyper Text Markup Language. It is
used to design web pages using a markup language. HTML is the
combination of hypertext and markup language.
Hypertext defines the link between the web pages. It uses
predefined tags and elements which tell the browser how to
properly display the content.
Originally, HTML was developed with the intent of defining the
structure of documents like headings, paragraphs, lists, and so
forth to facilitate the sharing of scientific information between
researchers. Now, HTML is being widely used to format web
pages with the help of different tags available in HTML language.
HTML is a MUST for students and working professionals to
become a great Software Engineer specially when they are
working in Web Development Domain. Here list down some of
the key advantages of learning HTML:
Create Web site - You can create a website or customize an
existing web template if you know HTML well.
Become a web designer - If you want to start a carrer as a
professional web designer, HTML and CSS designing is a
must skill.
Understand web - If you want to optimize your website, to
boost its speed and performance, it is good to know HTML
to yield best results.
Learn other languages - Once you understands the basic of
HTML then other related technologies like javascript, php, or
angular are become easier to understand
8
Introduction to CSS :-
Cascading Style Sheets, fondly referred to as CSS, is a
simply designed language intended to simplify the process of
making web pages presentable.
CSS allows you to apply styles to web pages. CSS is easy to
learn and understand, but it provides powerful control over the
presentation of an HTML document.
CSS is a MUST for students and working professionals to
become a great Software Engineer specially when they are
working in Web Development Domain. I will list down some
of the key advantages of learning CSS:
Create Stunning Web site - CSS handles the look and
feel part of a web page. Using CSS, you can control the
color of the text, the style of fonts, the spacing between
paragraphs, how columns are sized and laid out, what
background images or colors are used, layout
designs,variations in display for different devices and
screen sizes as well as a variety of other effects.
Become a web designer - If you want to start a carrer as
a professional web designer, HTML and CSS designing
is a must skill.
Control web - CSS is easy to learn and understand but it
provides powerful control over the presentation of an
HTML document. Most commonly, CSS is combined
with the markup languages HTML or XHTML.
Learn other languages - Once you understands the
basic of HTML and CSS then other related technologies
like javascript, php, or angular are become easier to
understand.
9
Introduction to Javascript :-
JavaScript is a lightweight,
interpreted programming language. It is designed for creating
network-centric applications. It is complimentary to and
integrated with Java. JavaScript is very easy to implement
because it is integrated with HTML.
Javascript is a MUST for students and working professionals
to become a great Software Engineer specially when they are
working in Web Development Domain. I will list down some
of the key advantages of learning Javascript:
Javascript is the most popular programming language in
the world and that makes it a programmer’s great choice.
Once you learnt Javascript, it helps you developing great
front-end as well as back-end softwares using different
Javascript based frameworks like jQuery, Node.JS etc.
Javascript is everywhere, it comes installed on every
modern web browser and so to learn Javascript you really
do not need any special environment setup. For example
Chrome, Mozilla Firefox , Safari and every browser you
know as of today, supports Javascript.
Javascript helps you create really beautiful and crazy fast
websites. You can develop your website with a console
like look and feel and give your users the best Graphical
User Experience.
JavaScript usage has now extended to mobile app
development, desktop app development, and game
development.
Due to high demand, there is tons of job growth and high
pay for those who know JavaScript.
10
Welcome
To
Duo Gamer
11
Steps in making Gaming Website
(Duo Gamer)
Duo Gamer.html
<!DOCTYPE html>
<html>
<head>
<title>Duo Gamer</title>
<link rel="stylesheet" type="text/css" href="s.css">
</head>
<body>
<header>
<h2><font size="80px" face="Kristen ITC" >Duo Gamer</font></h2>
<ul>
<li><a href="Duo Gamer.html"><font size="4px">Home</font></a></li>
<li><a href="game.html"><font size="4px">Games</font></a></li>
<li><a href="rule.html"><font size="4px">Help</font></a></li>
</ul>
</header>
12
<main>
<p>Enjoy Duo Games!</p>
<button onclick="window.location.href='game.html'">
<font face="arial black">Play Now</font>
</button>
</main>
</body>
</html>
Coding (s.css)
*
{
margin:0;
padding: 0;
box-sizing: border-box;
}
body{
height: 100vh;
background: url("neon.png");
background-size: 100%;
background-repeat: no-repeat;
background-position: right;
background-color: black;
}
header{
height: 60px;
display: flex;
align-items: center;
justify-content: space-around;
color:rgb(206, 214, 210);
background-color: rgb(0, 0, 0);
text-shadow: #bb5500 10px 0px 10px;
}
header ul{
list-style: none;
display: flex;
}
13
header ul li{
width: 80px;
height: 60px;
line-height: 60px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
header ul li:hover{
background: linearGradient(#c53d8e,#f4f4f4);
Color: rgb(224, 139, 204);
}
main{
height: calc(100vh-60px);
display: flex;
justify-content: left;
align-items: left;
flex-direction: column;
}
main p{
width: 500px;
height: 80px;
font-family: Matura MT Script Capitals;
line-height: 80px;
text-align: center;
font-size: 50px;
margin-top: 130px;
margin-left: 50px;
color: rgb(35, 108, 172);
border-radius: 50px;
text-shadow: 1px 1px 2px rgb(47, 0, 255), 0 0 1em
rgb(202, 43, 26), 0 0 0.2em rgb(215, 236, 111);;
}
14
main button{
width: 200px;
height: 60px;
border: none;
outline: none;
border-radius: 10px;
margin-top: 70px;
margin-left: 170px;
font-size: 30px;
background: linear-gradient(#cc8899,#bb5500);
cursor: pointer;
font-family: Matura MT Script Capitals;
}
main button:hover{
transform: translate(6px);
transition: 0.2s;
}
a:link {
color: rgb(255, 255, 255);
text-decoration: none;
}
a:active {
color:#e2d1dd;
}
a:hover {
color: hotpink;
}
15
Game.html
Login Form
Signup Form
16
Coding (game.html)
<!DOCTYPE html>
<html>
<head>
<title>Games</title>
<link rel="stylesheet" type="text/css"
href="g.css">
</head>
<body>
<header>
<h2><font size="80px" face="Kristen ITC" >Duo
Gamer</font></h2>
<ul>
<li><a href="Duo Gamer.html"><font
size="4px">Home</font></a></li>
<li><a href="game.html"><font
size="4px">Games</font></a></li>
<li><a href="rule.html"><font
size="4px">Rules</font></a></li>
</ul>
</header>
<div class="wrapper">
<div class="title-text">
<div class="title login">
Login to play
</div>
<div class="title signup">
Signup to play
</div>
</div>
<div class="form-container">
<div class="slide-controls">
<input type="radio" name="slide" id="login"
checked>
<input type="radio" name="slide"
id="signup">
<label for="login" class="slide
login">Login</label>
<label for="signup" class="slide
signup">Signup</label>
<div class="slider-tab"></div>
17
</div>
<div class="form-inner">
<form action="play.html" method="post"
class="login">
<div class="field">
<input type="email" placeholder="Email
Address" name="email" id="email" required>
</div>
<div class="field">
<input type="password"
placeholder="Password" name="password" id="password"
required>
</div>
<div class="pass-link">
<a href=" ">Forgot password?</a>
</div>
<div class="field btn">
<div class="btn-layer"></div>
<input type="submit" value="Login">
</div>
<div class="signup-link">
Don't have an account? <a
href="">Signup now</a>
</div>
</form>
<form action="login.php" method="post"
class="signup">
<div class="field">
<input type="text" placeholder="Name"
name="name" id="name" required>
</div>
<div class="field">
<input type="email" placeholder="Email
Address" name="email" id="email" required>
</div>
<div class="field">
<input type="password”placeholder="Password"
name="password" id="password"required>
</div>
18
<div class="field btn">
<div class="btn-layer"></div>
19
Coding (g.css)
@import url('https://fonts.googleapis.com/css2?
family=Poppins:wght@200;300;400;500;600;700&display=swap')
;
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
header{
height: 70px;
width: 80%;
border-radius: 24px;
display: flex;
align-items: center;
justify-content: space-around;
color:rgb(206, 214, 210);
background-color: rgb(0, 0, 0);
text-shadow: #bb5500 10px 0px 10px;
}
header ul{
list-style: none;
display: flex;
}
header ul li{
width: 80px;
height: 60px;
line-height: 60px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
header ul li:hover{
background: linearGradient(#c53d8e,#f4f4f4);
Color: rgb(99, 187, 209);
}
header ul li:nth-child(1){
border-bottom: 4px solid #000000;
}
20
a:link {
color: rgb(255, 255, 255);
text-decoration: none;
}
a:active {
color:#f7f0f5;
}
a:visited:hover {
color: hotpink;
}
a:visited {
color:rgb(215, 225, 220);
}
html,body {
display: grid;
height: 100%;
width: 100%;
place-items: center;
background: url("login.jpg");
/* background: linear-gradient(-135deg, #c850c0,
#4158d0); */
height: 100vh;
background: url("login.jpg");
background-size: 100%;
background-repeat: no-repeat;
background-position: right;
background-color: black;
}
::selection{
background: #814dca;
color: rgb(244, 234, 234);
}
.wrapper{
overflow: hidden;
max-width: 390px;
background: rgb(227, 221, 221);
padding: 30px;
border-radius: 5px;
box-shadow: 0px 15px 20px rgba(0, 0, 0, 0.025);
}
21
.wrapper .slide-controls{
position: relative;
display: flex;
height: 50px;
width: 100%;
overflow: hidden;
margin: 30px 0 10px 0;
justify-content: space-between;
border: 1px solid rgb(171, 170, 170);
border-radius: 5px;
}
.slide-controls .slide{
height: 100%;
width: 100%;
color: rgb(238, 222, 222);
font-size: 18px;
font-weight: 500;
text-align: center;
line-height: 48px;
cursor: pointer;
z-index: 1;
transition: all 0.6s ease;
}
.slide-controls label.signup{
color: #000;
}
.slide-controls .slider-tab{
position: absolute;
height: 100%;
width: 50%;
left: 0;
z-index: 0;
border-radius: 5px;
background: linear-gradient(-135deg, #c850c0,
#4158d0);
transition: all 0.6s cubic-bezier(0.68,-
0.55,0.265,1.55);
}
input[type="radio"]{
display: none;
}
22
#signup:checked ~ .slider-tab{
left: 50%;
}
#signup:checked ~ label.signup{
color: rgb(222, 212, 212);
cursor: default;
user-select: none;
}
#signup:checked ~ label.login{
color: #000;
}
#login:checked ~ label.signup{
color: #000;
}
#login:checked ~ label.login{
cursor: default;
user-select: none;
}
.wrapper .form-container{
width: 100%;
overflow: hidden;
}
.form-container .form-inner{
display: flex;
width: 200%;
}
.form-container .form-inner form{
width: 50%;
transition: all 0.6s cubic-bezier(0.68,-
0.55,0.265,1.55);
}
.form-inner form .field{
height: 50px;
width: 100%;
margin-top: 20px;
}
.form-inner form .field input:focus{
border-color: #421b56;
/* box-shadow: inset 0 0 3px #fb6aae; */
}
23
.form-inner form .field input{
height: 100%;
width: 100%;
outline: none;
padding-left: 15px;
border-radius: 5px;
border: 1px solid rgb(163, 157, 157);
border-bottom-width: 2px;
font-size: 17px;
transition: all 0.3s ease;
}
.form-inner form .field input::placeholder{
color: rgb(217, 215, 215);
transition: all 0.3s ease;
}
form .field input:focus::placeholder{
color: #b3b3b3;
}
.form-inner form .pass-link{
margin-top: 5px;
}
.form-inner form .signup-link{
text-align: center;
margin-top: 30px;
}
.form-inner form .pass-link a,
.form-inner form .signup-link a{
color: #8a30a5;
text-decoration: none;
}
.form-inner form .pass-link a:hover,
.form-inner form .signup-link a:hover{
text-decoration: underline;
}
form .btn{
height: 50px;
width: 100%;
border-radius: 5px;
position: relative;
overflow: hidden;
}
24
form .btn .btn-layer{
height: 100%;
width: 300%;
position: absolute;
left: -100%;
background: -webkit-linear-gradient(-135deg, #c850c0,
#4158d0);
border-radius: 5px;
transition: all 0.4s ease;;
}
form .btn:hover .btn-layer{
left: 0;
}
form .btn input[type="submit"]{
height: 100%;
width: 100%;
z-index: 1;
position: relative;
background: none;
border: none;
color: rgb(227, 217, 217);
padding-left: 0;
border-radius: 5px;
font-size: 20px;
font-weight: 500;
cursor: pointer;
}
25
play.html
Tetris
26
Coding (play.html)
<html>
<head>
<title>Play</title>
<style>
*{
margin:0;
padding: 0;
box-sizing: border-box;
}
body{
background-repeat: no-repeat;
background-size: cover;
background: url("wall.png");
background-size: 100%;
}
header{
height: 70px;
width: 80%;
display: flex;
align-items: center;
justify-content: space-around;
color:rgb(206, 214, 210);
background-color: rgb(0, 0, 0);
text-shadow: #bb5500 10px 0px 10px;
border-radius: 20px;
margin-left: 120px;
}
header ul{
list-style: none;
display: flex;
}
header ul li{
width: 80px;
height: 60px;
line-height: 60px;
font-weight: bold;
text-align: center;
cursor: pointer;
}
27
header ul li:hover{
background: linearGradient(#c53d8e,#f4f4f4);
Color: rgb(99, 187, 209);
}
a:link {
color: rgb(255, 255, 255);
text-decoration: none;
}
a:active {
color: hotpink;
}
a:hover {
color: hotpink;
}
img{
float:center;
border:6px solid rgb(228, 101, 92);
opacity: 0.4;
height: 50%;
width: 70%;
transition: 1s;
}
img:hover{
float:center;
border:6px double rgb(163, 163, 32);
background-size:cover;
opacity:8.0;
transform:scale(1.3);
z-index:3;
}
.pqr{
float:left;
height:100%;
width:100%;
size: 50px;
padding-left: 200px;
padding-top: 80px;
}
28
table{
width:100%;
height:90%;
background-size:cover;
overflow:hidden;
overflow:visible;
}
</style>
</head>
<body>
<header>
<h2><font size="80px" face="Kristen
ITC" >Duo Gamer</font></h2>
<ul>
<li><a href="Duo
Gamer.html"><font size="4px">Home</font></a></li>
<li><a href="play.html"><font
size="4px">Games</font></a></li>
<li><a href="rule.html"><font
size="4px">Rules</font></a></li>
</ul>
</header>
<table colspan="2" rowspan="2" height="80%" width="25%"
>
<caption><font color="white"
face="arial black" size="7px">Click the game to play !
</font></caption>
<tr>
<td ><a href="index.html"><div
class="pqr"> <img src="rps.gif"></div></a></td>
<td><a href="tetris.html"><div
class="pqr"> <img src="Screen.png"></div></a> </td>
</tr>
</table>
</body>
</html>
29
index.html
Coding (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css" />
<meta charset="UTF-8" />
<meta="viewport" content="width=device-width, initial-
scale=1.0" />
<link rel="preconnect"
href="https://fonts.gstatic.com" />
<link rel="preconnect"
href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?
family=Barlow:wght@600&display=swap" rel="stylesheet">
<title>Rock Paper Scissors</title>
</head>
<body>
<div class="wrapper">
<div class="scoreboard"> 30
<div class="wrapper">
<div class="scoreboard">
<div class="title">
<img src='title.png' />
</div>
<div class="score">
<p> SCORE</p>
<h1> 0 </h1>
</div>
</div>
<div class="hands">
<div class="hand paper">
<img src="Paper.png"
onclick="pickUserHand('paper')"/>
</div>
<div class="hand scissors">
<img src="Scissors.png"
onclick="pickUserHand('scissors')"/>
</div>
<div class="hand rock">
<img src="Rock.png"
onclick="pickUserHand('rock')"/>
</div>
</div>
<div class="contest">
<div class="userhand">
<h1>YOU PICKED</h1>
<div class="handImageContainer">
<img id="userPickImage" sac="Paper.png">
</div>
</div>
<div class="referee">
<div class="decision"><h1> YOU WIN!
</h1></div>
<div class="new Game"
onclick="restartGame()">PLAY AGAIN</div>
</div>
31
<div class="computerhand">
<h1>COMPUTER PICKED</h1>
<div class="handImageContainer">
<img id="computerPickImage" src='Paper.png'/>
</div>
</div>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
Coding (style.css)
/*---------
Global styles
--------*/
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font-family: "Barlow Condensed", sans-serif;
}
/*
-------------------------
HTML elements
-------------------------
*/
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 100vw;
height: 100vh;
background-image: url("w.png");
background-size: cover;
}
32
.scoreboard {
width: 700px;
height: 150px;
border-radius: 15px;
border: 1px solid white;
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 50px;
}
.title {
padding-left: 30px;
}
.score {
width: 150px;
height: 114px;
background-color: white;
border: 1px solid white;
border-radius: 8px;
margin-right: 30px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.score h1 {
color: #565468;
font-size: 56px;
font-family: "Barlow", sans-serif;
}
.score p {
color: #0b31d9;
font-size: 16px;
font-style: normal;
font-weight: 600;
line-height: 19px;
letter-spacing: 2.5px;
text-align: left;
}
33
.hands {
background-image: url("triangle.png");
background-position: center;
background-repeat: no-repeat;
visibility: visible;
opacity: 1;
position: relative;
width: 476px;
height: 430px;
margin-top: 100px;
display: flex;
z-index: 0;
flex-wrap: wrap;
justify-content: center;
}
.hands img {
width: 200px;
height: 200px;
display: block;
}
.hands .paper {
margin-right: 20px;
}
.hands .scissors {
margin-left: 20px;
}
.hands .hand {
cursor: pointer;
transition: all 0.25s;
}
.hands .hand:hover {
transform: translate3d(0px, -8px, 0px);
}
.contest {
display: none;
margin-top: 50px;
width: 900px;
} 34
.contest img {
width: 275px;
height: 275px;
}
.contest > div {
flex: 1;
}
.contest h1 {
color: white;
font-size: 20px;
margin-top: 20px;
margin-bottom: 50px;
text-align: center;
}
.contest .newGame {
color: hsl(229, 25%, 31%);
background-color: white;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
transition: all 0.15s;
}
.newGame:hover {
background: rgb(218, 218, 218);
transform: translate3d(0px, -2px, 0px);
}
.contest .handImageContainer {
display: flex;
justify-content: center;
}
.referee {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
} 35
.referee h1 {
font-size: 45px;
color: white;
}
.computerhand {
display: flex;
flex-direction: column;
}
Coding (index.js)
const handOptions = {
"rock": "Rock.png",
"paper": "Paper.png",
"scissors": "Scissors.png"
}
let SCORE = 0;
const pickUserHand = (hand) => {
let hands = document.querySelector(".hands");
hands.style.display = "none";
let contest = document.querySelector(".contest");
contest.style.display = "flex";
// set user Image
document.getElementById("userPickImage").src =
handOptions[hand];
pickComputerHand(hand);
};
const pickComputerHand = (hand) => {
let hands = ["rock", "paper", "scissors"];
let cpHand = hands[Math.floor(Math.random() *
hands.length)];
referee(hand, cpHand);
36
// set computer image
document.getElementById("computerPickImage").src =
handOptions[cpHand]
referee(hand, cpHand);
};
const referee = (userHand, cpHand) => {
if (userHand == "paper" && cpHand == "scissors") {
setDecision("YOU LOSE!");
}
if (userHand == "paper" && cpHand == "rock") {
setDecision("YOU WIN!");
setScore(SCORE + 1);
}
if (userHand == "paper" && cpHand == "paper") {
setDecision("It's a tie!");
}
if (userHand == "rock" && cpHand == "scissors") {
setDecision("YOU WIN!");
setScore(SCORE + 1);
}
if (userHand == "rock" && cpHand == "paper") {
setDecision("YOU LOSE!");
}
if (userHand == "rock" && cpHand == "rock") {
setDecision("It's a tie!");
}
if (userHand == "scissors" && cpHand == "scissors") {
setDecision("It's a tie!");
}
if (userHand == "scissors" && cpHand == "rock") {
setDecision("YOU LOSE!");
}
if (userHand == "scissors" && cpHand == "paper") {
setDecision("YOU WIN!");
setScore(SCORE + 1);
}
};
37
const restartGame = () => {
let contest = document.querySelector(".contest");
contest.style.display = "none";
let hands = document.querySelector(".hands");
hands.style.display = "flex";
}
const setDecision = (decision) => {
document.querySelector(".decision h1").innerText =
decision;
}
const setScore = (newScore) => {
SCORE = newScore;
document.querySelector(".score h1").innerText =
newScore;
}
tetris.html
38
Coding (tetris.html)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width = device-
width, initial-scale = 1">
<title>Tetris</title>
<link rel="stylesheet" type="text/css"
href="mainstyle.css">
<script src="TetrisBasic.js"></script>
</head>
<body>
<canvas id='my-canvas'></canvas>
</body>
</html>
Coding (mainstyle.css)
body {
text-align: center;
background: rgb(176, 100, 100);
background: url("tetrisback.png");
background-repeat: no-repeat;
background-size: cover;
background-size: 100%;
display: flex;
}
#my-canvas {
background: rgb(183, 197, 134);
margin-left: 600px;
margin-top: 120px;
display: block;
justify-content: center;
background: linear-gradient(rgb(224, 193, 193)) ;
}
39
Coding (mainstyle.css)
let canvas;
let ctx;
let gBArrayHeight = 20; // Number of cells in array height
let gBArrayWidth = 12; // Number of cells in array width
let startX = 4; // Starting X position for Tetromino
let startY = 0; // Starting Y position for Tetromino
let score = 0; // Tracks the score
let level = 1; // Tracks current level
let winOrLose = "Playing";
// Used as a look up table where each value in the array
// contains the x & y position we can use to draw the
// box on the canvas
let coordinateArray = [...Array(gBArrayHeight)].map(e =>
Array(gBArrayWidth).fill(0));
40
// 4. Created to track the direction I'm moving the
Tetromino
// so that I can stop trying to move through walls
let DIRECTION = {
IDLE: 0,
DOWN: 1,
LEFT: 2,
RIGHT: 3
};
let direction;
class Coordinates{
constructor(x, y){
this.x = x;
this.y = y;
}
}
function SetupCanvas(){
canvas = document.getElementById('my-canvas');
41
ctx = canvas.getContext('2d');
canvas.width = 936;
canvas.height = 956;
// Draw score
ctx.fillText(score.toString(), 310, 127);
// Draw level label text
ctx.fillText("LEVEL", 300, 157);
// Draw level
ctx.fillText(level.toString(), 310, 190);
DrawTetromino();
}
function DrawTetrisLogo(){
ctx.drawImage(tetrisLogo, 300, 8, 161, 54);
}
function DrawTetromino(){
// Cycle through the x & y array for the tetromino
looking
43
// d keycode (RIGHT)
} else if(key.keyCode === 68){
// 4. Check if I'll hit the wall
direction = DIRECTION.RIGHT;
if(!HittingTheWall() && !
CheckForHorizontalCollision()){
DeleteTetromino();
startX++;
DrawTetromino();
}
// s keycode (DOWN)
} else if(key.keyCode === 83){
MoveTetrominoDown();
// 9. e keycode calls for rotation of Tetromino
} else if(key.keyCode === 69){
RotateTetromino();
}
}
}
function MoveTetrominoDown(){
// 4. Track that I want to move down
direction = DIRECTION.DOWN;
45
// 10. Automatically calls for a Tetromino to fall every
second
window.setInterval(function(){
if(winOrLose != "Game Over"){
MoveTetrominoDown();
}
}, 1000);
function CreateTetromino(){
// Get a random tetromino index
let randomTetromino = Math.floor(Math.random() *
tetrominos.length);
// Set the one to draw
curTetromino = tetrominos[randomTetromino];
// Get the color for it
curTetrominoColor = tetrominoColors[randomTetromino];
}
}
if(collision){
// Check for game over and if so set game over text
if(startY <= 2){
winOrLose = "Game Over";
ctx.fillStyle = 'white';
ctx.fillRect(310, 242, 140, 30);
ctx.fillStyle = 'black';
ctx.fillText(winOrLose, 310, 261);
} else {
CreateTetromino();
}
}
return collision;
}
function CheckForCompletedRows(){
52
stoppedShapeArray[x][y2] = square; // Draw
color into stopped
// Look for the x & y values in the lookup table
let coorX = coordinateArray[x][y2].x;
let coorY = coordinateArray[x][y2].y;
ctx.fillStyle = nextSquare;
ctx.fillRect(coorX, coorY, 21, 21);
square = 0;
gameBoardArray[x][i] = 0; // Clear the spot
in GBA
stoppedShapeArray[x][i] = 0; // Clear the
spot in SSA
coorX = coordinateArray[x][i].x;
coorY = coordinateArray[x][i].y;
ctx.fillStyle = 'white';
ctx.fillRect(coorX, coorY, 21, 21);
}
}
}
}
rule.html
Coding (rule.html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Rule</title>
<style>
*{
margin:0;
padding: 0;
box-sizing: border-box;
}
body{
background-repeat: no-repeat;
background-size: cover;
background: url("rule.png"); 55
background-size: 100%;
}
header{
header ul li:hover{
background: linearGradient(#c53d8e,#f4f4f4);
Color: rgb(99, 187, 209);
}
a:link {
color: rgb(255, 255, 255);
text-decoration: none;
}
a:active {
color: hotpink;
}
a:hover {
color: hotpink;
}
.img{
height:"60%" ;
56
width:"50%";
margin:"50px";
}
BIBLIOGRAPHY
https://www.youtube.com/watch?
v=C6jSg4VPNZE&t=1062s
https://github.com/marcoris/tetrisJS
https://www.codingnepalweb.com/login-and-
registration-form-in-html/
https://www.youtube.com/watch?v=tXn4cLwdY7w
57
Thank You
58