This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Decylavon's profile picture

Triple Chance Slots

Started by Decylavon, 21 October 2012 - 04:35 PM
Decylavon #1
Posted 21 October 2012 - 06:35 PM
Basic code of "Triple Chance Slots" game I made

SCREENSHOTS
Spoiler


CODE
Spoiler

--Triple Chance by Decylavon aka. MaXx0r
r1={1,1,1}
r2={2,2,2}
r3={3,3,3}

mon = peripheral.wrap("top")
multiplier=0

function spin()
	clear()
	chances=0
	spincount=15
	
	for i=0,spincount do
		r3[1]=r2[1]
		r3[2]=r2[2]
		r3[3]=r2[3]
		
		r2[1]=r1[1]
		r2[2]=r1[2]
		r2[3]=r1[3]
		
		r1[1]=math.random(1,9)
		r1[2]=math.random(1,9)
		r1[3]=math.random(1,9)
		
		print("===============")
		print("=TRIPLE CHANCE=")
		print("===============")
		print("=| "..r1[1].." | "..r1[2].." | "..r1[3].." |=")
		print("=| "..r2[1].." | "..r2[2].." | "..r2[3].." |=")
		print("=| "..r3[1].." | "..r3[2].." | "..r3[3].." |=")
		print("===============")
		
		mon.clear()
		mon.setCursorPos(2,1)
		mon.write("===============")
		mon.setCursorPos(2,2)
		mon.write("=TRIPLE CHANCE=")
		mon.setCursorPos(2,3)
		mon.write("===============")
		mon.setCursorPos(2,4)
		mon.write("=| "..r1[1].." | "..r1[2].." | "..r1[3].." |=")
		mon.setCursorPos(2,5)
		mon.write("=| "..r2[1].." | "..r2[2].." | "..r2[3].." |=")
		mon.setCursorPos(2,6)
		mon.write("=| "..r3[1].." | "..r3[2].." | "..r3[3].." |=")
		mon.setCursorPos(2,7)
		mon.write("===============")
		
		sleep(0.1)
		if i < spincount then
			shell.run("clear")
		else
			if r1[1]==r1[2] and r1[2]==r1[3] then
				win(6*r1[2])
			elseif r2[1]==r2[2] and r2[2]==r2[3] then
				win(9*r2[2])
			elseif r3[1]==r3[2] and r3[2]==r3[3] then
				win(6*r3[2])
			elseif r1[1]==r2[2] and r2[2]==r3[3] then
				win(3*r2[2])
			elseif r1[3]==r2[2] and r2[2]==r3[1] then
				win(3*r2[2])
			else
				lose()
			end
		end
	end
end

function clear()
	mon.clear()
	shell.run("clear")
end

function win(multiplier)
	print("***WINNER***")
	print("+++[x"..multiplier.."]+++")
	
	mon.setCursorPos(4,8)
	mon.write("***WINNER***")
	mon.setCursorPos(5,9)
	mon.write("+++[x"..multiplier.."]+++")
	
	sleep(0.5)
	
	print("*CHANCE("..chances.."/3) [Y]*")
	
	mon.setCursorPos(1,10)
	mon.write("*CHANCE("..chances.."/3) [Y]*")
	
	if io.read() == "Y" then
		chances=chances+1
		chance(multiplier)
	else
		chances=0
		clear()
		
		print("***GOODBYE***")
		
		mon.setCursorPos(3,1)
		mon.write("***GOODBYE***")
	end
end

function lose()
	print("***LOSER***")
	print("+++[x"..multiplier.."]+++")
	
	mon.setCursorPos(4,8)
	mon.write("***LOSER***")
	mon.setCursorPos(5,9)
	mon.write("+++[x"..multiplier.."]+++")
end

function chance(cmultiplier)
	clear()
	if math.random(1) then
		chancemultiplier=cmultiplier*2
	
		print("***LUCKY ONE***")
		print("+++[x"..chancemultiplier.."]+++")
		
		mon.setCursorPos(2,1)
		mon.write("***LUCKY ONE***")
		mon.setCursorPos(4,2)
		mon.write("+++[x"..chancemultiplier.."]+++")
		
		if chances < 3 then
			sleep(0.5)
			
			print("*CHANCE("..chances.."/3) [Y]*")
			
			mon.setCursorPos(1,3)
			mon.write("*CHANCE("..chances.."/3) [Y]*")
			
			if io.read() == "Y" then
				chances=chances+1
				chance(chancemultiplier)
			else
				sleep(1)
				chances=0
				clear()
				
				print("***GOODBYE***")
				
				mon.setCursorPos(3,1)
				mon.write("***GOODBYE***")
			end
		else
			print("*CHANCE("..chances.."/3)*")
			print("***GOODBYE***")
			
			mon.setCursorPos(3,3)
			mon.write("*CHANCE("..chances.."/3)*")
			mon.setCursorPos(3,4)
			mon.write("***GOODBYE***")
		end
	else
		chancemultiplier=0
		print("***BAD LUCK***")
		print("+++[x"..chancemultiplier.."]+++")
		
		mon.setCursorPos(2,1)
		mon.write("***BAD LUCK***")
		mon.setCursorPos(4,2)
		mon.write("+++[x"..chancemultiplier.."]+++")
	end
end

spin()

DOWNLOAD
Spoilerhttp://pastebin.com/5es45gQm

Post your suggestions and leave a comment please :)/>/>
Decylavon #2
Posted 21 October 2012 - 10:48 PM
-Added "Chance"
Cranium #3
Posted 22 October 2012 - 04:40 PM
Not bad. I like it. I made a slots machine as well, but it's more complicated with a much lower chance of winning.