Skip to content

Commit

Permalink
Version 1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliastik committed Jan 31, 2020
1 parent 09b52b4 commit 111115b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 44 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Game written in pure JavaScript and object oriented.

## About this game

* Version: 1.4.2
* Version: 1.5
* Made in France by Eliastik - [eliastiksofts.com](http://eliastiksofts.com) - Contact : [eliastiksofts.com/contact](http://eliastiksofts.com/contact)
* License: GNU GPLv3 (see LICENCE.txt file)

Expand All @@ -27,6 +27,12 @@ Game written in pure JavaScript and object oriented.

## Changelog

* Version 1.5 (1/31/2020) :
- Performance improvement (multi-threading);
- Fixed speed management: the game is smoother;
- Major changes in the architecture of the game code (MVC, other changes);
- Bug fixes and other adjustments.

* Version 1.4.2 (10/7/2019) :
- Added a labyrinth mode: it's now possible to generate mazes. The goal is to find the path to the apple through the maze. Levels of this type are also possible (to download later).
- Bug fixes and other adjustments.
Expand Down Expand Up @@ -115,7 +121,7 @@ Jeu programmé en JavaScript pur et en orienté objet.

## À propos du jeu

* Version du jeu : 1.4.2
* Version du jeu : 1.5
* Made in France by Eliastik - [eliastiksofts.com](http://eliastiksofts.com) - Contact : [eliastiksofts.com/contact](http://eliastiksofts.com/contact)
* Licence : GNU GPLv3 (voir le fichier LICENCE.txt)

Expand All @@ -130,6 +136,12 @@ Jeu programmé en JavaScript pur et en orienté objet.

## Journal des changements

* Version 1.5 (31/01/2020) :
- Amélioration des performances (multi-threading) ;
- Correction de la gestion de la vitesse : le jeu est plus fluide ;
- Grands changements dans l'architecture du code du jeu (MVC, autres changements) ;
- Corrections de bugs et autres ajustements.

* Version 1.4.2 (07/10/2019) :
- Ajout d'un mode labyrinthe : il est désormais possible de générer des labyrinthes. Le but est de trouver le chemin vers la pomme à travers le labyrinthe. Des niveaux de ce type sont également possibles (à télécharger ultérieurement).
- Corrections de bugs et autres ajustements.
Expand Down Expand Up @@ -211,11 +223,10 @@ Jeu programmé en JavaScript pur et en orienté objet.

### À faire (ou idées) :

* Jeu multi-joueur en ligne (création d'un programme serveur avec socket.io)
* Améliorer l'IA pour l'empêcher de se bloquer -> plus long chemin si bloqué
* Bonus dans le mode niveaux (pièces obtenues en fonction du score/temps (1.75 fois ce qui est demandé dans l'objectif) permettant d'acheter des bonus (passer dernier niveau ou activer le mode assistant IA))
* (Afficher difficulté niveaux)
* (?) Nouveau type niveau avec le contrôle de plusieurs Snake joueurs (prit correctement en compte par le jeu)
* (Architecture client-serveur)

### Fait :

Expand All @@ -226,14 +237,16 @@ Jeu programmé en JavaScript pur et en orienté objet.
* hue-rotate ne fonctionne pas sur Microsoft Edge et Safari -> pas de changement de couleur des Snake possible (workaround trouvé avec le Snake pointé par la flèche + détection et texte différent)
* Animations
* Labyrinthes
* Multithreading
* MVC (architecture client-serveur)

### Problèmes :

* (Performances lorsque plusieurs Snake sur une seule grille (aux algorithmes d'IA -> nombreuses IA))

## Déclaration de licence

Copyright (C) 2019 Eliastik (eliastiksofts.com)
Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)

Ce programme est un logiciel libre ; vous pouvez le redistribuer ou le modifier suivant les termes de la GNU General Public License telle que publiée par la Free Software Foundation ; soit la version 3 de la licence, soit (à votre gré) toute version ultérieure.

Expand All @@ -243,7 +256,7 @@ Vous devez avoir reçu une copie de la GNU General Public License en même temps

----

Copyright (C) 2019 Eliastik (eliastiksofts.com)
Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Expand Down
2 changes: 1 addition & 1 deletion assets/css/main.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down
35 changes: 20 additions & 15 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down Expand Up @@ -66,13 +66,18 @@ SOLO_PLAYER_DOWNLOAD_LEVELS_TO = "snakeia_solo_player_downloadedLevels";
SOLO_AI_DOWNLOAD_LEVELS_TO = "snakeia_solo_ai_downloadedLevels";

var selectedMode = SOLO_AI;
var enableAnimations = true;
var showDebugInfo = false;

document.getElementById("versionTxt").innerHTML = APP_VERSION;
document.getElementById("appVersion").innerHTML = APP_VERSION;
document.getElementById("dateTxt").innerHTML = DATE_VERSION;
document.getElementById("appUpdateDate").innerHTML = DATE_VERSION;

document.getElementById("enableAnimations").onchange = function() {
enableAnimations = this.checked;
};

// Libs
String.prototype.strcmp = function(str) {
return ((this == str) ? 0 : ((this > str) ? 1 : -1));
Expand Down Expand Up @@ -721,39 +726,39 @@ function validateSettings(returnValidation) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls, mazeGrid);
var snake = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
} else if(selectedMode == SOLO_PLAYER) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls, mazeGrid);
var snake = new Snake(RIGHT, 3, grid, playerHumanType);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
} else if(selectedMode == PLAYER_VS_AI) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake = new Snake(RIGHT, 3, grid, playerHumanType);

if(sameGrid) {
var snake2 = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry);
games.push(new Game(grid, [snake, snake2], speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, [snake, snake2], speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
} else {
var grid2 = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake2 = new Snake(RIGHT, 3, grid2, PLAYER_AI, aiLevel, autoRetry);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed));
games.push(new Game(grid2, snake2, speed, document.getElementById("gameContainer"), false, false, progressiveSpeed));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed, null, null, null, null, !enableAnimations));
games.push(new Game(grid2, snake2, speed, document.getElementById("gameContainer"), false, false, progressiveSpeed, null, null, null, null, !enableAnimations));
}
} else if(selectedMode == AI_VS_AI) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry);

if(sameGrid) {
var snake2 = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry);
games.push(new Game(grid, [snake, snake2], speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, [snake, snake2], speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
} else {
var grid2 = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake2 = new Snake(RIGHT, 3, grid2, PLAYER_AI, aiLevel, autoRetry);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid2, snake2, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
games.push(new Game(grid2, snake2, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
}
} else if(selectedMode == BATTLE_ROYALE) {
if(sameGrid) {
Expand All @@ -768,20 +773,20 @@ function validateSettings(returnValidation) {
snakes.push(new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry));
}

games.push(new Game(grid, snakes, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed));
games.push(new Game(grid, snakes, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations));
} else {
if(battleAgainstAIs) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake = new Snake(RIGHT, 3, grid, playerHumanType, aiLevel, autoRetry);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed, 350, 250));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed, 350, 250, null, null, !enableAnimations));
}

for(var i = 0; i < numberIA; i++) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, autoRetry);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed, 350, 250));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), true, false, progressiveSpeed, 350, 250, null, null, !enableAnimations));
}
}
}
Expand Down Expand Up @@ -1106,7 +1111,7 @@ function playLevel(level, player, type) {
snakes.push(new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel));
}

var playerGame = new Game(grid, snakes, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed);
var playerGame = new Game(grid, snakes, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, null, null, null, null, !enableAnimations);
games.push(playerGame);
} else {
if(numberIA + 1 <= 2) {
Expand All @@ -1117,14 +1122,14 @@ function playLevel(level, player, type) {
var height = 250;
}

var playerGame = new Game(grid, playerSnake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, width, height);
var playerGame = new Game(grid, playerSnake, speed, document.getElementById("gameContainer"), true, true, progressiveSpeed, width, height, null, null, !enableAnimations);
games.push(playerGame);

for(var i = 0; i < numberIA; i++) {
var grid = new Grid(widthGrid, heightGrid, generateWalls, borderWalls);
var snake = new Snake(RIGHT, 3, grid, PLAYER_AI, aiLevel, false);

games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), false, false, progressiveSpeed, width, height));
games.push(new Game(grid, snake, speed, document.getElementById("gameContainer"), false, false, progressiveSpeed, width, height, null, null, !enableAnimations));
}
}

Expand Down
4 changes: 2 additions & 2 deletions assets/js/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ var GameConstants = {
IMAGE_SNAKE_SATURATION: 50,
IMAGE_SNAKE_VALUE: 77,
CARS_TO_PRERENDER: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "×"],
APP_VERSION: "1.4.2",
DATE_VERSION: "10/07/2019"
APP_VERSION: "1.5",
DATE_VERSION: "01/31/2020"
},
Direction: {
UP: 0,
Expand Down
6 changes: 5 additions & 1 deletion assets/js/src/gameUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,10 @@ GameUI.prototype.setNotification = function(notification) {
}

this.notificationMessage = notification;

if(this.notificationMessage instanceof NotificationMessage && this.disableAnimation) {
this.notificationMessage.disableAnimation = true;
}
};

