Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions basket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let basket = {
goodlist: [],

countTotalPrice() {
var priceSum = 0;
for (i in this.goodlist) {
let finalPrice = this.goodlist[i].price * this.goodlist[i].amount;
priceSum += finalPrice;
}
return priceSum;
},

countTotalNumber() {
let totalNum = 0;
for (i in this.goodlist) {
totalNum += this.goodlist[i].amount;
}
return totalNum;
}
}
4 changes: 4 additions & 0 deletions code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

console.log(basket);
console.log(basket.countTotalNumber());
console.log(basket.countTotalPrice());
66 changes: 66 additions & 0 deletions goods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
let goods = [
{
name: 'лампа',
price: 1200,
amount: 4,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'диван',
price: 25000,
amount: 1,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'тумба',
price: 4500,
amount: 2,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'зеркало',
price: 5000,
amount: 4,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'шкаф',
price: 35000,
amount: 1,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'туалетный столик',
price: 7000,
amount: 2,
putToBasket() {
basket.goodlist.push(this);
}
},
{
name: 'пуфик',
price: 2000,
amount: 2,
putToBasket() {
basket.goodlist.push(this);
}
}
]
goods.forEach(function(item, i) {
if (i % 2 == 0) {
item.putToBasket();
} else {
item.putToBasket();
item.putToBasket();
}
});
25 changes: 25 additions & 0 deletions hw4-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<meta charset="UTF-8">

<script>
function countNum() {
let number = prompt('Назовите число от 0 до 999');

let arrNum = number.split('').reverse();

let obj = {
'сотни': arrNum[2],
'десятки': arrNum[1],
'единицы': arrNum[0]
}

if (arrNum.length <= 3) {
return obj;
} else {
return ('Число больше 999 :(');
}
}

console.log(countNum());


</script>
15 changes: 15 additions & 0 deletions hw4-2_main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="basket.js"></script>
<script src="goods.js"></script>
<script src="code.js"></script>

</body>
</html>
28 changes: 28 additions & 0 deletions hw4-3_code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
let game = {

run() {
while(true) {
let direction = prompt('Введите направление: 2, 8, 4, 6');
if (direction === null) {
console.log('Игра окончена');
return;
}

let nextPoint = mover.getNextPoint(direction);
renderer.clear();
player.move(nextPoint);
renderer.render();

}
},

init() {
console.log('Для начала игры введите команду game.run()');
renderer.render();
},

};



game.init();
5 changes: 5 additions & 0 deletions hw4-3_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

let config = {
nRows: 10,
nColemns: 10
};
16 changes: 16 additions & 0 deletions hw4-3_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script src="hw4-3_mover.js"></script>
<script src="hw4-3_player.js"></script>
<script src="hw4-3_config.js"></script>
<script src="hw4-3_renderer.js"></script>
<script src="hw4-3_code.js"></script>
</body>
</html>
76 changes: 76 additions & 0 deletions hw4-3_mover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
let mover = {
getNextPoint(direction) {
let nextPoint = {
x: player.x,
y: player.y
}

switch (direction) {
case '2':
if (player.y == 0) {
nextPoint.y;
} else {
nextPoint.y--;
}
break;
case '6':
if (player.x == 9) {
nextPoint.x;
} else {
nextPoint.x++;
}
break;
case '8':
if (player.y == 9) {
nextPoint.y;
} else {
nextPoint.y++;
}
break;
case '4':
if (player.x == 0) {
nextPoint.x;
} else {
nextPoint.x--;
}
break;
case '3':
if (player.y == 0 || player.x == 9) {
nextPoint.x;
nextPoint.y;
} else {
nextPoint.x++;
nextPoint.y--;
}
break;
case '1':
if (player.x == 0 || player.y == 0) {
nextPoint.x;
nextPoint.y;
} else {
nextPoint.x--;
nextPoint.y--;
}
break;
case '7':
if (player.x == 0 || player.y == 9) {
nextPoint.x;
nextPoint.y;
} else {
nextPoint.x--;
nextPoint.y++;
}
break;
case '9':
if (player.x == 9 || player.y == 9) {
nextPoint.x;
nextPoint.y;
} else {
nextPoint.x++;
nextPoint.y++;
}
break;
}
return nextPoint;
}
};
10 changes: 10 additions & 0 deletions hw4-3_player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let player = {
x: 0,
y: 0,

move(nextPoint) {
this.x = nextPoint.x;
this.y = nextPoint.y;
}
};

33 changes: 33 additions & 0 deletions hw4-3_renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Объект отрисовки карты
*/


let renderer = {
map: '',
/**
* Метод отрисовки карты
*/
render() {

for(let i = 0; i < config.nRows; i++) {
for(let j = 0; j < config.nColemns; j++) {
if (player.x == j && player.y == i) {
this.map += 'o';
} else {
this.map += 'x';
}

}
this.map += '\n';
}


console.log(this.map);
},

clear() {
console.clear();
this.map = '';
}
};