Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge 4,294,967,295 - make your're are game

Name: Anonymous 2020-08-14 22:31

Wouldn't it be nice to have some code posted here for a change? Any humble stupid code.
This challenge is about making a game and finishing it. You can use any shitty language and write the simplest game possible, the only challenge is to FINISH it. That means that the game is playable and somewhat enjoyable.

Deadline: 2020-08-22T00:00:00Z Do what you can, a Rock paper scissors simulator is fine. Snake, Pacman, whatever, just finish it! Size limit is the max post length, but you can use any external libraries you want.

Name: Anonymous 2020-08-14 22:42

Here's Lights Out in JavaScript
https://en.wikipedia.org/wiki/Lights_Out_(game)

<!DOCTYPE html>
<html>
<head>
<title>Lights Out Game</title>
<style>
table#board { border: 1px solid black; }
table#board td {
width:25px;
height:25px;
border: 1px solid black;
}
td.on { background-color: darkorange; }
</style>
</head>
<body>
<table id="board"></table>
<p id="msg"></p>
<script>
var boardState = new Array(25);
for (var i = 0; i < boardState.length; i++) boardState[i] = false;
function generateTable() {
var table = document.getElementById('board');
for (var i = 0; i < 5; i++) {
var row = table.insertRow(i);
for (var j = 0; j < 5; j++) {
var td = document.createElement('td');
td.setAttribute('id', `${5 * i + j}`);
td.addEventListener('click', updateBoard);
row.appendChild(td);
}
}
}
function updateBoard() {
switchCell(this);
var id = parseInt(this.id);
if (id > 4) switchCell(document.getElementById(id - 5));
if (id % 5 != 4) switchCell(document.getElementById(id + 1));
if (id < 20) switchCell(document.getElementById(id + 5));
if (id % 5 != 0) switchCell(document.getElementById(id - 1));
if (boardState.every(Boolean)) document.getElementById('msg').innerHTML = 'You won!';
}
function switchCell(cell) {
var id = cell.id;
boardState[id] = !boardState[id];
cell.classList.toggle('on');
}
generateTable();
</script>
</body>
</html>

Name: Anonymous 2020-08-15 6:04

>>2 Added some improvements:
<!DOCTYPE html>
<html>
<head>

<meta charset="ISO-8859-1">

<title>Lights Out Game</title>
<style>
table#board { max-width:none;overflow: scroll;
border: 1px solid green; }
table#board td {
font-size:1em;
width:1em;
height:1em;
border: 1px solid red;
}
td::before{ content:attr(state); }
</style>
</head>
<body>
<table id="board"></table>
<input type="text" onchange="generateTable(this.value)">Enter Board Size</input>
<script>
const onstate='O';
const offstate=' ';

function generateTable(boardsize) {
var table = document.getElementById('board');
table.innerHTML='';
for (var i = 0; i < boardsize; i++) {
var row = table.insertRow(i);
for (var j = 0; j < boardsize; j++) {
var td = document.createElement('td');
td.setAttribute('row', i);
td.setAttribute('col', j);
td.setAttribute('state',Math.random()>0.5?offstate:onstate);
td.addEventListener('click', updateBoard);
row.appendChild(td);
}
}
}
function updateBoard() {

var row=parseInt(this.getAttribute('row'),10)
var col=parseInt(this.getAttribute('col'),10);
toggle(row,col);
toggle(row+1,col);
toggle(row-1,col);
toggle(row,col+1);
toggle(row,col-1);
if (!document.querySelector(`td[state="${offstate}"`)) alert('Victory');
}
function toggle(row,col){
var cell=document.querySelector(`#board td[row="${row}"][col="${col}"]`);
if(!cell)return;
var state=cell.getAttribute('state');
if(state==onstate){cell.setAttribute('state',offstate)}
else{cell.setAttribute('state',onstate);}
}

generateTable(25);
</script>
</body>
</html>
Edited on 15/08/2020 06:11.

Name: Anonymous 2020-08-15 7:09

A game similar in principle to Lights Out with more states and options, inspired by >>3
<!DOCTYPE html>
<html>
<head>

<meta charset="ISO-8859-1">

<title>Majority Set:set at least 50% of cells to same number </title>
<style>
table#board { max-width:none;overflow: scroll;
border: 1px solid green; }
table#board td {
font-size:1em;
width:1em;
height:1em;
border: 1px solid red;
}
td::before{ content:attr(state); }
#stats::before{content:"Numbers:"}
</style>
</head>
<body>
<table id="board"></table>
<input type="text" id='boardside' value=5 onchange="generateTable(this.value)">Enter Board Side Size(x*x)</input>
<br> <input type="text" id='difficulty' value=10 onchange="setdifficulty(this.value)">Enter Difficulty Level(0-35)</input>
<div id=stats></div>
<script>
var winpercent=50;
var gamewin=0;
function generateTable(boardsize) {
var table = document.getElementById('board');
table.innerHTML='';gamewin=0;
for (var i = 0; i < boardsize; i++) {
var row = table.insertRow(i);
for (var j = 0; j < boardsize; j++) {

var td = document.createElement('td');
td.setAttribute('row', i);
td.setAttribute('col', j);
td.setAttribute('state',((Math.random()*10)|0)%10);
td.addEventListener('click', updateBoard);
row.appendChild(td);
}
}
}
function updateBoard() {if(gamewin==1)return;
var boardmax=document.querySelectorAll('td[state]').length;
var row=parseInt(this.getAttribute('row'),10)
var col=parseInt(this.getAttribute('col'),10);
toggle(row,col);
toggle(row+1,col);
toggle(row-1,col);
toggle(row,col+1);
toggle(row,col-1);
var stat=''
for(var i=0;i<10;i++){
var single=document.querySelectorAll(`td[state="${i}"]`).length;
stat+=i+":"+(single*100/boardmax).toFixed(0)+"% ";
if (single>boardmax*winpercent/100){ alert('Victory:'+winpercent+'%\n'+single+"/"+boardmax);gamewin=1;
generateTable(document.getElementById('boardside').value);return;}
}
document.getElementById('stats').innerHTML=stat;
}
function toggle(row,col){
var cell=document.querySelector(`#board td[row="${row}"][col="${col}"]`);
if(!cell)return;
var state=parseInt(cell.getAttribute('state'),10);
cell.setAttribute('state',(state+1)%10);

}
function setdifficulty(value){winpercent=30+Math.min(Math.abs(value|0)*2,70);
document.title=`Majority Set:set at least ${winpercent}% of cells to same number`;
alert(document.title);
}
generateTable(5);
</script>
</body>
</html>

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List