xxxxxxxxxx
254
let digits = {0:"0️⃣",1:"1️⃣",2:"2️⃣",3:"3️⃣",4:"4️⃣",5:"5️⃣",6:"6️⃣",7:"7️⃣",8:"8️⃣",9:"9️⃣"};
let digits_to_auction;
let auctioned_digits = ['🆓','🆓','🆓','🆓','🆓','🆓']
// let auctioned_digits = ['🆓','🆓','🆓','🆓','🆓','🆓','🆓','🆓','🆓','🆓']
let currentDigitIndex = -1;
let playerTokens = 20;
let playerDigits = [];
let currentBid = 0;
let gameOver = false;
let coin_width=30;
let coin_height = 5;
let button_length=40;
let minus_button,plus_button,go_button;
let numpad=[];
let used_indexes=[]
let select_index_label = ""
let logedin = false;
let first_login = true;
let first_logedin = true;
let logout_btn;
let usernm_ip,passwd_ip,login_btn;
let tokens = {"stack1":5,"stack2":5,"stack3":5,"stack4":5}
let UserName='nagesh'
let Password ='123'
function setup() {
createCanvas(400, 600);
// pixelDensity(1);
textAlign(CENTER,CENTER);
digits_to_auction = shuffle([0,1,2,3,4,5,6,7,8,9]);
}
function draw(){
if(!logedin){
if(first_login){
usernm_ip = createInput('');
passwd_ip = createInput('');
login_btn = createButton('Login');
login_btn.mousePressed(login);
first_login=false;
}
login_page();
}else{
if(first_logedin){
logout_btn = createButton('Logout');
minus_button = createButton('➖');
plus_button = createButton('➕');
for(let i=0;i<auctioned_digits.length;i++){
numpad.push(createButton(i.toString()))
numpad[i].style('font-size', '24px');
numpad[i].style('background-color','#F5F5F5')
numpad[i].mousePressed(pickIndex);
}
go_button = createButton('|||⮐')
minus_button.style('font-size', '24px');
plus_button.style('font-size', '24px');
go_button.style('font-size', '24px');
go_button.style('background-color','green')
minus_button.mousePressed(BidDecrease);
plus_button.mousePressed(BidIncrease);
go_button.mousePressed(go);
logout_btn.mousePressed(logout);
first_logedin=false;
}
after_login();
}
}
function login(){
let username = usernm_ip.value();
let passwd = passwd_ip.value();
if(username == UserName && passwd == Password){
logedin=true;
removeElements();
}
}
function logout(){
logedin=false;
first_login=true;
first_logedin=true;
removeElements();
}
function login_page(){
background(125,125,125);
textSize(15);
text('Username',width/2 - usernm_ip.width/2+70,height/4-20);
usernm_ip.position(width/2 - usernm_ip.width/2,height/4);
text('Password',width/2 - usernm_ip.width/2+70,height/2-20);
passwd_ip.position(width/2 - passwd_ip.width/2,height/2);
login_btn.position(width/2 - login_btn.width/2,3*height/4);
}
function after_login() {
background(255,255,255);
fill('red');
textSize(15);
text(select_index_label,width/2-50,50);
//Display Current Digit
textAlign(CENTER,CENTER);
fill(0);
textSize(30);
text(`Digit for Auction: ${digits[digits_to_auction[digits_to_auction.length-1]]}`,width/2,100);
// Display player tokens
textSize(40);
text("🧑🏽💻",width/4,150);
textSize(20);
text(`Tokens: 💰${playerTokens}`,width/4,200);
let sp = 0;
fill('gold')
for (let t=0; t<playerTokens;t++){
rect(width/2+floor(t/5)*40,200-(t%5)*5,coin_width,coin_height,5);
textSize(5);
text("💵",width/2+floor(t/5)*40+coin_width/2,200-(t%5)*5+coin_height/2)
}
//Display CurrentBid
textSize(20);
fill('black')
text(`Bid : 💰${currentBid}`,width/4,250)
fill('gold')
for (let b=0; b<currentBid;b++){
rect(width/2+floor(b/5)*40,250-(b%5)*5,coin_width,coin_height,5);
textSize(5);
text("💵",width/2+floor(b/5)*40+coin_width/2,250-(b%5)*5+coin_height/2)
}
//Display Digits aquired
textSize(20);
fill('black')
text("DIGITS",width/2,300);
text(`${auctioned_digits.join(" ")}`,width/2,350);
//logout button position
logout_btn.position(width-60,5);
minus_button.position(width/2-button_length/2-5,height-220);
plus_button.position(width/2+button_length/2+5,height-220);
for(let i=0;i<auctioned_digits.length;i++){
numpad[i].position(width/2-button_length/2-5+floor(i%3)*5 + (i%3)*30,height-160 + 30*floor(i/3)+floor(i/3)*10);
}
go_button.position(width/2-button_length/2 + ((auctioned_digits.length+1)%3)*30,height-135 + 30*floor((auctioned_digits.length+1)/3)+5);
}
function BidIncrease(){
if(currentBid < playerTokens && !gameOver){
currentBid++;
}
return;
}
function BidDecrease(){
if(currentBid > 0 && !gameOver){
currentBid--;
}
return;
}
function go(){
if(!gameOver){
if (currentDigitIndex<0){
select_index_label="Please Select Index for your digit!";
return;
}
playerTokens -= currentBid;
if(currentBid>0){
auctioned_digits[currentDigitIndex]=digits[digits_to_auction[digits_to_auction.length-1]];
numpad[currentDigitIndex].style('background-color','red');
used_indexes.push(currentDigitIndex);
if(used_indexes.length == auctioned_digits.length){
}
digits_to_auction.pop();
currentBid=0;
currentDigitIndex=-1;
select_index_label="";
if(used_indexes.length == auctioned_digits.length || playerTokens == 0){
gameOver=true;
select_index_label="GameOver";
sendData();
}
}
}
}
function pickIndex(){
let ix = int(this.html());
if(used_indexes.includes(ix)){
select_index_label="This index already been used!";
return;
}
if(currentBid<=0){
select_index_label="Please bid before picking Index!";
return;
}
if(ix>=0 ){
currentDigitIndex=ix;
numpad[currentDigitIndex].style('background-color','#BEBEBE')
}
select_index_label="";
return;
}
//google sheet
let url = "https://script.google.com/macros/s/AKfycbwr272lrn79oJO0iBO3nf6b3Bpzr0_AJDUEA2EV_8iAzWmzt-DAWJ1XzNnTfw9h7TdN/exec"; // Replace with the actual URL
// function setup() {
// createCanvas(400, 400);
// let sendButton = createButton("Send Data");
// sendButton.position(150, 200);
// sendButton.mousePressed(sendData);
// }
function sendData() {
let data = {
name: "Nagesh",
score: int(random(1, 100)) // Random score for example
};
fetch(url, {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then(() => console.log("Data Sent"));
}