Browse Source
Merge branch 'main' of https://gitlab2.informatik.hs-fulda.de/fdai7359/gesellschaftsspiele-sammlung
main
Merge branch 'main' of https://gitlab2.informatik.hs-fulda.de/fdai7359/gesellschaftsspiele-sammlung
main
Raphael Elström
2 years ago
10 changed files with 883 additions and 239 deletions
-
13schlangen_und_leitern/HTML.html
-
63schlangen_und_leitern/css/style.css
-
63schlangen_und_leitern/js/Bridge.js
-
377schlangen_und_leitern/js/boardHandling.js
-
21schlangen_und_leitern/js/diceHandling.js
-
141schlangen_und_leitern/js/makeBoard.js
-
123schlangen_und_leitern/js/playerHandling.js
-
114schlangen_und_leitern/tests/boardHandling.test.js
-
14schlangen_und_leitern/tests/diceHandling.test.js
-
129schlangen_und_leitern/tests/playerHandling.test.js
@ -0,0 +1,377 @@ |
|||
//ein Array erstellen, aus dem die Spilebrett gezeichnet werden kann
|
|||
function buildBoard(objectArr,canvasPointArr){ |
|||
// build board array
|
|||
let boardArr = buildBoardArray() |
|||
//leiter Objekte(anfang , ende)
|
|||
let leitern = []; |
|||
//schlange Objekte (anfang , ende)
|
|||
let schlangen = []; |
|||
dynamicObjects(leitern, schlangen) |
|||
// draw board on screen using board array
|
|||
drawBoard(boardArr); |
|||
//draw canvas overlay
|
|||
drawCanavas() |
|||
// cast points to center of board cells
|
|||
canvasPointGen(canvasPointArr); |
|||
// add snakes and ladders objects to object array
|
|||
generateBoardObjects(leitern, schlangen, objectArr) |
|||
//draw board objects
|
|||
drawBoardObjects(canvasPointArr, objectArr) |
|||
} |
|||
|
|||
function buildBoardArray(){ |
|||
let boardArr = []; |
|||
let width = 10; |
|||
let height = 10; |
|||
let count = 100 |
|||
let direction = 0 //0 = gerade reihe (links nach Rechts) ; 1 = ungerade reihe (rechts nach Links)
|
|||
// construct board array
|
|||
for(var y = 0; y < height ; y++){ |
|||
let row = []; |
|||
if(direction == 0){ |
|||
for(var x = 0; x < width; x++ ){ |
|||
row.push(count); |
|||
count--; |
|||
} |
|||
direction = 1; |
|||
} |
|||
else if (direction == 1) { |
|||
for(var x = 0; x < width; x++ ){ |
|||
row.unshift(count); |
|||
count -- |
|||
} |
|||
direction = 0; |
|||
} |
|||
else { |
|||
|
|||
console.log("board Build error, direction corrupted") |
|||
} |
|||
boardArr.push(row) |
|||
} |
|||
return boardArr; |
|||
} |
|||
|
|||
|
|||
|
|||
function dynamicObjects(ladderArr, snakeArr){ |
|||
|
|||
//get the difficulty settings
|
|||
//normal , intermediate, hard
|
|||
//dicide number of snakes and ladders
|
|||
//decide their positions
|
|||
let snakeCount = 5 ; |
|||
let ladderCount = 5; |
|||
//everage number of rows moved
|
|||
let snakeLength = 1.0 |
|||
let ladderLength = 1.0 |
|||
|
|||
for (let i = 0; i < snakeCount; i++){ |
|||
//pick random number between 11 and 100
|
|||
let minStart = Math.ceil(11); |
|||
let maxStart = Math.floor(100); |
|||
let start = Math.floor(Math.random() * (maxStart - minStart + 1) + minStart) |
|||
//create an end point for this number
|
|||
let minEnd = 10 |
|||
let maxEnd = 30 |
|||
|
|||
//pick a seccond number not in the same decimal as the first number
|
|||
let end = start - (Math.floor(Math.random() * (maxEnd - minEnd + 1) + minEnd))*snakeLength |
|||
|
|||
//check if its below 1
|
|||
if(end <=0){ |
|||
end = 1 |
|||
} |
|||
//add these as an [] to corisponding array
|
|||
snakeArr.push([start,end]) |
|||
} |
|||
for (let i = 0; i < ladderCount; i++){ |
|||
//pick random number between 1 and 90
|
|||
let minStart = Math.ceil(1); |
|||
let maxStart = Math.floor(90); |
|||
let start = Math.floor(Math.random() * (maxStart - minStart + 1) + minStart) |
|||
//create an end point for this number
|
|||
let minEnd = 10 |
|||
let maxEnd = 30 |
|||
|
|||
//pick a seccond number not in the same decimal as the first number
|
|||
let end = start + (Math.floor(Math.random() * (maxEnd - minEnd + 1) + minEnd))*ladderLength |
|||
|
|||
//check if its below 1
|
|||
if(end >=100){ |
|||
end = 99 |
|||
} |
|||
//add these as an [] to corisponding array
|
|||
ladderArr.push([start,end]) |
|||
} |
|||
console.log(snakeArr) |
|||
console.log(ladderArr) |
|||
|
|||
|
|||
|
|||
/////forbid
|
|||
//ladders at top
|
|||
//snakes on bottom
|
|||
//6 snake starts next to each other
|
|||
//neither leading to same level (not in the same decimal)
|
|||
//cannot have two starts in one spot
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
function drawBoard(arr){ |
|||
//Tabele Element auswählen
|
|||
let tbl = document.getElementById("board"); |
|||
//neue Reihen mit schleife einfugen
|
|||
for(let y = 0; y < arr.length; y++){ |
|||
let myRow = document.createElement("tr"); |
|||
myRow.id = "row" + y; |
|||
tbl.appendChild(myRow); |
|||
let row = document.getElementById("row" + y ); |
|||
// neue zellen für jede Reihe anknopfen
|
|||
for(let x = 0; x < arr[y].length; x++){ |
|||
|
|||
let cell = document.createElement("td"); |
|||
cell.id = "cell" + arr[y][x]; |
|||
row.appendChild(cell); |
|||
cell.innerHTML = (arr[y][x]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//spielbrett objekt Struktur
|
|||
function boardObject(){ |
|||
|
|||
this.type; |
|||
this.start; |
|||
this.end; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
//fullen des Objekts array
|
|||
function generateBoardObjects (leitern, schlangen, objectArray){ |
|||
|
|||
|
|||
for(let i = 0; i < leitern.length; i++){ |
|||
let leiter = new boardObject; |
|||
leiter.type = "l"; |
|||
leiter.start = leitern[i][0]; |
|||
leiter.end = leitern[i][1]; |
|||
objectArray.push(leiter); |
|||
} |
|||
|
|||
for(let i = 0; i < schlangen.length; i++){ |
|||
let schlange = new boardObject; |
|||
schlange.type = "s"; |
|||
schlange.start = schlangen[i][0]; |
|||
schlange.end = schlangen[i][1]; |
|||
objectArray.push(schlange); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
//make a canvas the same size as the playbaord
|
|||
function drawCanavas(){ |
|||
var ctx = document.getElementById("canvas"); |
|||
var board = document.getElementById("board"); |
|||
//get the tables measurements
|
|||
tableMes = board.getBoundingClientRect() |
|||
tableWidth = tableMes.width; |
|||
tableHight = tableMes.height; |
|||
console.log(tableHight, tableWidth) |
|||
//set canavas to table size
|
|||
ctx.height = tableHight |
|||
ctx.width = tableHight |
|||
} |
|||
|
|||
//canvas point objects
|
|||
function canvasPoint () { |
|||
this.cell |
|||
this.x |
|||
this.y |
|||
} |
|||
|
|||
function canvasPointGen(canvasPointArr){ |
|||
|
|||
//get canvas size
|
|||
var canvas = document.getElementById("canvas"); |
|||
//get induvidual cell sizes
|
|||
canvasWidth = canvas.width |
|||
cellSize = canvas.width/10 |
|||
|
|||
halfCell = cellSize/2 |
|||
//starting position for both axises
|
|||
yTracker = halfCell |
|||
//tracker for cell count
|
|||
let count = 100 |
|||
|
|||
//flip to account for direction change
|
|||
let direction = true // 0 is left to right, 1 is right to left
|
|||
|
|||
//for each cell create a point at its center
|
|||
for(let y = 0; y < 10; y++){ |
|||
|
|||
if (direction == true){ |
|||
var xTracker = halfCell |
|||
|
|||
for(let x = 0; x < 10; x++ ){ |
|||
//create new cell point obj
|
|||
let newPoint = new canvasPoint() |
|||
//set new objects variables
|
|||
newPoint.cell = count |
|||
newPoint.x = xTracker |
|||
newPoint.y = yTracker |
|||
console.log("new point"+ newPoint.cell, newPoint.x, newPoint.y) |
|||
canvasPointArr.push(newPoint) |
|||
//advance x and count
|
|||
xTracker += cellSize |
|||
//toggle direction
|
|||
count-- |
|||
} |
|||
} |
|||
else if (direction == false){ |
|||
var xTracker = (canvasWidth - halfCell) |
|||
for(let x = 10; x > 0; x--){ |
|||
//create new cell point obj
|
|||
let newPoint = new canvasPoint() |
|||
//set new objects variables
|
|||
newPoint.cell = count |
|||
newPoint.x = xTracker |
|||
newPoint.y = yTracker |
|||
console.log("new point"+ newPoint.cell, newPoint.x, newPoint.y) |
|||
canvasPointArr.push(newPoint) |
|||
//advance x and count
|
|||
xTracker -= cellSize |
|||
//toggle direction
|
|||
count-- |
|||
} |
|||
} |
|||
|
|||
yTracker += cellSize |
|||
if (direction == true){ |
|||
direction = false |
|||
} |
|||
else if (direction == false){ |
|||
direction = true |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
//function that draws a line using x,y cooridinates of two points
|
|||
function drawLine(type, startPosX, startPosY, endPosX, endPosY){ |
|||
|
|||
var c = document.getElementById("canvas"); |
|||
var ctx = c.getContext("2d"); |
|||
ctx.beginPath(); |
|||
ctx.moveTo(startPosX, startPosY); |
|||
ctx.lineTo(endPosX, endPosY); |
|||
ctx.stroke(); |
|||
ctx.lineWidth = 10; |
|||
switch (type) { |
|||
case "l": |
|||
ctx.strokeStyle = '#0FD71D'; |
|||
break; |
|||
|
|||
case "s": |
|||
ctx.strokeStyle = '#E21317'; |
|||
break; |
|||
default: |
|||
} |
|||
ctx.strokeStyle; |
|||
|
|||
} |
|||
|
|||
function drawBoardObjects(canvasPointArr, objectArray){ |
|||
//loop through all object in the object array
|
|||
for(let i = 0; i < objectArray.length; i++){ |
|||
|
|||
let startCell = objectArray[i].start |
|||
let endCell = objectArray[i].end |
|||
|
|||
let startPointX; |
|||
let startPointY; |
|||
let endPointX; |
|||
let endPointY; |
|||
|
|||
//find cell points on canvas
|
|||
for(let j = 0; j < canvasPointArr.length; j++){ |
|||
|
|||
|
|||
if(canvasPointArr[j].cell == startCell){ |
|||
startPointX = canvasPointArr[j].x; |
|||
startPointY =canvasPointArr[j].y |
|||
console.log("start found") |
|||
} |
|||
|
|||
else if(canvasPointArr[j].cell == endCell){ |
|||
endPointX = canvasPointArr[j].x; |
|||
endPointY =canvasPointArr[j].y |
|||
|
|||
console.log(endPointX, endPointX) |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
drawLine(objectArray[i].type,startPointX, startPointY, endPointX, endPointY) |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
function continueGame (){ |
|||
|
|||
changeElement("continue", "none") |
|||
changeElement("replay", "none") |
|||
changeElement("würfelBereich", "grid") |
|||
|
|||
} |
|||
|
|||
function hideStartMenu(){ |
|||
//playerselect versctecken
|
|||
changeElement("2Player", "none") |
|||
changeElement("3Player", "none") |
|||
changeElement("4Player", "none") |
|||
changeElement("isUp", "block") |
|||
|
|||
// Wufelbereich zeigen.
|
|||
changeElement("würfelBereich", "grid") |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
function changeElement(id, style){ |
|||
|
|||
document.getElementById(id).style.display = style; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
module.exports = { |
|||
buildBoardArray, |
|||
generateBoardObjects, |
|||
boardObject, |
|||
dynamicObjects |
|||
} |
@ -1,141 +0,0 @@ |
|||
//ein Array erstellen, aus dem die Spilebrett gezeichnet werden kann
|
|||
function buildBoard(){ |
|||
|
|||
let boardArr = []; |
|||
let width = 10; |
|||
let height = 10; |
|||
let count = 100 |
|||
let direction = 0 //0 = gerade reihe (links nach Rechts) ; 1 = ungerade reihe (rechts nach Links)
|
|||
|
|||
for(var y = 0; y < height ; y++){ |
|||
let row = []; |
|||
if(direction == 0){ |
|||
for(var x = 0; x < width; x++ ){ |
|||
row.push(count); |
|||
count--; |
|||
} |
|||
direction = 1; |
|||
} |
|||
else if (direction == 1) { |
|||
for(var x = 0; x < width; x++ ){ |
|||
row.unshift(count); |
|||
count -- |
|||
} |
|||
direction = 0; |
|||
} |
|||
else { |
|||
|
|||
console.log("board Build error, direction corrupted") |
|||
} |
|||
boardArr.push(row) |
|||
} |
|||
console.log(boardArr) |
|||
return boardArr; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
function drawBoard(arr){ |
|||
//Tabele Element auswählen
|
|||
let tbl = document.getElementById("board"); |
|||
//neue Reihen mit schleife einfugen
|
|||
for(let y = 0; y < arr.length; y++){ |
|||
let myRow = document.createElement("tr"); |
|||
myRow.id = "row" + y; |
|||
tbl.appendChild(myRow); |
|||
let row = document.getElementById("row" + y ); |
|||
// neue zellen für jede Reihe anknopfen
|
|||
for(let x = 0; x < arr[y].length; x++){ |
|||
|
|||
let cell = document.createElement("td"); |
|||
cell.id = "cell" + arr[y][x]; |
|||
row.appendChild(cell); |
|||
cell.innerHTML = (arr[y][x]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
//spielbrett objekt Struktur
|
|||
function boardObject(){ |
|||
|
|||
this.type; |
|||
this.start; |
|||
this.end; |
|||
} |
|||
|
|||
|
|||
//leiter Objekte(anfang , ende)
|
|||
let leitern = [[7, 33],[24, 44],[31, 55],[60, 77]]; |
|||
//schlange Objekte (anfang , ende)
|
|||
let schlangen = [[99, 56], [86, 64],[60, 28],[18,1]]; |
|||
|
|||
|
|||
|
|||
//fullen des Objekts array
|
|||
function generateBoardObjects (leitern, schlangen, objectArray){ |
|||
|
|||
|
|||
for(let i = 0; i < leitern.length; i++){ |
|||
let leiter = new boardObject; |
|||
leiter.type = "l"; |
|||
leiter.start = leitern[i][0]; |
|||
leiter.end = leitern[i][1]; |
|||
objectArray.push(leiter); |
|||
} |
|||
|
|||
for(let i = 0; i < schlangen.length; i++){ |
|||
let schlange = new boardObject; |
|||
schlange.type = "s"; |
|||
schlange.start = schlangen[i][0]; |
|||
schlange.end = schlangen[i][1]; |
|||
objectArray.push(schlange); |
|||
} |
|||
} |
|||
//function that draws a line using x,y cooridinates of two points
|
|||
function drawLine(type, count, ax,ay, bx, by){ |
|||
if(ay>by) |
|||
{ |
|||
bx=ax+bx; |
|||
ax=bx-ax; |
|||
bx=bx-ax; |
|||
by=ay+by; |
|||
ay=by-ay; |
|||
by=by-ay; |
|||
} |
|||
var calc=Math.atan((ay-by)/(bx-ax)); |
|||
calc=calc*180/Math.PI; |
|||
var length=Math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by)); |
|||
console.log(length) |
|||
|
|||
|
|||
let newLine = document.createElement("div") |
|||
newLine.id = type + count; |
|||
|
|||
let style = "height:" + length + "px;width:5px;background-color:black;position:absolute;top:" + (ay) + "px;left:" + (ax) + "px;transform:rotate(" + calc + "deg);-ms-transform:rotate(" + calc + "deg);transform-origin:0% 0%;-moz-transform:rotate(" + calc + "deg);-moz-transform-origin:0% 0%;-webkit-transform:rotate(" + calc + "deg);-webkit-transform-origin:0% 0%;-o-transform:rotate(" + calc + "deg);-o-transform-origin:0% 0%;" |
|||
|
|||
newLine.style.cssText = style; |
|||
document.getElementById("board").appendChild(newLine); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,114 @@ |
|||
//Importieren der FUnktionen
|
|||
const { |
|||
buildBoardArray, |
|||
generateBoardObjects, |
|||
boardObject, |
|||
dynamicObjects |
|||
} = require('../js/boardHandling'); |
|||
|
|||
|
|||
let boardEx =[ |
|||
[100, 99, 98, 97, 96, 95, 94, 93, 92, 91], |
|||
[81, 82, 83, 84, 85, 86, 87, 88, 89, 90], |
|||
[80, 79, 78, 77, 76, 75, 74, 73, 72, 71], |
|||
[61, 62, 63, 64, 65, 66, 67, 68, 69, 70], |
|||
[60, 59, 58, 57, 56, 55, 54, 53, 52, 51], |
|||
[41, 42, 43, 44, 45, 46, 47, 48, 49, 50], |
|||
[40, 39, 38, 37, 36, 35, 34, 33, 32, 31], |
|||
[21, 22, 23, 24, 25, 26, 27, 28, 29, 30], |
|||
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11], |
|||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
|||
]; |
|||
|
|||
//leiter Objekte
|
|||
let leitern = [[7, 33],[24, 44],[31, 55],[60, 77]]; |
|||
//schlange Objekte
|
|||
let schlangen = [[99, 56], [86, 64],[60, 28],[18,1]]; |
|||
|
|||
|
|||
|
|||
describe('tests ob das boardArray rigtig aufgebaut würde', () => { |
|||
|
|||
|
|||
it('past zum beispiel array', ()=>{ |
|||
|
|||
expect(buildBoardArray()).toEqual(boardEx); |
|||
|
|||
}); |
|||
|
|||
}) |
|||
|
|||
describe('testen ob alle board objekte korrekt initialisiert wird', () => { |
|||
|
|||
|
|||
it('testen, ob die Anzahl der Elemente im Array korrekt ist ', ()=>{ |
|||
let objectArr = [] ; |
|||
generateBoardObjects(leitern, schlangen, objectArr); |
|||
expect(objectArr.length).toBe((leitern.length + schlangen.length)); |
|||
}); |
|||
|
|||
|
|||
it('prüfen, ob jedem Objekt der richtige Typ zugeordnet ist', ()=>{ |
|||
let obArr = [] ; |
|||
generateBoardObjects(leitern, schlangen, obArr); |
|||
|
|||
for(let i = 0; i < obArr.length; i++){ |
|||
//prüfen leitern
|
|||
if(obArr[i].start < obArr[i].end) |
|||
expect(obArr[i].type).toBe("l"); |
|||
//prüfen schlange
|
|||
else { |
|||
expect(obArr[i].type).toBe("s"); |
|||
} |
|||
} |
|||
}); |
|||
|
|||
}) |
|||
|
|||
|
|||
|
|||
|
|||
describe('prüfen, ob dynamische Objekte korrekt erstellt wurden', () => { |
|||
|
|||
|
|||
it('Testen, ob genügend Objekte gemacht wurden', ()=>{ |
|||
|
|||
let leitern = []; |
|||
let schlangen = []; |
|||
dynamicObjects(leitern,schlangen) |
|||
expect(leitern.length).toBe(5); |
|||
expect(schlangen.length).toBe(5); |
|||
|
|||
}); |
|||
|
|||
it('Prüfun, ob alle Schlangenobjekte niedriger enden als sie beginnenn', ()=>{ |
|||
|
|||
|
|||
let leitern = []; |
|||
let schlangen = []; |
|||
dynamicObjects(leitern, schlangen) |
|||
for(let i = 0; i < schlangen.length; i++){ |
|||
|
|||
expect(schlangen[i][1]).toBeLessThan(schlangen[i][0]); |
|||
} |
|||
|
|||
|
|||
}); |
|||
|
|||
it('Prüfen, ob alle Leiterobjekte höher enden als sie beginnen', ()=>{ |
|||
|
|||
|
|||
let leitern = []; |
|||
let schlangen = []; |
|||
dynamicObjects(leitern, schlangen) |
|||
for(let i = 0; i < leitern.length; i++){ |
|||
|
|||
expect(leitern[i][0]).toBeLessThan(leitern[i][1]); |
|||
} |
|||
|
|||
|
|||
}); |
|||
|
|||
}) |
|||
|
|||
|
@ -0,0 +1,14 @@ |
|||
const generateNumber = require('../js/diceHandling'); |
|||
|
|||
describe('würfel testen', ()=>{ |
|||
|
|||
it('testen ob es von 100 Versuche immer eine zahl zwischen 1 und 6 zurück gibt',()=>{ |
|||
for(let i = 0; i <= 100; i++) |
|||
{ |
|||
expect(generateNumber()).toBeGreaterThanOrEqual(1); |
|||
expect(generateNumber()).toBeLessThan(7); |
|||
} |
|||
}) |
|||
|
|||
|
|||
}) |
@ -0,0 +1,129 @@ |
|||
//Importieren der FUnktionen
|
|||
const { |
|||
PlayerBuilder, |
|||
buildPlayerArray, |
|||
movePlayer, |
|||
over100, |
|||
landedOn, |
|||
resetNewOld |
|||
} = require('../js/playerHandling'); |
|||
|
|||
let player = {"position": 1, "newPosition": 1, "won": false}; |
|||
//example player array
|
|||
let playerArr2 = [ |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false} |
|||
|
|||
] |
|||
let playerArr3 = [ |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
|
|||
] |
|||
let playerArr4 = [ |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false}, |
|||
{"position": 1, "newPosition": 1, "won": false} |
|||
|
|||
] |
|||
let rolls =[1,2,3,4,5,6]; |
|||
|
|||
|
|||
let ladderArr = ( |
|||
{start: 7, end: 33}, |
|||
{start: 24, end: 44}, |
|||
{start: 31, end: 55}, |
|||
{start: 60, end: 77} |
|||
) |
|||
let snakeArr = ( |
|||
{start: 99, end: 56}, |
|||
{start: 86, end: 64}, |
|||
{start: 60, end: 28}, |
|||
{start: 18, end: 1} |
|||
) |
|||
|
|||
//Eine Test Gruppe, mit mehreren Tests
|
|||
describe('Testen, ob für jede mögliche Spieleranzahl die richtige Anzahl von Spielerobjekten erzeugt wird', () => { |
|||
|
|||
it('testen ob 2 Spieler Objekte generiert wird ', ()=>{ |
|||
expect(buildPlayerArray(2)).toEqual(playerArr2); |
|||
}); |
|||
it('testen ob 3 Spieler Objekte generiert wird ', ()=>{ |
|||
expect(buildPlayerArray(3)).toEqual(playerArr3); |
|||
}); |
|||
it('testen ob 4 Spieler Objekte generiert wird ', ()=>{ |
|||
expect(buildPlayerArray(4)).toEqual(playerArr4); |
|||
}); |
|||
}) |
|||
|
|||
describe('Testen ob das movePlayer funkction:', () => { |
|||
|
|||
it('die Position bei jeder möglichen Rolle korrekt ändert', ()=>{ |
|||
for(let i = 0; i <rolls.length; i++) |
|||
{ |
|||
|
|||
movePlayer(player, rolls[i]) |
|||
expect(player).toEqual({"position": 1, "newPosition": 1 +rolls[i], "won": false}); |
|||
} |
|||
}); |
|||
}) |
|||
|
|||
|
|||
|
|||
describe('Testen, ob der Spieler in einer Position über 100 sein kann', () => { |
|||
|
|||
|
|||
it('101 bis 130 wieder auf 100 setzen', ()=>{ |
|||
for(let i = 1; i <30; i++){ |
|||
let player = {"position": 1, "newPosition": 100, "won": false}; |
|||
over100(player); |
|||
expect(player).toEqual({"position": 1, "newPosition": 100, "won": false}); |
|||
} |
|||
|
|||
}); |
|||
|
|||
}) |
|||
|
|||
|
|||
describe('tests testen', () => { |
|||
|
|||
|
|||
it('testen alle leitern', ()=>{ |
|||
for(let i = 0; i <= ladderArr.length; i++) |
|||
{ |
|||
landedOn(player, ladderArr[i]); |
|||
expect(player).toBe({"position": 1, "newPosition": ladderArr[i].end, "won": false}); |
|||
} |
|||
}); |
|||
it('testen alle schlange', ()=>{ |
|||
|
|||
for(let i = 0; i <= snakeArr.length; i++) |
|||
{ |
|||
landedOn(player, snakeArr[i]); |
|||
expect(player).toBe({"position": 1, "newPosition": ladderArr[i].end, "won": false}); |
|||
} |
|||
}); |
|||
|
|||
}) |
|||
|
|||
|
|||
describe('testen, ob die neue Position die aktuelle Position ersetzt ', () => { |
|||
|
|||
|
|||
it('mit einer Zufallszahl von 1 bis 100 zwanzigmal', ()=>{ |
|||
for(let i = 0; i <= 20; i++) |
|||
{ |
|||
min = Math.ceil(1); |
|||
max = Math.floor(100); |
|||
let position = Math.floor(Math.random() * (max - min + 1) + min) |
|||
|
|||
let player = {"position": 1, "newPosition": position, "won": false} |
|||
resetNewOld(player); |
|||
expect(player).toEqual({"position": position, "newPosition": 0, "won": false}); |
|||
} |
|||
|
|||
}); |
|||
|
|||
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue