diff --git a/index.html b/index.html
index c90eee5..f62a98e 100644
--- a/index.html
+++ b/index.html
@@ -8,7 +8,7 @@
-
+
Document
diff --git a/js/main.js b/js/main.js
deleted file mode 100644
index 3b58636..0000000
--- a/js/main.js
+++ /dev/null
@@ -1,87 +0,0 @@
-//Copyright © space tarders 2023
-let token = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiQU5OTk5VTEFYMTIyNSIsInZlcnNpb24iOiJ2Mi4xLjEiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0wNCIsImlhdCI6MTcwMDIyNDU5MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.r05mWtD5FjC4s6Td-ycmHdzL7C2s75lz3q7OBmWeCqUUZ1ejPsRGQRWJDPmIh1kAqO4D9FFs3GCTPZUn1KsnQ-xmDvsIi_mqC1gJV-Q0irI7gwfsGXbfLaVCXo-Q98C_QWRh-O_xkrbhJkCcvnwdEhZm7FnZ3PL4XXKrG0XNa98JrnmG0qlz0cv8V9Q0sSIwXZbvA9BrhuV8PK7_YzPc6LZuNqgPeKiX_B-tSIHHl6Sr1EzuydnczmuS-xKQnbhmcqnpaCXzQmJr7tA8KLgu70KqpPCvA8AI6PLmBlvPWtZ20RdzezqlBh6S9SrBzQ9R0zr_9RyJxq28ws2jnHpVPw";
-let offset = {
- x: 10,
- y: 10
-};
-
-function initGame() {
- const settings = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/register',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Accept: 'application/json'
- },
- processData: false,
- data: '{\n "faction": "COSMIC",\n "symbol": "Daniel123",\n "email": ""\n}'
- };
-
- $.ajax(settings).done(function (response) {
- console.log(response);
- });
-}
-
-function getAgent() {
- const settings = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/my/agent',
- method: 'GET',
- headers: {
- Accept: 'application/json',
- Authorization:token
- }
- };
- $.ajax(settings).done(function (reponse) {
- $('.main-window').prepend(`
-
- ${reponse.data.accountId}
- ${reponse.data.symbol}
- ${reponse.data.headquarters}
- ${reponse.data.credits}
- ${reponse.data.startingFaction}
- ${reponse.data.shipCount}
-
- `);
- let metaSystem = reponse.data.headquarters.split("-");
- getSystem(metaSystem[0] + "-" + metaSystem[1]);
- });
-}
-
-function getWayPoint(wayPoint) {
- const settings = {
- async: true,
- crossDomain: true,
- url: `https://api.spacetraders.io/v2/systems/systemSymbol/waypoints/waypointSymbol`,
- method: 'GET',
- headers: {
- Accept: 'application/json'
- }
- };
-
- $.ajax(settings).done(function (response) {
- console.log(response);
- });
-};
-
-function getSystem(system) {
- const settings = {
- async: true,
- crossDomain: true,
- url: `https://api.spacetraders.io/v2/systems/${system}`,
- method: 'GET',
- headers: {
- Accept: 'application/json'
- }
- };
-
- $.ajax(settings).done(function (response) {
- drawSystem(response.data.waypoints);
- });
-}
-
-
-getAgent();
diff --git a/js/test.js b/js/test.js
index 4c6ad64..e9b4d4a 100644
--- a/js/test.js
+++ b/js/test.js
@@ -1,7 +1,26 @@
//Copyright © space tarders 2023
+
'use strict'
+
+const canvas = document.getElementById("canvas");
+let w = canvas.width = canvas.offsetWidth;
+let h = canvas.height = canvas.offsetHeight;
+const ctx = canvas.getContext("2d");
+let planets = [];
+let ships=[];
+
//lister vaisseau
-const token="Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiSEFNRE9VTEFITCIsInZlcnNpb24iOiJ2Mi4xLjEiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0wNCIsImlhdCI6MTcwMDIyNDI3MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.LNKY3vcOZIjiHUj-Z9z8kgNDqpQgB63u_6ceibfHQX-U1ox2bRjQqlSMnSjvUsXkx1G8qIDQUP9Sl-uuiHNzdtq1TmQD4x6c0nIEPNrP_OUbQSP98JZ2-xrp6h4TfXnK_o8OPqhpbRIH9iklnSrXswUZg6H2Cy78yS4sVaftiq0nBH5TLK4k5sEe5MVvhLiAuPAlNhYHUZdXP-T1y6PmmIim5d-0fwetkuC4Q2PLZp5Qg3b_2Bfy2GIUj4nI9m1e6ukaeuIF6VMYrsDUiBXD7jGrdFj2J2ZBrXKJQdQRfMKcUNpMqKdwM606S8VFDo6QHUxB5Rgi9GHFWGEKEMyBCQ"
+const token="Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiREFOSUVMIiwidmVyc2lvbiI6InYyLjEuNCIsInJlc2V0X2RhdGUiOiIyMDIzLTEyLTAyIiwiaWF0IjoxNzAyMDM4NTcwLCJzdWIiOiJhZ2VudC10b2tlbiJ9.cSeOMFA6by3J3mElGL1xKg0p--C7Dcir6VARIs27QmHqTy2hM-pkJosADSLuo-bXHhXSESLlCcmSzS3BIa4T4v6HI0PH4QFpVNjHBSg7-lt1Hjhm4KkRUnmXdBEAeAXq18cbd6xScfRq0rpRNFzJZg5dRit3fjBZ3MSdmlRVroUs4hJaeSu0HLxD3GGRxXRFtvvHgMuFu6vqE1rq0PxTYQksuhu-GGpheCcIuQHNNIGnd0E2z-xzRAJYrRBjdctMDMv_u-RUeM4A6OwAFEczMYM3yDkZJP4qpVKAtriRUxJVkRsqHFLfEzWx7VikwLijN72gbhVzoIJzKh75-1kcyg"
+// Fonction pour obtenir la position de la souris par rapport au centre du canvas
+function getMousePosition(e, canvas) {
+ let rect = canvas.offset();
+ return {
+ x: e.clientX - rect.left - canvas.width() / 2,
+ y: e.clientY - rect.top - canvas.height() / 2
+ };
+}
+
+
const ListMyShips = {
async: true,
crossDomain: true,
@@ -13,31 +32,118 @@ const ListMyShips = {
},
};
$.ajax(ListMyShips).done(function (response) {
- console.log(response);
+ ships.push(response);
+ });
+
+//recuperer le systeme ou on est
+function getShipPosition(){
+ const settings = {
+ async: true,
+ crossDomain: true,
+ url: 'https://api.spacetraders.io/v2/my/ships/DANIEL-1/nav',
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ Authorization:token
+ }
+ };
+
+ $.ajax(settings).done(function (response) {
+ console.log(response);
+ console.log(planets);
+
+ planets.forEach(planet => {
+ if(planet.symbol == response.data.waypointSymbol)
+ {
+ let xPlanet=planet.x
+ let yPlanet=planet.y
+ drawShip(xPlanet,yPlanet)
+ }
+ })
});
+}
+
+
+function drawShip(x,y){
+ ctx.fillStyle = "rgb(3,67,210)";
+ ctx.fillRect(x / 3 + w / 2, y / 3 + h / 2, 10, 10);
+}
+function getListWaypoint(system, page) {
+ return new Promise((resolve, reject) => {
+ const settings = {
+ async: true,
+ crossDomain: true,
+ url: `https://api.spacetraders.io/v2/systems/${system}/waypoints`,
+ method: 'GET',
+ headers: {
+ Accept: 'application/json'
+ },
+ data: {
+ limit: 20,
+ page: page
+ }
+ };
+ $.ajax(settings).done(function (response) {
+ const waypoints = response.data;
+ waypoints.forEach(waypoint => {
+ ctx.fillStyle = "rgb(0,0,0)";
+ ctx.fillRect(waypoint.x / 3 + w / 2, waypoint.y / 3 + h / 2, 6, 6);
+ });
-const listWaypoints = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/systems/X1-GY76/waypoints',
- method: 'GET',
- headers: {
- Accept: 'application/json',
- Authorization: token
+ resolve(waypoints);
+ }).fail(function (error) {
+ reject(error);
+ });
+ });
+}
+
+function getAllWaypoints(system) {
+ const promises = [];
+
+ for (let i = 1; i < 5; i++) {
+ promises.push(getListWaypoint(system, i));
}
-};
-$.ajax(listWaypoints).done(function (response) {
- console.log(response);
-});
+ return Promise.all(promises);
+}
-
+function getSystem() {
+ const settings = {
+ async: true,
+ crossDomain: true,
+ url: 'https://api.spacetraders.io/v2/my/agent',
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ Authorization: token
+ }
+ };
+
+ $.ajax(settings).done(function (reponse) {
+ let metaSystem = reponse.data.headquarters.split("-");
+ getAllWaypoints(metaSystem[0] + "-" + metaSystem[1])
+ .then(waypointsArray => {
+ planets = [].concat(...waypointsArray);
+ console.log('Planets:', planets);
+ getShipPosition();
+ })
+ .catch(error => {
+ console.error(error);
+ });
+ });
+}
+
+getSystem();
+
+
+
+function travelToPlanet(planet) {
const travelShip = {
async: true,
crossDomain: true,
- url: 'https://api.spacetraders.io/v2/my/ships/shipSymbol/navigate',
+ url: `https://api.spacetraders.io/v2/my/ships/shipSymbol/navigate`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -45,9 +151,58 @@ $.ajax(listWaypoints).done(function (response) {
Authorization: token
},
processData: false,
- data: '{\n "waypointSymbol":'+ waypoint+'\n}'
+ data: JSON.stringify({
+ destination: planet.symbol
+ })
};
-
+
$.ajax(travelShip).done(function (response) {
+ console.log(`Voyage vers ${planet.name} en cours...`);
console.log(response);
- });
\ No newline at end of file
+ }).fail(function (error) {
+ console.error(`Erreur lors du voyage vers ${planet.name}`);
+ console.error(error);
+ });
+}
+
+// Événement de clic sur le canvas
+$('#canvas').on('click', function (e) {
+ const mousePosition = getMousePosition(e, $('#canvas'));
+ checkClickedPlanet(mousePosition);
+});
+
+ // Fonction pour vérifier si une planète a été cliquée
+function checkClickedPlanet(mousePosition) {
+ console.log('Clicked position:', mousePosition.x, mousePosition.y);
+
+ planets.forEach(waypoint => {
+ console.log('Planet position:', waypoint.x / 3 + w / 2, waypoint.y / 3 + h / 2);
+
+ // Vérifier si la position de la souris est à l'intérieur de la zone de la planète
+ if (
+ mousePosition.x >= waypoint.x / 3 + w / 2 &&
+ mousePosition.x <= waypoint.x / 3 + w / 2 + 6 &&
+ mousePosition.y >= waypoint.y / 3 + h / 2 &&
+ mousePosition.y <= waypoint.y / 3 + h / 2 + 6
+ ) {
+ const confirmation = confirm(`Voulez-vous voyager vers ${waypoint.name}?`);
+
+ if (confirmation) {
+ // Vérifier les conditions de voyage
+ if (conditionsVoyageRemplies(waypoint)) {
+ travelToPlanet(waypoint);
+ } else {
+ alert('Vous ne pouvez pas voyager vers cette planète. Conditions non remplies.');
+ }
+ } else {
+ console.log('Voyage annulé.');
+ }
+ }
+ });
+}
+
+function conditionsVoyageRemplies(waypoint) {
+ return 0;
+}
+
+
diff --git a/test.js b/test.js
deleted file mode 100644
index 8cc5aa8..0000000
--- a/test.js
+++ /dev/null
@@ -1,104 +0,0 @@
-//Copyright © space tarders 2023
-
-'use strict'
-
-const canvas = document.getElementById("canvas");
-let w = canvas.width = canvas.offsetWidth;
-let h = canvas.height = canvas.offsetHeight;
-const ctx = canvas.getContext("2d");
-let planets = [];
-
-//lister vaisseau
-const token="Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiREFOSUVMMTIzNCIsInZlcnNpb24iOiJ2Mi4xLjIiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0xOCIsImlhdCI6MTcwMDgzMjc4MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.JIOfLaTzMeV4nrZ4tI8jdwrLyuNiqbMdXvXcNQfr1swHRBoIz39ozF6n33NOA7Zhp6frCXO8lflrDH2BTobOes5e2Q0BqNTj0Xq3MJeCc6QDsywv_doiIenDbf3gY7Aju_gC3z3u0uw0IqLhgxFIurlFgdXhsXX466i71sPrK8PPtGezTqB7_b7umAh3AknAuAaGi5no5VsvhCDJjH_Sb5HNkCYCvkENTm_INY5cprizOXjwYJd_91-b3ChMyJwMKJH9t68_rmDtZrU757sqSpDWE6ugh2auXEQXh3Am-BjBP1W6hlPjrOsxodD4mGYMgX8uYmZMRubIze0eu8FiNA"
-$('#canvas').on('click',function(e){
- console.log(getMousePosition(e, $('#canvas')));
- function getMousePosition(e, canvas) {
- let rect = canvas.offset();
- return {
- x: (e.clientX - rect.left) - canvas.width()/2,
- y: (e.clientY - rect.top) - canvas.height()/2
- };
- }
-})
-
-const ListMyShips = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/my/ships',
- method: 'GET',
- headers: {
- Accept: 'application/json',
- Authorization: token
- },
- };
- $.ajax(ListMyShips).done(function (response) {
- console.log(response);
- });
-
-//recuperer le systeme ou on est
- function getSystem() {
- const settings = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/my/agent',
- method: 'GET',
- headers: {
- Accept: 'application/json',
- Authorization:token
- }
- };
- $.ajax(settings).done(function (reponse) {
- let metaSystem = reponse.data.headquarters.split("-");
- getListWaypoint(metaSystem[0] + "-" + metaSystem[1]);
- });
-}
-getSystem();
-
-//lister les points du systeme
-function getListWaypoint(system) {
- for(let i=1;i<5;i++){
- const settings = {
- async: true,
- crossDomain: true,
- url: `https://api.spacetraders.io/v2/systems/${system}/waypoints`,
- method: 'GET',
- headers: {
- Accept: 'application/json'
- },
- data:{
- limit:20,
- page:i
- }
- };
-
- $.ajax(settings).done(function (response) {
- console.log(response.data)
- response.data.forEach(waypoint => {
- planets.push(waypoint);
- ctx.fillStyle = "rgb(0,0,0)";
- ctx.fillRect(waypoint.x/3 + w/2, waypoint.y/3 + h/2,6,6)
- });
- });
- }
-}
-drawSystem();
-function travel(waypoint)
-{
- const travelShip = {
- async: true,
- crossDomain: true,
- url: 'https://api.spacetraders.io/v2/my/ships/shipSymbol/navigate',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Accept: 'application/json',
- Authorization: token
- },
- processData: false,
- data: `{\n ${waypoint}: "string"\n}`
- };
-
- $.ajax(travelShip).done(function (response) {
- console.log(response);
- });
-}
diff --git a/token.txt b/token.txt
index c622557..201de82 100644
--- a/token.txt
+++ b/token.txt
@@ -1,3 +1,3 @@
lister les vaisseaux de depart
comment on peut les deplacer
-token : eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGlmaWVyIjoiSEFNRE9VTEFITCIsInZlcnNpb24iOiJ2Mi4xLjEiLCJyZXNldF9kYXRlIjoiMjAyMy0xMS0wNCIsImlhdCI6MTcwMDIyNDI3MSwic3ViIjoiYWdlbnQtdG9rZW4ifQ.LNKY3vcOZIjiHUj-Z9z8kgNDqpQgB63u_6ceibfHQ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