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>

Name: Anonymous 2020-08-15 9:53

<script>//a game of pure luck
alert(Math.random()/Math.random()>1.0?"You win!":"You lose.");
</script> Edited on 15/08/2020 09:56.

Name: Anonymous 2020-08-15 10:11

<script>//a game of pure luck with user interaction
var a=Math.random();
var b=Math.random();
var guess=confirm("Is A larger than B?");
alert(((guess &&(a>b))||(!guess &&(a<=b)))
?"You win!\n"+a+" : "+b:"You lose.\n"+a+" : "+b);
</script>

Name: Anonymous 2020-08-15 16:07

>>3,4
Nice, nice, nice.
>>6
Good one, Anon! Congrats for finishing you're are game!
Guessing games are a lot of fun. You still have time left, why don't you try and implement Mastermind?
https://en.wikipedia.org/wiki/Mastermind_(board_game)

Name: Anonymous 2020-08-15 19:22

>>7
I don't like guessing game, its just pure luck.
All guessing games are trash. Click here to randomly win N crystals is feeding the rat-pushing-lever incentive.
Its not fun. The code is a joke.

Name: Anonymous 2020-08-15 20:23

>>8
just pure luck
No. Open your eyes.
In 1977, Donald Knuth demonstrated that the codebreaker can solve the pattern in five moves or fewer, using an algorithm that progressively reduces the number of possible patterns.

Name: Anonymous 2020-08-16 3:11

In case you're not already sweating your ass off during the heatwave to finish that awesome little game you've planned forever, here are a few ideas:
- given a HTML <table> grid and JavaScript like in >>2-4, cloning Minesweeper is a breeze.
- Sokoban
- Red Donkey
- Jezzball
- Nim (less involved, doesn't need graphics)
- ...

Name: Anonymous 2020-08-16 7:02

I want to take part but i am on vacation until 23 august Z. Will there be a follow-up?

Name: Anonymous 2020-08-16 8:25

>>11
Doesn't being on vacation mean you have only free time for making your're are game?? Your SO didn't want you to bring your laptop? Even if you spend your holidays in Africa you can go to a cybercafe (they still have them I'm certain), open Chrome, hit ctrl+shift+j and you have a Javashit IDE. If you're on a desert island with your mobile phone, you can install eruda https://github.com/liriliri/eruda It'll give you the developer tools on your Android Chrome. Or write the code on a piece of paper. Do you think Bill Gates had a personal computer at his disposal when he wrote BASIC for the Altair? That deadline is my birthday, Anon! I don't do things randomly. But alright... if at least some anons prove they're able to finish their're are game instead of turning this place into /pol/, there will be a follow-up and an integer overflow just for you.

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