GameUI.prototype.setTimeToDisplay = function(time) {
Expand Down Expand Up @@ -1315,7 +1319,7 @@ GameUI.prototype.drawSnakeInfos = function(ctx, totalWidth, caseWidth, caseHeigh
var caseX = Math.floor(posX * caseWidth + ((this.canvas.width - totalWidth) / 2));
var caseY = this.headerHeight + posY * caseHeight;

if(!this.snakes[i].gameOver) {
if(!this.disableAnimation && !this.snakes[i].gameOver) {
var offset = this.offsetFrame / (this.speed * GameConstants.Setting.TIME_MULTIPLIER);
var offset = (offset > 1 ? 1 : offset);
var offsetX = (caseWidth * offset) - caseWidth;
Expand Down
18 changes: 12 additions & 6 deletions assets/js/src/notificationMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if(typeof(require) !== "undefined") {
var GameConstants = require("./constants");
}

function NotificationMessage(text, textColor, backgroundColor, delayBeforeClosing, animationDelay, fontSize, fontFamily, foreGround) {
function NotificationMessage(text, textColor, backgroundColor, delayBeforeClosing, animationDelay, fontSize, fontFamily, foreGround, disableAnimation) {
this.text = text;
this.textColor = textColor == undefined ? "rgba(255, 255, 255, 0.75)" : textColor;
this.backgroundColor = backgroundColor == undefined ? "rgba(46, 204, 113, 0.5)" : backgroundColor;
Expand All @@ -35,6 +35,7 @@ function NotificationMessage(text, textColor, backgroundColor, delayBeforeClosin
this.init = false;
this.closed = false;
this.closing = false;
this.disableAnimation = disableAnimation == undefined ? false : disableAnimation;
this.closeButton;
}

Expand Down Expand Up @@ -65,16 +66,18 @@ NotificationMessage.prototype.draw = function(game) {
this.fontSize = this.getFontSize(ctx) * 1.25;

var heightText = game.wrapTextLines(ctx, this.text, null, this.fontSize)["height"];

var height = heightText + this.fontSize / 2;
var width = canvas.width;

var offsetY = this.animationTime / this.animationDelay;
var offsetY = 1;

if(!this.closing) {
this.animationTime += offsetTime;
} else {
this.animationTime -= offsetTime;
if(this.disableAnimation) {
this.animationTime = -1;
} else {
this.animationTime -= offsetTime;
}
}

if(this.animationTime < 0) {
Expand All @@ -83,7 +86,10 @@ NotificationMessage.prototype.draw = function(game) {
}

if(!this.closed) {
var offsetY = this.animationTime / this.animationDelay;
if(!this.disableAnimation) {
offsetY = this.animationTime / this.animationDelay;
}

var y = canvas.height - (height * (offsetY <= 1 ? offsetY : 1));

ctx.fillStyle = this.backgroundColor;
Expand Down
2 changes: 1 addition & 1 deletion assets/locales/engine.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down
2 changes: 1 addition & 1 deletion assets/locales/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down
6 changes: 4 additions & 2 deletions assets/locales/menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down Expand Up @@ -52,6 +52,7 @@ i18next.addResourceBundle("fr", "translation", {
"readme": "Fichier Lisez-moi",
"source": "Télécharger la source",
"language": "Langue :",
"enableAnimations": "Activer les animations"
},
"settings": {
"title": "Paramètres de la partie :",
Expand Down Expand Up @@ -198,7 +199,8 @@ i18next.addResourceBundle("en", "translation", {
"infos": "More informations",
"readme": "Readme file",
"source": "Download the source",
"language": "Language:"
"language": "Language:",
"enableAnimations": "Enable the animations"
},
"settings": {
"title": "Game settings:",
Expand Down
10 changes: 8 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
* Copyright (C) 2019 Eliastik (eliastiksofts.com)
* Copyright (C) 2019-2020 Eliastik (eliastiksofts.com)
*
* This file is part of "SnakeIA".
*
Expand Down Expand Up @@ -86,12 +86,18 @@ <h1 class="h3 mb-3 font-weight-normal" data-i18n="menu.selectGame">Sélectionnez
<p class="m-0"><small><a href="http://www.eliastiksofts.com/snakeia" target="_blank" data-i18n="menu.infos">Plus d'infos</a><a href="README.md" target="_blank" data-i18n="menu.readme">Fichier Lisez-moi</a><a href="http://www.eliastiksofts.com/snakeia/downloads" target="_blank" data-i18n="menu.source">Télécharger la source</a></small></p>
<div class="language">
<hr />
<div class="form-group row">
<div class="mb-1 row">
<label for="languageSelect" class="col-sm-4 col-form-label" data-i18n="menu.language">Langue :</label>
<div class="col-sm-8">
<select id="languageSelect" class="form-control" rows="10" disabled></select>
</div>
</div>
<div class="row justify-content-center">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="enableAnimations" checked>
<label class="custom-control-label" for="enableAnimations" data-i18n="menu.enableAnimations">Activer les animations</label>
</div>
</div>
</div>
</div>
<div id="settings">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snakeia",
"version": "1.4.2",
"version": "1.5",
"description": "A Snake version with an artificial intelligence. This version has many game modes. You can play against the AI, or let it play alone. A Battle Royale mode is also available, this mode sees between 2 and 100 AI fight! Many settings are available to vary the games. A Levels mode (for the player and the AI) is also available, it's a series of level with a particular goal to achieve (get a minimum score, get a score in time, …). Downloadable levels are available.",
"main": "node-index.js",
"scripts": {
Expand Down
Loading

0 comments on commit 111115b

Please sign in to comment.