[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SigBio] some code that maybe sort of could work as a basis for whack-a-mole



It's just a grid of 9 zeroes, and then at random times (the length of time that it remains all zeroes varies from 1 to 9 seconds randomly) one of them will change to a 1.

then perhaps you could do:

if (grid[x][y]==1):
        #code that would graphically display a mole in specific coordinates

Oh, and for mac users, replace the line os.system('CLS'); with os.system('clear');

-Charith

#! /usr/bin/env python


import random;
import time;
go =0;
cin = 1;
start = time.clock();
while (cin==1):
	
   
	#print start;
	#ab =0;
	#for sd in range(0,100):
	#	ab=ab+1;
	#print time.clock();
	go =0;
	ptime = random.randrange(0,10);
	ptime=ptime-.02;
	while (go==0):
		grid = [[0,0,0],[0,0,0],[0,0,0]];
		time.sleep(1);
		x = random.randrange(0,3);
		y = random.randrange(0,3);
		go =1;
		
		if (time.clock()-start>ptime):
			grid[x][y]=1;
			start = time.clock();
			ptime = random.randrange(0,10);
			ptime=ptime-.02;
	import os;
	os.system('CLS');
	for sx in range(0,3):
		print str(grid[sx])+'\n';